blob: 579f8ed06ed2676643e7ed79cc5cb38f6ba83779 [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 {
155 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600156 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600157 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600158 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600159 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600160
Karl Schultz6addd812016-02-02 17:17:23 -0700161 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600162
Karl Schultz6addd812016-02-02 17:17:23 -0700163 string GetFailureMsg(void) { return m_failureMsg; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600164
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600165 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
166
Karl Schultz6addd812016-02-02 17:17:23 -0700167 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600168
Karl Schultz6addd812016-02-02 17:17:23 -0700169 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600170
Karl Schultz6addd812016-02-02 17:17:23 -0700171 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600172 vector<string> otherMsgs = GetOtherFailureMsgs();
173 cout << "Other error messages logged for this test were:" << endl;
174 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
175 cout << " " << *iter << endl;
176 }
177 }
178
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600179 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200180
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600181 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
182 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
183 m_msgFlags = message_flag_mask;
184 // Match ANY message matching specified type
185 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200186 }
187
188 void VerifyFound() {
189 // Not seeing the desired message is a failure. /Before/ throwing, dump
190 // any other messages.
191 if (!DesiredMsgFound()) {
192 DumpFailureMsgs();
193 FAIL() << "Did not receive expected error '" << m_desiredMsg << "'";
194 }
195 }
196
197 void VerifyNotFound() {
198 // ExpectSuccess() configured us to match anything. Any error is a
199 // failure.
200 if (DesiredMsgFound()) {
201 DumpFailureMsgs();
202 FAIL() << "Expected to succeed but got error: " << GetFailureMsg();
203 }
204 }
205
Karl Schultz6addd812016-02-02 17:17:23 -0700206 private:
207 VkFlags m_msgFlags;
208 string m_desiredMsg;
209 string m_failureMsg;
210 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600211 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700212 bool *m_bailout;
213 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600214};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500215
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600216static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
217 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
218 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600219 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
220 if (msgFlags & errMonitor->GetMessageFlags()) {
221 return errMonitor->CheckForDesiredMsg(pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600222 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600223 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600224}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500225
Karl Schultz6addd812016-02-02 17:17:23 -0700226class VkLayerTest : public VkRenderFramework {
227 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800228 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
229 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600230 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
231 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700232 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600233 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
234 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700235 }
Tony Barbour300a6082015-04-07 13:44:53 -0600236
Tony Barbourfe3351b2015-07-28 10:17:20 -0600237 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600238 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800239 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600240 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
241 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700242 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600243 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700244 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600245 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700246 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600247 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
248 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
249 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700250 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
251 }
252 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
253 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
254 }
255
256 protected:
257 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600258 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600259
260 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600261 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600262 std::vector<const char *> instance_extension_names;
263 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600264
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700265 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600266 /*
267 * Since CreateDbgMsgCallback is an instance level extension call
268 * any extension / layer that utilizes that feature also needs
269 * to be enabled at create instance time.
270 */
Karl Schultz6addd812016-02-02 17:17:23 -0700271 // Use Threading layer first to protect others from
272 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700273 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600274 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800275 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700276 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800277 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600278 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700279 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600280
Ian Elliott2c1daf52016-05-12 09:41:46 -0600281 if (m_enableWSI) {
282 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
283 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
284#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
285#if defined(VK_USE_PLATFORM_ANDROID_KHR)
286 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
287#endif // VK_USE_PLATFORM_ANDROID_KHR
288#if defined(VK_USE_PLATFORM_MIR_KHR)
289 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
290#endif // VK_USE_PLATFORM_MIR_KHR
291#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
292 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
293#endif // VK_USE_PLATFORM_WAYLAND_KHR
294#if defined(VK_USE_PLATFORM_WIN32_KHR)
295 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
296#endif // VK_USE_PLATFORM_WIN32_KHR
297#endif // NEED_TO_TEST_THIS_ON_PLATFORM
298#if defined(VK_USE_PLATFORM_XCB_KHR)
299 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
300#elif defined(VK_USE_PLATFORM_XLIB_KHR)
301 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
302#endif // VK_USE_PLATFORM_XLIB_KHR
303 }
304
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600305 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600306 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800307 this->app_info.pApplicationName = "layer_tests";
308 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600309 this->app_info.pEngineName = "unittest";
310 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600311 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600312
Tony Barbour15524c32015-04-29 17:34:29 -0600313 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600314 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600315 }
316
317 virtual void TearDown() {
318 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600319 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600320 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600321 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600322
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600323 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600324};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500325
Karl Schultz6addd812016-02-02 17:17:23 -0700326VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600327 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600328
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800329 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600330
331 /*
332 * For render test all drawing happens in a single render pass
333 * on a single command buffer.
334 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200335 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800336 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600337 }
338
339 return result;
340}
341
Karl Schultz6addd812016-02-02 17:17:23 -0700342VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600343 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600344
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200345 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800346 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200347 }
Tony Barbour300a6082015-04-07 13:44:53 -0600348
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800349 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600350
351 return result;
352}
353
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600354void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500355 // Create identity matrix
356 int i;
357 struct vktriangle_vs_uniform data;
358
359 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700360 glm::mat4 View = glm::mat4(1.0f);
361 glm::mat4 Model = glm::mat4(1.0f);
362 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500363 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700364 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500365
366 memcpy(&data.mvp, &MVP[0][0], matrixSize);
367
Karl Schultz6addd812016-02-02 17:17:23 -0700368 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600369 {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 -0500370 };
371
Karl Schultz6addd812016-02-02 17:17:23 -0700372 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500373 data.position[i][0] = tri_data[i].posX;
374 data.position[i][1] = tri_data[i].posY;
375 data.position[i][2] = tri_data[i].posZ;
376 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700377 data.color[i][0] = tri_data[i].r;
378 data.color[i][1] = tri_data[i].g;
379 data.color[i][2] = tri_data[i].b;
380 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500381 }
382
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500383 ASSERT_NO_FATAL_FAILURE(InitViewport());
384
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600385 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500386
Karl Schultz6addd812016-02-02 17:17:23 -0700387 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600388 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500389
390 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800391 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500392 pipelineobj.AddShader(&vs);
393 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600394 if (failMask & BsoFailLineWidth) {
395 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600396 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600397 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600398 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
399 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600400 }
401 if (failMask & BsoFailDepthBias) {
402 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600403 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600404 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600405 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600406 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600407 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600408 }
Karl Schultz6addd812016-02-02 17:17:23 -0700409 // Viewport and scissors must stay in synch or other errors will occur than
410 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600411 if (failMask & BsoFailViewport) {
412 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600413 m_viewports.clear();
414 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600415 }
416 if (failMask & BsoFailScissor) {
417 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600418 m_scissors.clear();
419 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600420 }
421 if (failMask & BsoFailBlend) {
422 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600423 VkPipelineColorBlendAttachmentState att_state = {};
424 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
425 att_state.blendEnable = VK_TRUE;
426 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600427 }
428 if (failMask & BsoFailDepthBounds) {
429 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
430 }
431 if (failMask & BsoFailStencilReadMask) {
432 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
433 }
434 if (failMask & BsoFailStencilWriteMask) {
435 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
436 }
437 if (failMask & BsoFailStencilReference) {
438 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
439 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500440
441 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600442 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443
444 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600445 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500446
Tony Barbourfe3351b2015-07-28 10:17:20 -0600447 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500448
449 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600450 if (failMask & BsoFailIndexBuffer) {
451 // Use DrawIndexed w/o an index buffer bound
452 DrawIndexed(3, 1, 0, 0, 0);
453 } else {
454 Draw(3, 1, 0, 0);
455 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500456
Mark Muellerd4914412016-06-13 17:52:06 -0600457 if (failMask & BsoFailCmdClearAttachments) {
458 VkClearAttachment color_attachment = {};
459 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
460 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
461 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
462
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600463 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600464 }
465
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500466 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600467 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500468
Tony Barbourfe3351b2015-07-28 10:17:20 -0600469 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500470}
471
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600472void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
473 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500474 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600475 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500476 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600477 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500478 }
479
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800480 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700481 // Make sure depthWriteEnable is set so that Depth fail test will work
482 // correctly
483 // Make sure stencilTestEnable is set so that Stencil fail test will work
484 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600485 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800486 stencil.failOp = VK_STENCIL_OP_KEEP;
487 stencil.passOp = VK_STENCIL_OP_KEEP;
488 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
489 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600490
491 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
492 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600493 ds_ci.pNext = NULL;
494 ds_ci.depthTestEnable = VK_FALSE;
495 ds_ci.depthWriteEnable = VK_TRUE;
496 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
497 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600498 if (failMask & BsoFailDepthBounds) {
499 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600500 ds_ci.maxDepthBounds = 0.0f;
501 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600502 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600503 ds_ci.stencilTestEnable = VK_TRUE;
504 ds_ci.front = stencil;
505 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600506
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600507 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600508 pipelineobj.SetViewport(m_viewports);
509 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800510 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600511 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600512 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800513 commandBuffer->BindPipeline(pipelineobj);
514 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500515}
516
Ian Elliott2c1daf52016-05-12 09:41:46 -0600517class VkWsiEnabledLayerTest : public VkLayerTest {
518 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600519 protected:
520 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600521};
522
Mark Muellerdfe37552016-07-07 14:47:42 -0600523class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600524 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600525 enum eTestEnFlags {
526 eDoubleDelete,
527 eInvalidDeviceOffset,
528 eInvalidMemoryOffset,
529 eBindNullBuffer,
530 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600531 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600532 };
533
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600534 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600535
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600536 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
537 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600538 return true;
539 }
540 VkDeviceSize offset_limit = 0;
541 if (eInvalidMemoryOffset == aTestFlag) {
542 VkBuffer vulkanBuffer;
543 VkBufferCreateInfo buffer_create_info = {};
544 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
545 buffer_create_info.size = 32;
546 buffer_create_info.usage = aBufferUsage;
547
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600548 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600549 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600550
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600551 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600552 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
553 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600554 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
555 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600556 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600557 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600558 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600559 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600560 }
561 if (eOffsetAlignment < offset_limit) {
562 return true;
563 }
564 return false;
565 }
566
567 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600568 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
569 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600570
571 if (eBindNullBuffer == aTestFlag) {
572 VulkanMemory = 0;
573 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
574 } else {
575 VkBufferCreateInfo buffer_create_info = {};
576 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
577 buffer_create_info.size = 32;
578 buffer_create_info.usage = aBufferUsage;
579
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600580 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600581
582 CreateCurrent = true;
583
584 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600585 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600586
587 VkMemoryAllocateInfo memory_allocate_info = {};
588 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
589 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600590 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
591 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600592 if (!pass) {
593 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
594 return;
595 }
596
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600597 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600598 AllocateCurrent = true;
599 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600600 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
601 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600602 BoundCurrent = true;
603
604 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
605 }
606 }
607
608 ~VkBufferTest() {
609 if (CreateCurrent) {
610 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
611 }
612 if (AllocateCurrent) {
613 if (InvalidDeleteEn) {
614 union {
615 VkDeviceMemory device_memory;
616 unsigned long long index_access;
617 } bad_index;
618
619 bad_index.device_memory = VulkanMemory;
620 bad_index.index_access++;
621
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600622 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600623 }
624 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
625 }
626 }
627
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600628 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600629
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600631
632 void TestDoubleDestroy() {
633 // Destroy the buffer but leave the flag set, which will cause
634 // the buffer to be destroyed again in the destructor.
635 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
636 }
637
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600638 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600639 bool AllocateCurrent;
640 bool BoundCurrent;
641 bool CreateCurrent;
642 bool InvalidDeleteEn;
643
644 VkBuffer VulkanBuffer;
645 VkDevice VulkanDevice;
646 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600647};
648
649class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600650 public:
651 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600652 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600653 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600654 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600655 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
656 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600657 BindIdGenerator++; // NB: This can wrap w/misuse
658
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600659 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
660 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600661
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
663 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
664 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
665 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
666 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600667
668 unsigned i = 0;
669 do {
670 VertexInputAttributeDescription[i].binding = BindId;
671 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600672 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
673 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600674 i++;
675 } while (AttributeCount < i);
676
677 i = 0;
678 do {
679 VertexInputBindingDescription[i].binding = BindId;
680 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600681 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600682 i++;
683 } while (BindingCount < i);
684 }
685
686 ~VkVerticesObj() {
687 if (VertexInputAttributeDescription) {
688 delete[] VertexInputAttributeDescription;
689 }
690 if (VertexInputBindingDescription) {
691 delete[] VertexInputBindingDescription;
692 }
693 }
694
695 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600696 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
697 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600698 return true;
699 }
700
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600701 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600702 VkDeviceSize *offsetList;
703 unsigned offsetCount;
704
705 if (aOffsetCount) {
706 offsetList = aOffsetList;
707 offsetCount = aOffsetCount;
708 } else {
709 offsetList = new VkDeviceSize[1]();
710 offsetCount = 1;
711 }
712
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600713 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600714 BoundCurrent = true;
715
716 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600717 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600718 }
719 }
720
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600721 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600722 static uint32_t BindIdGenerator;
723
724 bool BoundCurrent;
725 unsigned AttributeCount;
726 unsigned BindingCount;
727 uint32_t BindId;
728
729 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
730 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
731 VkVertexInputBindingDescription *VertexInputBindingDescription;
732 VkConstantBufferObj VulkanMemoryBuffer;
733};
734
735uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500736// ********************************************************************************************************************
737// ********************************************************************************************************************
738// ********************************************************************************************************************
739// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600740#if PARAMETER_VALIDATION_TESTS
741TEST_F(VkLayerTest, RequiredParameter) {
742 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
743 "pointer, array, and array count parameters");
744
745 ASSERT_NO_FATAL_FAILURE(InitState());
746
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600748 // Specify NULL for a pointer to a handle
749 // Expected to trigger an error with
750 // parameter_validation::validate_required_pointer
751 vkGetPhysicalDeviceFeatures(gpu(), NULL);
752 m_errorMonitor->VerifyFound();
753
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
755 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600756 // Specify NULL for pointer to array count
757 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600758 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600759 m_errorMonitor->VerifyFound();
760
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600762 // Specify 0 for a required array count
763 // Expected to trigger an error with parameter_validation::validate_array
764 VkViewport view_port = {};
765 m_commandBuffer->SetViewport(0, 0, &view_port);
766 m_errorMonitor->VerifyFound();
767
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600769 // Specify NULL for a required array
770 // Expected to trigger an error with parameter_validation::validate_array
771 m_commandBuffer->SetViewport(0, 1, NULL);
772 m_errorMonitor->VerifyFound();
773
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600775 // Specify VK_NULL_HANDLE for a required handle
776 // Expected to trigger an error with
777 // parameter_validation::validate_required_handle
778 vkUnmapMemory(device(), VK_NULL_HANDLE);
779 m_errorMonitor->VerifyFound();
780
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
782 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600783 // Specify VK_NULL_HANDLE for a required handle array entry
784 // Expected to trigger an error with
785 // parameter_validation::validate_required_handle_array
786 VkFence fence = VK_NULL_HANDLE;
787 vkResetFences(device(), 1, &fence);
788 m_errorMonitor->VerifyFound();
789
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600791 // Specify NULL for a required struct pointer
792 // Expected to trigger an error with
793 // parameter_validation::validate_struct_type
794 VkDeviceMemory memory = VK_NULL_HANDLE;
795 vkAllocateMemory(device(), NULL, NULL, &memory);
796 m_errorMonitor->VerifyFound();
797
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600799 // Specify 0 for a required VkFlags parameter
800 // Expected to trigger an error with parameter_validation::validate_flags
801 m_commandBuffer->SetStencilReference(0, 0);
802 m_errorMonitor->VerifyFound();
803
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600804 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 -0600805 // Specify 0 for a required VkFlags array entry
806 // Expected to trigger an error with
807 // parameter_validation::validate_flags_array
808 VkSemaphore semaphore = VK_NULL_HANDLE;
809 VkPipelineStageFlags stageFlags = 0;
810 VkSubmitInfo submitInfo = {};
811 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
812 submitInfo.waitSemaphoreCount = 1;
813 submitInfo.pWaitSemaphores = &semaphore;
814 submitInfo.pWaitDstStageMask = &stageFlags;
815 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
816 m_errorMonitor->VerifyFound();
817}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600818
Dustin Gravesfce74c02016-05-10 11:42:58 -0600819TEST_F(VkLayerTest, ReservedParameter) {
820 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
821
822 ASSERT_NO_FATAL_FAILURE(InitState());
823
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600825 // Specify 0 for a reserved VkFlags parameter
826 // Expected to trigger an error with
827 // parameter_validation::validate_reserved_flags
828 VkEvent event_handle = VK_NULL_HANDLE;
829 VkEventCreateInfo event_info = {};
830 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
831 event_info.flags = 1;
832 vkCreateEvent(device(), &event_info, NULL, &event_handle);
833 m_errorMonitor->VerifyFound();
834}
835
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600836TEST_F(VkLayerTest, InvalidStructSType) {
837 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
838 "structure's sType field");
839
840 ASSERT_NO_FATAL_FAILURE(InitState());
841
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600843 // Zero struct memory, effectively setting sType to
844 // VK_STRUCTURE_TYPE_APPLICATION_INFO
845 // Expected to trigger an error with
846 // parameter_validation::validate_struct_type
847 VkMemoryAllocateInfo alloc_info = {};
848 VkDeviceMemory memory = VK_NULL_HANDLE;
849 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
850 m_errorMonitor->VerifyFound();
851
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600853 // Zero struct memory, effectively setting sType to
854 // VK_STRUCTURE_TYPE_APPLICATION_INFO
855 // Expected to trigger an error with
856 // parameter_validation::validate_struct_type_array
857 VkSubmitInfo submit_info = {};
858 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
859 m_errorMonitor->VerifyFound();
860}
861
862TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600863 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600864
865 ASSERT_NO_FATAL_FAILURE(InitState());
866
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600868 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
Karl Schultz38b50992016-07-11 16:09:09 -0600869 // NULL.
870 // Need to pick a function that has no allowed pNext structure types.
871 // Expected to trigger an error with
872 // parameter_validation::validate_struct_pnext
873 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600874 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600875 // Zero-initialization will provide the correct sType
876 VkApplicationInfo app_info = {};
877 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
878 event_alloc_info.pNext = &app_info;
879 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
880 m_errorMonitor->VerifyFound();
881
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
883 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600884 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
885 // a function that has allowed pNext structure types and specify
886 // a structure type that is not allowed.
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600887 // Expected to trigger an error with
888 // parameter_validation::validate_struct_pnext
889 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600890 VkMemoryAllocateInfo memory_alloc_info = {};
891 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
892 memory_alloc_info.pNext = &app_info;
893 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600894 m_errorMonitor->VerifyFound();
895
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600896 // Positive test to check parameter_validation and unique_objects support
897 // for NV_dedicated_allocation
898 uint32_t extension_count = 0;
899 bool supports_nv_dedicated_allocation = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600900 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600901 ASSERT_VK_SUCCESS(err);
902
903 if (extension_count > 0) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600904 std::vector<VkExtensionProperties> available_extensions(extension_count);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600905
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600906 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600907 ASSERT_VK_SUCCESS(err);
908
909 for (const auto &extension_props : available_extensions) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600910 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600911 supports_nv_dedicated_allocation = true;
912 }
913 }
914 }
915
916 if (supports_nv_dedicated_allocation) {
917 m_errorMonitor->ExpectSuccess();
918
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600919 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
920 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600921 dedicated_buffer_create_info.pNext = nullptr;
922 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
923
924 uint32_t queue_family_index = 0;
925 VkBufferCreateInfo buffer_create_info = {};
926 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
927 buffer_create_info.pNext = &dedicated_buffer_create_info;
928 buffer_create_info.size = 1024;
929 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
930 buffer_create_info.queueFamilyIndexCount = 1;
931 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
932
933 VkBuffer buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600934 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600935 ASSERT_VK_SUCCESS(err);
936
937 VkMemoryRequirements memory_reqs;
938 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
939
940 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600941 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600942 dedicated_memory_info.pNext = nullptr;
943 dedicated_memory_info.buffer = buffer;
944 dedicated_memory_info.image = VK_NULL_HANDLE;
945
946 VkMemoryAllocateInfo memory_info = {};
947 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
948 memory_info.pNext = &dedicated_memory_info;
949 memory_info.allocationSize = memory_reqs.size;
950
951 bool pass;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600952 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600953 ASSERT_TRUE(pass);
954
955 VkDeviceMemory buffer_memory;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600956 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600957 ASSERT_VK_SUCCESS(err);
958
959 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
960 ASSERT_VK_SUCCESS(err);
961
962 vkDestroyBuffer(m_device->device(), buffer, NULL);
963 vkFreeMemory(m_device->device(), buffer_memory, NULL);
964
965 m_errorMonitor->VerifyNotFound();
966 }
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600967}
Dustin Graves5d33d532016-05-09 16:21:12 -0600968
969TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600970 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600971
972 ASSERT_NO_FATAL_FAILURE(InitState());
973
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
975 "range of the core VkFormat "
976 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600977 // Specify an invalid VkFormat value
978 // Expected to trigger an error with
979 // parameter_validation::validate_ranged_enum
980 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600981 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600982 m_errorMonitor->VerifyFound();
983
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600984 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 -0600985 // Specify an invalid VkFlags bitmask value
986 // Expected to trigger an error with parameter_validation::validate_flags
987 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600988 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
989 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600990 m_errorMonitor->VerifyFound();
991
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600992 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 -0600993 // Specify an invalid VkFlags array entry
994 // Expected to trigger an error with
995 // parameter_validation::validate_flags_array
996 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600997 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600998 VkSubmitInfo submit_info = {};
999 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1000 submit_info.waitSemaphoreCount = 1;
1001 submit_info.pWaitSemaphores = &semaphore;
1002 submit_info.pWaitDstStageMask = &stage_flags;
1003 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1004 m_errorMonitor->VerifyFound();
1005
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001007 // Specify an invalid VkBool32 value
1008 // Expected to trigger a warning with
1009 // parameter_validation::validate_bool32
1010 VkSampler sampler = VK_NULL_HANDLE;
1011 VkSamplerCreateInfo sampler_info = {};
1012 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1013 sampler_info.pNext = NULL;
1014 sampler_info.magFilter = VK_FILTER_NEAREST;
1015 sampler_info.minFilter = VK_FILTER_NEAREST;
1016 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1017 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1018 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1019 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1020 sampler_info.mipLodBias = 1.0;
1021 sampler_info.maxAnisotropy = 1;
1022 sampler_info.compareEnable = VK_FALSE;
1023 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1024 sampler_info.minLod = 1.0;
1025 sampler_info.maxLod = 1.0;
1026 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1027 sampler_info.unnormalizedCoordinates = VK_FALSE;
1028 // Not VK_TRUE or VK_FALSE
1029 sampler_info.anisotropyEnable = 3;
1030 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1031 m_errorMonitor->VerifyFound();
1032}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001033
1034TEST_F(VkLayerTest, FailedReturnValue) {
1035 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1036
1037 ASSERT_NO_FATAL_FAILURE(InitState());
1038
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001039 // Find an unsupported image format
1040 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1041 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1042 VkFormat format = static_cast<VkFormat>(f);
1043 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001044 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001045 unsupported = format;
1046 break;
1047 }
1048 }
1049
1050 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1052 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001053 // Specify an unsupported VkFormat value to generate a
1054 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1055 // Expected to trigger a warning from
1056 // parameter_validation::validate_result
1057 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001058 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1059 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001060 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1061 m_errorMonitor->VerifyFound();
1062 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001063}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001064
1065TEST_F(VkLayerTest, UpdateBufferAlignment) {
1066 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001067 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001068
1069 ASSERT_NO_FATAL_FAILURE(InitState());
1070
1071 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1072 vk_testing::Buffer buffer;
1073 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1074
1075 BeginCommandBuffer();
1076 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001078 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1079 m_errorMonitor->VerifyFound();
1080
1081 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001083 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1084 m_errorMonitor->VerifyFound();
1085
1086 // Introduce failure by using dataSize that is < 0
1087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001088 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001089 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1090 m_errorMonitor->VerifyFound();
1091
1092 // Introduce failure by using dataSize that is > 65536
1093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001094 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001095 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1096 m_errorMonitor->VerifyFound();
1097
1098 EndCommandBuffer();
1099}
1100
1101TEST_F(VkLayerTest, FillBufferAlignment) {
1102 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1103
1104 ASSERT_NO_FATAL_FAILURE(InitState());
1105
1106 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1107 vk_testing::Buffer buffer;
1108 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1109
1110 BeginCommandBuffer();
1111
1112 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001114 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1115 m_errorMonitor->VerifyFound();
1116
1117 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001119 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1120 m_errorMonitor->VerifyFound();
1121
1122 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001124 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1125 m_errorMonitor->VerifyFound();
1126
1127 EndCommandBuffer();
1128}
Dustin Graves40f35822016-06-23 11:12:53 -06001129
1130// This is a positive test. No failures are expected.
1131TEST_F(VkLayerTest, IgnoreUnrelatedDescriptor) {
1132 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSet validation code "
1133 "is ignoring VkWriteDescriptorSet members that are not "
1134 "related to the descriptor type specified by "
1135 "VkWriteDescriptorSet::descriptorType. Correct "
1136 "validation behavior will result in the test running to "
1137 "completion without validation errors.");
1138
Dustin Graves5e2d8fc2016-07-07 16:18:49 -06001139 const uintptr_t invalid_ptr = 0xcdcdcdcd;
1140
Dustin Graves40f35822016-06-23 11:12:53 -06001141 ASSERT_NO_FATAL_FAILURE(InitState());
1142
1143 // Image Case
1144 {
1145 m_errorMonitor->ExpectSuccess();
1146
1147 VkImage image;
1148 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1149 const int32_t tex_width = 32;
1150 const int32_t tex_height = 32;
1151 VkImageCreateInfo image_create_info = {};
1152 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1153 image_create_info.pNext = NULL;
1154 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1155 image_create_info.format = tex_format;
1156 image_create_info.extent.width = tex_width;
1157 image_create_info.extent.height = tex_height;
1158 image_create_info.extent.depth = 1;
1159 image_create_info.mipLevels = 1;
1160 image_create_info.arrayLayers = 1;
1161 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis51cde412016-07-11 16:08:30 -06001162 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Dustin Graves40f35822016-06-23 11:12:53 -06001163 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1164 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001165 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Dustin Graves40f35822016-06-23 11:12:53 -06001166 ASSERT_VK_SUCCESS(err);
1167
1168 VkMemoryRequirements memory_reqs;
1169 VkDeviceMemory image_memory;
1170 bool pass;
1171 VkMemoryAllocateInfo memory_info = {};
1172 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1173 memory_info.pNext = NULL;
1174 memory_info.allocationSize = 0;
1175 memory_info.memoryTypeIndex = 0;
1176 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
1177 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001178 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001179 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001180 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001181 ASSERT_VK_SUCCESS(err);
1182 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
1183 ASSERT_VK_SUCCESS(err);
1184
1185 VkImageViewCreateInfo image_view_create_info = {};
1186 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1187 image_view_create_info.image = image;
1188 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
1189 image_view_create_info.format = tex_format;
1190 image_view_create_info.subresourceRange.layerCount = 1;
1191 image_view_create_info.subresourceRange.baseMipLevel = 0;
1192 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001193 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dustin Graves40f35822016-06-23 11:12:53 -06001194
1195 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001196 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Dustin Graves40f35822016-06-23 11:12:53 -06001197 ASSERT_VK_SUCCESS(err);
1198
1199 VkDescriptorPoolSize ds_type_count = {};
1200 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1201 ds_type_count.descriptorCount = 1;
1202
1203 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1204 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1205 ds_pool_ci.pNext = NULL;
1206 ds_pool_ci.maxSets = 1;
1207 ds_pool_ci.poolSizeCount = 1;
1208 ds_pool_ci.pPoolSizes = &ds_type_count;
1209
1210 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001211 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001212 ASSERT_VK_SUCCESS(err);
1213
1214 VkDescriptorSetLayoutBinding dsl_binding = {};
1215 dsl_binding.binding = 0;
1216 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1217 dsl_binding.descriptorCount = 1;
1218 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1219 dsl_binding.pImmutableSamplers = NULL;
1220
1221 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001222 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001223 ds_layout_ci.pNext = NULL;
1224 ds_layout_ci.bindingCount = 1;
1225 ds_layout_ci.pBindings = &dsl_binding;
1226 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001227 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001228 ASSERT_VK_SUCCESS(err);
1229
1230 VkDescriptorSet descriptor_set;
1231 VkDescriptorSetAllocateInfo alloc_info = {};
1232 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1233 alloc_info.descriptorSetCount = 1;
1234 alloc_info.descriptorPool = ds_pool;
1235 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001236 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001237 ASSERT_VK_SUCCESS(err);
1238
1239 VkDescriptorImageInfo image_info = {};
1240 image_info.imageView = view;
1241 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
1242
1243 VkWriteDescriptorSet descriptor_write;
1244 memset(&descriptor_write, 0, sizeof(descriptor_write));
1245 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1246 descriptor_write.dstSet = descriptor_set;
1247 descriptor_write.dstBinding = 0;
1248 descriptor_write.descriptorCount = 1;
1249 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1250 descriptor_write.pImageInfo = &image_info;
1251
1252 // Set pBufferInfo and pTexelBufferView to invalid values, which should
1253 // be
1254 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
1255 // This will most likely produce a crash if the parameter_validation
1256 // layer
1257 // does not correctly ignore pBufferInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001258 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
1259 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001260
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001261 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001262
1263 m_errorMonitor->VerifyNotFound();
1264
Dustin Graves40f35822016-06-23 11:12:53 -06001265 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1266 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1267 vkDestroyImageView(m_device->device(), view, NULL);
1268 vkDestroyImage(m_device->device(), image, NULL);
1269 vkFreeMemory(m_device->device(), image_memory, NULL);
1270 }
1271
1272 // Buffer Case
1273 {
1274 m_errorMonitor->ExpectSuccess();
1275
1276 VkBuffer buffer;
1277 uint32_t queue_family_index = 0;
1278 VkBufferCreateInfo buffer_create_info = {};
1279 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1280 buffer_create_info.size = 1024;
1281 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1282 buffer_create_info.queueFamilyIndexCount = 1;
1283 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
1284
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001285 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Graves40f35822016-06-23 11:12:53 -06001286 ASSERT_VK_SUCCESS(err);
1287
1288 VkMemoryRequirements memory_reqs;
1289 VkDeviceMemory buffer_memory;
1290 bool pass;
1291 VkMemoryAllocateInfo memory_info = {};
1292 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1293 memory_info.pNext = NULL;
1294 memory_info.allocationSize = 0;
1295 memory_info.memoryTypeIndex = 0;
1296
1297 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
1298 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001299 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001300 ASSERT_TRUE(pass);
1301
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001302 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001303 ASSERT_VK_SUCCESS(err);
1304 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
1305 ASSERT_VK_SUCCESS(err);
1306
1307 VkDescriptorPoolSize ds_type_count = {};
1308 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1309 ds_type_count.descriptorCount = 1;
1310
1311 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1312 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1313 ds_pool_ci.pNext = NULL;
1314 ds_pool_ci.maxSets = 1;
1315 ds_pool_ci.poolSizeCount = 1;
1316 ds_pool_ci.pPoolSizes = &ds_type_count;
1317
1318 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001319 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001320 ASSERT_VK_SUCCESS(err);
1321
1322 VkDescriptorSetLayoutBinding dsl_binding = {};
1323 dsl_binding.binding = 0;
1324 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1325 dsl_binding.descriptorCount = 1;
1326 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1327 dsl_binding.pImmutableSamplers = NULL;
1328
1329 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001330 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001331 ds_layout_ci.pNext = NULL;
1332 ds_layout_ci.bindingCount = 1;
1333 ds_layout_ci.pBindings = &dsl_binding;
1334 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001335 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001336 ASSERT_VK_SUCCESS(err);
1337
1338 VkDescriptorSet descriptor_set;
1339 VkDescriptorSetAllocateInfo alloc_info = {};
1340 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1341 alloc_info.descriptorSetCount = 1;
1342 alloc_info.descriptorPool = ds_pool;
1343 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001344 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001345 ASSERT_VK_SUCCESS(err);
1346
1347 VkDescriptorBufferInfo buffer_info = {};
1348 buffer_info.buffer = buffer;
1349 buffer_info.offset = 0;
1350 buffer_info.range = 1024;
1351
1352 VkWriteDescriptorSet descriptor_write;
1353 memset(&descriptor_write, 0, sizeof(descriptor_write));
1354 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1355 descriptor_write.dstSet = descriptor_set;
1356 descriptor_write.dstBinding = 0;
1357 descriptor_write.descriptorCount = 1;
1358 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1359 descriptor_write.pBufferInfo = &buffer_info;
1360
1361 // Set pImageInfo and pTexelBufferView to invalid values, which should
1362 // be
1363 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
1364 // This will most likely produce a crash if the parameter_validation
1365 // layer
1366 // does not correctly ignore pImageInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001367 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
1368 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001369
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001370 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001371
1372 m_errorMonitor->VerifyNotFound();
1373
1374 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
1375 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1376 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1377 vkDestroyBuffer(m_device->device(), buffer, NULL);
1378 vkFreeMemory(m_device->device(), buffer_memory, NULL);
1379 }
1380
1381 // Texel Buffer Case
1382 {
1383 m_errorMonitor->ExpectSuccess();
1384
1385 VkBuffer buffer;
1386 uint32_t queue_family_index = 0;
1387 VkBufferCreateInfo buffer_create_info = {};
1388 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1389 buffer_create_info.size = 1024;
1390 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
1391 buffer_create_info.queueFamilyIndexCount = 1;
1392 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
1393
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001394 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Graves40f35822016-06-23 11:12:53 -06001395 ASSERT_VK_SUCCESS(err);
1396
1397 VkMemoryRequirements memory_reqs;
1398 VkDeviceMemory buffer_memory;
1399 bool pass;
1400 VkMemoryAllocateInfo memory_info = {};
1401 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1402 memory_info.pNext = NULL;
1403 memory_info.allocationSize = 0;
1404 memory_info.memoryTypeIndex = 0;
1405
1406 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
1407 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001408 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001409 ASSERT_TRUE(pass);
1410
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001411 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001412 ASSERT_VK_SUCCESS(err);
1413 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
1414 ASSERT_VK_SUCCESS(err);
1415
1416 VkBufferViewCreateInfo buff_view_ci = {};
1417 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
1418 buff_view_ci.buffer = buffer;
1419 buff_view_ci.format = VK_FORMAT_R8_UNORM;
1420 buff_view_ci.range = VK_WHOLE_SIZE;
1421 VkBufferView buffer_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001422 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
Dustin Graves40f35822016-06-23 11:12:53 -06001423
1424 VkDescriptorPoolSize ds_type_count = {};
1425 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1426 ds_type_count.descriptorCount = 1;
1427
1428 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1429 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1430 ds_pool_ci.pNext = NULL;
1431 ds_pool_ci.maxSets = 1;
1432 ds_pool_ci.poolSizeCount = 1;
1433 ds_pool_ci.pPoolSizes = &ds_type_count;
1434
1435 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001436 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001437 ASSERT_VK_SUCCESS(err);
1438
1439 VkDescriptorSetLayoutBinding dsl_binding = {};
1440 dsl_binding.binding = 0;
1441 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1442 dsl_binding.descriptorCount = 1;
1443 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1444 dsl_binding.pImmutableSamplers = NULL;
1445
1446 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001447 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001448 ds_layout_ci.pNext = NULL;
1449 ds_layout_ci.bindingCount = 1;
1450 ds_layout_ci.pBindings = &dsl_binding;
1451 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001452 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001453 ASSERT_VK_SUCCESS(err);
1454
1455 VkDescriptorSet descriptor_set;
1456 VkDescriptorSetAllocateInfo alloc_info = {};
1457 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1458 alloc_info.descriptorSetCount = 1;
1459 alloc_info.descriptorPool = ds_pool;
1460 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001461 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001462 ASSERT_VK_SUCCESS(err);
1463
1464 VkWriteDescriptorSet descriptor_write;
1465 memset(&descriptor_write, 0, sizeof(descriptor_write));
1466 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1467 descriptor_write.dstSet = descriptor_set;
1468 descriptor_write.dstBinding = 0;
1469 descriptor_write.descriptorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001470 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Dustin Graves40f35822016-06-23 11:12:53 -06001471 descriptor_write.pTexelBufferView = &buffer_view;
1472
1473 // Set pImageInfo and pBufferInfo to invalid values, which should be
1474 // ignored for descriptorType ==
1475 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
1476 // This will most likely produce a crash if the parameter_validation
1477 // layer
1478 // does not correctly ignore pImageInfo and pBufferInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001479 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
1480 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001481
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001482 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001483
1484 m_errorMonitor->VerifyNotFound();
1485
1486 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
1487 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1488 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1489 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
1490 vkDestroyBuffer(m_device->device(), buffer, NULL);
1491 vkFreeMemory(m_device->device(), buffer_memory, NULL);
1492 }
1493}
Cortd889ff92016-07-27 09:51:27 -07001494
1495TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1496 VkResult err;
1497
1498 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001499 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001500
1501 ASSERT_NO_FATAL_FAILURE(InitState());
1502 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1503
1504 std::vector<const char *> device_extension_names;
1505 auto features = m_device->phy().features();
1506 // Artificially disable support for non-solid fill modes
1507 features.fillModeNonSolid = false;
1508 // The sacrificial device object
1509 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1510
1511 VkRenderpassObj render_pass(&test_device);
1512
1513 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1514 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1515 pipeline_layout_ci.setLayoutCount = 0;
1516 pipeline_layout_ci.pSetLayouts = NULL;
1517
1518 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001519 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001520 ASSERT_VK_SUCCESS(err);
1521
1522 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1523 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1524 rs_ci.pNext = nullptr;
1525 rs_ci.lineWidth = 1.0f;
1526 rs_ci.rasterizerDiscardEnable = true;
1527
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001528 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1529 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001530
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001531 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1533 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001534 {
1535 VkPipelineObj pipe(&test_device);
1536 pipe.AddShader(&vs);
1537 pipe.AddShader(&fs);
1538 pipe.AddColorAttachment();
1539 // Introduce failure by setting unsupported polygon mode
1540 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1541 pipe.SetRasterization(&rs_ci);
1542 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1543 }
1544 m_errorMonitor->VerifyFound();
1545
1546 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1548 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001549 {
1550 VkPipelineObj pipe(&test_device);
1551 pipe.AddShader(&vs);
1552 pipe.AddShader(&fs);
1553 pipe.AddColorAttachment();
1554 // Introduce failure by setting unsupported polygon mode
1555 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1556 pipe.SetRasterization(&rs_ci);
1557 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1558 }
1559 m_errorMonitor->VerifyFound();
1560
1561 // Try again with polygonMode=FILL. No error is expected
1562 m_errorMonitor->ExpectSuccess();
1563 {
1564 VkPipelineObj pipe(&test_device);
1565 pipe.AddShader(&vs);
1566 pipe.AddShader(&fs);
1567 pipe.AddColorAttachment();
1568 // Set polygonMode to a good value
1569 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
1570 pipe.SetRasterization(&rs_ci);
1571 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1572 }
1573 m_errorMonitor->VerifyNotFound();
1574
1575 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1576}
1577
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001578#endif // PARAMETER_VALIDATION_TESTS
1579
Tobin Ehlis0788f522015-05-26 16:11:58 -06001580#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001581#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001582TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001583{
1584 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001585 VkFenceCreateInfo fenceInfo = {};
1586 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1587 fenceInfo.pNext = NULL;
1588 fenceInfo.flags = 0;
1589
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001591
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001592 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001593
1594 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1595 vk_testing::Buffer buffer;
1596 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001597
Tony Barbourfe3351b2015-07-28 10:17:20 -06001598 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001599 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001600 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001601
1602 testFence.init(*m_device, fenceInfo);
1603
1604 // Bypass framework since it does the waits automatically
1605 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001606 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001607 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1608 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001609 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001610 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001611 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001612 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001613 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001614 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001615 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001616
1617 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001618 ASSERT_VK_SUCCESS( err );
1619
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001620 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001621 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001622
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001623 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001624}
1625
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001626TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001627{
1628 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001629 VkFenceCreateInfo fenceInfo = {};
1630 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1631 fenceInfo.pNext = NULL;
1632 fenceInfo.flags = 0;
1633
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001635
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001636 ASSERT_NO_FATAL_FAILURE(InitState());
1637 ASSERT_NO_FATAL_FAILURE(InitViewport());
1638 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1639
Tony Barbourfe3351b2015-07-28 10:17:20 -06001640 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001641 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001642 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001643
1644 testFence.init(*m_device, fenceInfo);
1645
1646 // Bypass framework since it does the waits automatically
1647 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001648 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001649 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1650 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001651 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001652 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001653 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001654 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001655 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001656 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001657 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001658
1659 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001660 ASSERT_VK_SUCCESS( err );
1661
Jon Ashburnf19916e2016-01-11 13:12:43 -07001662 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001663 VkCommandBufferBeginInfo info = {};
1664 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1665 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001666 info.renderPass = VK_NULL_HANDLE;
1667 info.subpass = 0;
1668 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001669 info.occlusionQueryEnable = VK_FALSE;
1670 info.queryFlags = 0;
1671 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001672
1673 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001674 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001675
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001676 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001677}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001678#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001679
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001680// This is a positive test. No failures are expected.
1681TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1682 VkResult err;
1683 bool pass;
1684
1685 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1686 "the buffer, create an image, and bind the same memory to "
1687 "it");
1688
1689 m_errorMonitor->ExpectSuccess();
1690
1691 ASSERT_NO_FATAL_FAILURE(InitState());
1692
1693 VkBuffer buffer;
1694 VkImage image;
1695 VkDeviceMemory mem;
1696 VkMemoryRequirements mem_reqs;
1697
1698 VkBufferCreateInfo buf_info = {};
1699 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1700 buf_info.pNext = NULL;
1701 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1702 buf_info.size = 256;
1703 buf_info.queueFamilyIndexCount = 0;
1704 buf_info.pQueueFamilyIndices = NULL;
1705 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1706 buf_info.flags = 0;
1707 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1708 ASSERT_VK_SUCCESS(err);
1709
1710 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1711
1712 VkMemoryAllocateInfo alloc_info = {};
1713 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1714 alloc_info.pNext = NULL;
1715 alloc_info.memoryTypeIndex = 0;
1716
1717 // Ensure memory is big enough for both bindings
1718 alloc_info.allocationSize = 0x10000;
1719
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001720 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 -06001721 if (!pass) {
1722 vkDestroyBuffer(m_device->device(), buffer, NULL);
1723 return;
1724 }
1725
1726 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1727 ASSERT_VK_SUCCESS(err);
1728
1729 uint8_t *pData;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001730 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001731 ASSERT_VK_SUCCESS(err);
1732
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001733 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001734
1735 vkUnmapMemory(m_device->device(), mem);
1736
1737 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1738 ASSERT_VK_SUCCESS(err);
1739
1740 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1741 // memory. In fact, it was never used by the GPU.
1742 // Just be be sure, wait for idle.
1743 vkDestroyBuffer(m_device->device(), buffer, NULL);
1744 vkDeviceWaitIdle(m_device->device());
1745
1746 VkImageCreateInfo image_create_info = {};
1747 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1748 image_create_info.pNext = NULL;
1749 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1750 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1751 image_create_info.extent.width = 64;
1752 image_create_info.extent.height = 64;
1753 image_create_info.extent.depth = 1;
1754 image_create_info.mipLevels = 1;
1755 image_create_info.arrayLayers = 1;
1756 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1757 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1758 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1759 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1760 image_create_info.queueFamilyIndexCount = 0;
1761 image_create_info.pQueueFamilyIndices = NULL;
1762 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1763 image_create_info.flags = 0;
1764
1765 VkMemoryAllocateInfo mem_alloc = {};
1766 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1767 mem_alloc.pNext = NULL;
1768 mem_alloc.allocationSize = 0;
1769 mem_alloc.memoryTypeIndex = 0;
1770
1771 /* Create a mappable image. It will be the texture if linear images are ok
1772 * to be textures or it will be the staging image if they are not.
1773 */
1774 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1775 ASSERT_VK_SUCCESS(err);
1776
1777 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1778
1779 mem_alloc.allocationSize = mem_reqs.size;
1780
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001781 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 -06001782 if (!pass) {
1783 vkDestroyImage(m_device->device(), image, NULL);
1784 return;
1785 }
1786
Tobin Ehlis077ded32016-05-12 17:39:13 -06001787 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001788 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1789 ASSERT_VK_SUCCESS(err);
1790
1791 m_errorMonitor->VerifyNotFound();
1792
Tony Barbourdf4c0042016-06-01 15:55:43 -06001793 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001794 vkDestroyBuffer(m_device->device(), buffer, NULL);
1795 vkDestroyImage(m_device->device(), image, NULL);
1796}
1797
Tobin Ehlisf11be982016-05-11 13:52:53 -06001798TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1799 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1800 "buffer and image to memory such that they will alias.");
1801 VkResult err;
1802 bool pass;
1803 ASSERT_NO_FATAL_FAILURE(InitState());
1804
Tobin Ehlis077ded32016-05-12 17:39:13 -06001805 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001806 VkImage image;
1807 VkDeviceMemory mem; // buffer will be bound first
1808 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001809 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001810
1811 VkBufferCreateInfo buf_info = {};
1812 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1813 buf_info.pNext = NULL;
1814 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1815 buf_info.size = 256;
1816 buf_info.queueFamilyIndexCount = 0;
1817 buf_info.pQueueFamilyIndices = NULL;
1818 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1819 buf_info.flags = 0;
1820 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1821 ASSERT_VK_SUCCESS(err);
1822
Tobin Ehlis077ded32016-05-12 17:39:13 -06001823 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001824
1825 VkImageCreateInfo image_create_info = {};
1826 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1827 image_create_info.pNext = NULL;
1828 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1829 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1830 image_create_info.extent.width = 64;
1831 image_create_info.extent.height = 64;
1832 image_create_info.extent.depth = 1;
1833 image_create_info.mipLevels = 1;
1834 image_create_info.arrayLayers = 1;
1835 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001836 // Image tiling must be optimal to trigger error when aliasing linear buffer
1837 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001838 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1839 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1840 image_create_info.queueFamilyIndexCount = 0;
1841 image_create_info.pQueueFamilyIndices = NULL;
1842 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1843 image_create_info.flags = 0;
1844
Tobin Ehlisf11be982016-05-11 13:52:53 -06001845 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1846 ASSERT_VK_SUCCESS(err);
1847
Tobin Ehlis077ded32016-05-12 17:39:13 -06001848 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1849
1850 VkMemoryAllocateInfo alloc_info = {};
1851 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1852 alloc_info.pNext = NULL;
1853 alloc_info.memoryTypeIndex = 0;
1854 // Ensure memory is big enough for both bindings
1855 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001856 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1857 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001858 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001859 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001860 vkDestroyImage(m_device->device(), image, NULL);
1861 return;
1862 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001863 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1864 ASSERT_VK_SUCCESS(err);
1865 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1866 ASSERT_VK_SUCCESS(err);
1867
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001869 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001870 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1871 m_errorMonitor->VerifyFound();
1872
1873 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001874 // aliasing buffer2
1875 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1876 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001877 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1878 ASSERT_VK_SUCCESS(err);
1879 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1880 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001882 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001883 m_errorMonitor->VerifyFound();
1884
1885 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001886 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001887 vkDestroyImage(m_device->device(), image, NULL);
1888 vkFreeMemory(m_device->device(), mem, NULL);
1889 vkFreeMemory(m_device->device(), mem_img, NULL);
1890}
1891
Tobin Ehlis35372522016-05-12 08:32:31 -06001892TEST_F(VkLayerTest, InvalidMemoryMapping) {
1893 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1894 VkResult err;
1895 bool pass;
1896 ASSERT_NO_FATAL_FAILURE(InitState());
1897
1898 VkBuffer buffer;
1899 VkDeviceMemory mem;
1900 VkMemoryRequirements mem_reqs;
1901
1902 VkBufferCreateInfo buf_info = {};
1903 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1904 buf_info.pNext = NULL;
1905 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1906 buf_info.size = 256;
1907 buf_info.queueFamilyIndexCount = 0;
1908 buf_info.pQueueFamilyIndices = NULL;
1909 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1910 buf_info.flags = 0;
1911 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1912 ASSERT_VK_SUCCESS(err);
1913
1914 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1915 VkMemoryAllocateInfo alloc_info = {};
1916 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1917 alloc_info.pNext = NULL;
1918 alloc_info.memoryTypeIndex = 0;
1919
1920 // Ensure memory is big enough for both bindings
1921 static const VkDeviceSize allocation_size = 0x10000;
1922 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001923 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 -06001924 if (!pass) {
1925 vkDestroyBuffer(m_device->device(), buffer, NULL);
1926 return;
1927 }
1928 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1929 ASSERT_VK_SUCCESS(err);
1930
1931 uint8_t *pData;
1932 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001933 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 -06001934 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1935 m_errorMonitor->VerifyFound();
1936 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001937 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001938 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1940 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1941 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001942 m_errorMonitor->VerifyFound();
1943
1944 // Unmap the memory to avoid re-map error
1945 vkUnmapMemory(m_device->device(), mem);
1946 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1948 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1949 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001950 m_errorMonitor->VerifyFound();
1951 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1953 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001954 m_errorMonitor->VerifyFound();
1955 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001957 vkUnmapMemory(m_device->device(), mem);
1958 m_errorMonitor->VerifyFound();
1959 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001960 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001961 ASSERT_VK_SUCCESS(err);
1962 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001963 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001964 mmr.memory = mem;
1965 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") is less than Memory Object's offset (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001967 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1968 m_errorMonitor->VerifyFound();
1969 // Now flush range that oversteps mapped range
1970 vkUnmapMemory(m_device->device(), mem);
1971 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1972 ASSERT_VK_SUCCESS(err);
1973 mmr.offset = 16;
1974 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") exceeds the Memory Object's upper-bound (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001976 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1977 m_errorMonitor->VerifyFound();
1978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001979 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1980 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001981 if (!pass) {
1982 vkFreeMemory(m_device->device(), mem, NULL);
1983 vkDestroyBuffer(m_device->device(), buffer, NULL);
1984 return;
1985 }
1986 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1987 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1988
1989 vkDestroyBuffer(m_device->device(), buffer, NULL);
1990 vkFreeMemory(m_device->device(), mem, NULL);
1991}
1992
Mark Lobodzinski1f515922016-08-16 10:03:30 -06001993TEST_F(VkLayerTest, NonCoherentMemoryMapping) {
1994
1995 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
1996 "mapping while using VK_WHOLE_SIZE does not cause access "
1997 "violations");
1998 VkResult err;
1999 uint8_t *pData;
2000 ASSERT_NO_FATAL_FAILURE(InitState());
2001
2002 VkDeviceMemory mem;
2003 VkMemoryRequirements mem_reqs;
2004 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
2005 VkMemoryAllocateInfo alloc_info = {};
2006 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2007 alloc_info.pNext = NULL;
2008 alloc_info.memoryTypeIndex = 0;
2009
2010 static const VkDeviceSize allocation_size = 0x1000;
2011 alloc_info.allocationSize = allocation_size;
2012
2013 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002014 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
2015 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002016 if (!pass) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002017 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
2018 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
2019 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002020 if (!pass) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002021 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
2022 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
2023 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
2024 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002025 if (!pass) {
2026 return;
2027 }
2028 }
2029 }
2030
2031 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
2032 ASSERT_VK_SUCCESS(err);
2033
2034 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
2035 // mapped range
2036 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002037 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002038 ASSERT_VK_SUCCESS(err);
2039 VkMappedMemoryRange mmr = {};
2040 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2041 mmr.memory = mem;
2042 mmr.offset = 0;
2043 mmr.size = VK_WHOLE_SIZE;
2044 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2045 ASSERT_VK_SUCCESS(err);
2046 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2047 ASSERT_VK_SUCCESS(err);
2048 m_errorMonitor->VerifyNotFound();
2049 vkUnmapMemory(m_device->device(), mem);
2050
2051 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
2052 // mapped range
2053 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002054 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002055 ASSERT_VK_SUCCESS(err);
2056 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2057 mmr.memory = mem;
2058 mmr.offset = 13;
2059 mmr.size = VK_WHOLE_SIZE;
2060 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2061 ASSERT_VK_SUCCESS(err);
2062 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2063 ASSERT_VK_SUCCESS(err);
2064 m_errorMonitor->VerifyNotFound();
2065 vkUnmapMemory(m_device->device(), mem);
2066
2067 // Map with prime offset and size
2068 // Flush/Invalidate subrange of mapped area with prime offset and size
2069 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002070 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002071 ASSERT_VK_SUCCESS(err);
2072 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2073 mmr.memory = mem;
2074 mmr.offset = allocation_size - 107;
2075 mmr.size = 61;
2076 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2077 ASSERT_VK_SUCCESS(err);
2078 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2079 ASSERT_VK_SUCCESS(err);
2080 m_errorMonitor->VerifyNotFound();
2081 vkUnmapMemory(m_device->device(), mem);
2082
2083 vkFreeMemory(m_device->device(), mem, NULL);
2084}
2085
Ian Elliott1c32c772016-04-28 14:47:13 -06002086TEST_F(VkLayerTest, EnableWsiBeforeUse) {
2087 VkResult err;
2088 bool pass;
2089
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002090 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
2091 // following declaration (which is temporarily being moved below):
2092 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002093 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2094 VkSwapchainCreateInfoKHR swapchain_create_info = {};
2095 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002096 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06002097 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002098 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06002099
2100 ASSERT_NO_FATAL_FAILURE(InitState());
2101
Ian Elliott3f06ce52016-04-29 14:46:21 -06002102#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
2103#if defined(VK_USE_PLATFORM_ANDROID_KHR)
2104 // Use the functions from the VK_KHR_android_surface extension without
2105 // enabling that extension:
2106
2107 // Create a surface:
2108 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2110 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002111 pass = (err != VK_SUCCESS);
2112 ASSERT_TRUE(pass);
2113 m_errorMonitor->VerifyFound();
2114#endif // VK_USE_PLATFORM_ANDROID_KHR
2115
Ian Elliott3f06ce52016-04-29 14:46:21 -06002116#if defined(VK_USE_PLATFORM_MIR_KHR)
2117 // Use the functions from the VK_KHR_mir_surface extension without enabling
2118 // that extension:
2119
2120 // Create a surface:
2121 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06002123 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
2124 pass = (err != VK_SUCCESS);
2125 ASSERT_TRUE(pass);
2126 m_errorMonitor->VerifyFound();
2127
2128 // Tell whether an mir_connection supports presentation:
2129 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2131 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002132 m_errorMonitor->VerifyFound();
2133#endif // VK_USE_PLATFORM_MIR_KHR
2134
Ian Elliott3f06ce52016-04-29 14:46:21 -06002135#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
2136 // Use the functions from the VK_KHR_wayland_surface extension without
2137 // enabling that extension:
2138
2139 // Create a surface:
2140 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2142 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002143 pass = (err != VK_SUCCESS);
2144 ASSERT_TRUE(pass);
2145 m_errorMonitor->VerifyFound();
2146
2147 // Tell whether an wayland_display supports presentation:
2148 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2150 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002151 m_errorMonitor->VerifyFound();
2152#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06002153#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06002154
Ian Elliott3f06ce52016-04-29 14:46:21 -06002155#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002156 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2157 // TO NON-LINUX PLATFORMS:
2158 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06002159 // Use the functions from the VK_KHR_win32_surface extension without
2160 // enabling that extension:
2161
2162 // Create a surface:
2163 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2165 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002166 pass = (err != VK_SUCCESS);
2167 ASSERT_TRUE(pass);
2168 m_errorMonitor->VerifyFound();
2169
2170 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06002172 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002173 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002174// Set this (for now, until all platforms are supported and tested):
2175#define NEED_TO_TEST_THIS_ON_PLATFORM
2176#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06002177
Ian Elliott1c32c772016-04-28 14:47:13 -06002178#if defined(VK_USE_PLATFORM_XCB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002179 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2180 // TO NON-LINUX PLATFORMS:
2181 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002182 // Use the functions from the VK_KHR_xcb_surface extension without enabling
2183 // that extension:
2184
2185 // Create a surface:
2186 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002188 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2189 pass = (err != VK_SUCCESS);
2190 ASSERT_TRUE(pass);
2191 m_errorMonitor->VerifyFound();
2192
2193 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06002194 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06002195 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2197 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06002198 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002199// Set this (for now, until all platforms are supported and tested):
2200#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002201#endif // VK_USE_PLATFORM_XCB_KHR
2202
Ian Elliott12630812016-04-29 14:35:43 -06002203#if defined(VK_USE_PLATFORM_XLIB_KHR)
2204 // Use the functions from the VK_KHR_xlib_surface extension without enabling
2205 // that extension:
2206
2207 // Create a surface:
2208 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002210 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
2211 pass = (err != VK_SUCCESS);
2212 ASSERT_TRUE(pass);
2213 m_errorMonitor->VerifyFound();
2214
2215 // Tell whether an Xlib VisualID supports presentation:
2216 Display *dpy = NULL;
2217 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002219 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
2220 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002221// Set this (for now, until all platforms are supported and tested):
2222#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06002223#endif // VK_USE_PLATFORM_XLIB_KHR
2224
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002225// Use the functions from the VK_KHR_surface extension without enabling
2226// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002227
Ian Elliott489eec02016-05-05 14:12:44 -06002228#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002229 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002231 vkDestroySurfaceKHR(instance(), surface, NULL);
2232 m_errorMonitor->VerifyFound();
2233
2234 // Check if surface supports presentation:
2235 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002237 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2238 pass = (err != VK_SUCCESS);
2239 ASSERT_TRUE(pass);
2240 m_errorMonitor->VerifyFound();
2241
2242 // Check surface capabilities:
2243 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2245 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06002246 pass = (err != VK_SUCCESS);
2247 ASSERT_TRUE(pass);
2248 m_errorMonitor->VerifyFound();
2249
2250 // Check surface formats:
2251 uint32_t format_count = 0;
2252 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2254 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06002255 pass = (err != VK_SUCCESS);
2256 ASSERT_TRUE(pass);
2257 m_errorMonitor->VerifyFound();
2258
2259 // Check surface present modes:
2260 uint32_t present_mode_count = 0;
2261 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2263 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06002264 pass = (err != VK_SUCCESS);
2265 ASSERT_TRUE(pass);
2266 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002267#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002268
Ian Elliott1c32c772016-04-28 14:47:13 -06002269 // Use the functions from the VK_KHR_swapchain extension without enabling
2270 // that extension:
2271
2272 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002274 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2275 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002276 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06002277 pass = (err != VK_SUCCESS);
2278 ASSERT_TRUE(pass);
2279 m_errorMonitor->VerifyFound();
2280
2281 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2283 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06002284 pass = (err != VK_SUCCESS);
2285 ASSERT_TRUE(pass);
2286 m_errorMonitor->VerifyFound();
2287
2288 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2290 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06002291 pass = (err != VK_SUCCESS);
2292 ASSERT_TRUE(pass);
2293 m_errorMonitor->VerifyFound();
2294
2295 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002296 //
2297 // NOTE: Currently can't test this because a real swapchain is needed (as
2298 // opposed to the fake one we created) in order for the layer to lookup the
2299 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002300
2301 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002303 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
2304 m_errorMonitor->VerifyFound();
2305}
2306
Ian Elliott2c1daf52016-05-12 09:41:46 -06002307TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06002308
Dustin Graves6c6d8982016-05-17 10:09:21 -06002309#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06002310 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002311
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002312 VkResult err;
2313 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002314 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2315 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002316 // uint32_t swapchain_image_count = 0;
2317 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
2318 // uint32_t image_index = 0;
2319 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06002320
2321 ASSERT_NO_FATAL_FAILURE(InitState());
2322
2323 // Use the create function from one of the VK_KHR_*_surface extension in
2324 // order to create a surface, testing all known errors in the process,
2325 // before successfully creating a surface:
2326 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002328 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
2329 pass = (err != VK_SUCCESS);
2330 ASSERT_TRUE(pass);
2331 m_errorMonitor->VerifyFound();
2332
2333 // Next, try to create a surface with the wrong
2334 // VkXcbSurfaceCreateInfoKHR::sType:
2335 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
2336 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002338 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2339 pass = (err != VK_SUCCESS);
2340 ASSERT_TRUE(pass);
2341 m_errorMonitor->VerifyFound();
2342
Ian Elliott2c1daf52016-05-12 09:41:46 -06002343 // Create a native window, and then correctly create a surface:
2344 xcb_connection_t *connection;
2345 xcb_screen_t *screen;
2346 xcb_window_t xcb_window;
2347 xcb_intern_atom_reply_t *atom_wm_delete_window;
2348
2349 const xcb_setup_t *setup;
2350 xcb_screen_iterator_t iter;
2351 int scr;
2352 uint32_t value_mask, value_list[32];
2353 int width = 1;
2354 int height = 1;
2355
2356 connection = xcb_connect(NULL, &scr);
2357 ASSERT_TRUE(connection != NULL);
2358 setup = xcb_get_setup(connection);
2359 iter = xcb_setup_roots_iterator(setup);
2360 while (scr-- > 0)
2361 xcb_screen_next(&iter);
2362 screen = iter.data;
2363
2364 xcb_window = xcb_generate_id(connection);
2365
2366 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
2367 value_list[0] = screen->black_pixel;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002368 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002369
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002370 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
2371 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002372
2373 /* Magic code that will send notification when window is destroyed */
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002374 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
2375 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002376
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002377 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002378 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002379 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 -06002380 free(reply);
2381
2382 xcb_map_window(connection, xcb_window);
2383
2384 // Force the x/y coordinates to 100,100 results are identical in consecutive
2385 // runs
2386 const uint32_t coords[] = {100, 100};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002387 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002388
Ian Elliott2c1daf52016-05-12 09:41:46 -06002389 // Finally, try to correctly create a surface:
2390 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
2391 xcb_create_info.pNext = NULL;
2392 xcb_create_info.flags = 0;
2393 xcb_create_info.connection = connection;
2394 xcb_create_info.window = xcb_window;
2395 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2396 pass = (err == VK_SUCCESS);
2397 ASSERT_TRUE(pass);
2398
Ian Elliott2c1daf52016-05-12 09:41:46 -06002399 // Check if surface supports presentation:
2400
2401 // 1st, do so without having queried the queue families:
2402 VkBool32 supported = false;
2403 // TODO: Get the following error to come out:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2405 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
2406 "function");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002407 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2408 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002409 // ASSERT_TRUE(pass);
2410 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06002411
2412 // Next, query a queue family index that's too large:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2414 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002415 pass = (err != VK_SUCCESS);
2416 ASSERT_TRUE(pass);
2417 m_errorMonitor->VerifyFound();
2418
2419 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002420 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2421 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002422 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2423 pass = (err == VK_SUCCESS);
2424 ASSERT_TRUE(pass);
2425
Ian Elliott2c1daf52016-05-12 09:41:46 -06002426 // Before proceeding, try to create a swapchain without having called
2427 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
2428 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2429 swapchain_create_info.pNext = NULL;
2430 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2432 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
2433 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002434 pass = (err != VK_SUCCESS);
2435 ASSERT_TRUE(pass);
2436 m_errorMonitor->VerifyFound();
2437
Ian Elliott2c1daf52016-05-12 09:41:46 -06002438 // Get the surface capabilities:
2439 VkSurfaceCapabilitiesKHR surface_capabilities;
2440
2441 // Do so correctly (only error logged by this entrypoint is if the
2442 // extension isn't enabled):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002443 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002444 pass = (err == VK_SUCCESS);
2445 ASSERT_TRUE(pass);
2446
Ian Elliott2c1daf52016-05-12 09:41:46 -06002447 // Get the surface formats:
2448 uint32_t surface_format_count;
2449
2450 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
2452 "specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002453 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
2454 pass = (err == VK_SUCCESS);
2455 ASSERT_TRUE(pass);
2456 m_errorMonitor->VerifyFound();
2457
2458 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
2459 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002460 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 -06002461 surface_format_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002462 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002463 pass = (err == VK_SUCCESS);
2464 ASSERT_TRUE(pass);
2465 m_errorMonitor->VerifyFound();
2466
2467 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002468 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002469 pass = (err == VK_SUCCESS);
2470 ASSERT_TRUE(pass);
2471
2472 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002473 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002474
2475 // Next, do a 2nd try with surface_format_count being set too high:
2476 surface_format_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2478 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002479 pass = (err == VK_SUCCESS);
2480 ASSERT_TRUE(pass);
2481 m_errorMonitor->VerifyFound();
2482
2483 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002484 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002485 pass = (err == VK_SUCCESS);
2486 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002487 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002488 pass = (err == VK_SUCCESS);
2489 ASSERT_TRUE(pass);
2490
Ian Elliott2c1daf52016-05-12 09:41:46 -06002491 // Get the surface present modes:
2492 uint32_t surface_present_mode_count;
2493
2494 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
2496 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002497
Ian Elliott2c1daf52016-05-12 09:41:46 -06002498 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
2499 pass = (err == VK_SUCCESS);
2500 ASSERT_TRUE(pass);
2501 m_errorMonitor->VerifyFound();
2502
2503 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
2504 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002505 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 -06002506 surface_present_mode_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002507 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
2508 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002509 pass = (err == VK_SUCCESS);
2510 ASSERT_TRUE(pass);
2511 m_errorMonitor->VerifyFound();
2512
2513 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002514 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002515 pass = (err == VK_SUCCESS);
2516 ASSERT_TRUE(pass);
2517
2518 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002519 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002520
2521 // Next, do a 2nd try with surface_format_count being set too high:
2522 surface_present_mode_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2524 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002525 pass = (err == VK_SUCCESS);
2526 ASSERT_TRUE(pass);
2527 m_errorMonitor->VerifyFound();
2528
2529 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002530 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002531 pass = (err == VK_SUCCESS);
2532 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002533 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002534 pass = (err == VK_SUCCESS);
2535 ASSERT_TRUE(pass);
2536
Ian Elliott2c1daf52016-05-12 09:41:46 -06002537 // Create a swapchain:
2538
2539 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
2541 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002542
Ian Elliott2c1daf52016-05-12 09:41:46 -06002543 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
2544 pass = (err != VK_SUCCESS);
2545 ASSERT_TRUE(pass);
2546 m_errorMonitor->VerifyFound();
2547
2548 // Next, call with a non-NULL swapchain_create_info, that has the wrong
2549 // sType:
2550 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002552
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002553 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002554 pass = (err != VK_SUCCESS);
2555 ASSERT_TRUE(pass);
2556 m_errorMonitor->VerifyFound();
2557
2558 // Next, call with a NULL swapchain pointer:
2559 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2560 swapchain_create_info.pNext = NULL;
2561 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002562 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
2563 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002564
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002565 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002566 pass = (err != VK_SUCCESS);
2567 ASSERT_TRUE(pass);
2568 m_errorMonitor->VerifyFound();
2569
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002570 // TODO: Enhance swapchain layer so that
2571 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06002572
2573 // Next, call with a queue family index that's too large:
2574 uint32_t queueFamilyIndex[2] = {100000, 0};
2575 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2576 swapchain_create_info.queueFamilyIndexCount = 2;
2577 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2579 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002580 pass = (err != VK_SUCCESS);
2581 ASSERT_TRUE(pass);
2582 m_errorMonitor->VerifyFound();
2583
2584 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
2585 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2586 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2588 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
2589 "pCreateInfo->pQueueFamilyIndices).");
2590 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002591 pass = (err != VK_SUCCESS);
2592 ASSERT_TRUE(pass);
2593 m_errorMonitor->VerifyFound();
2594
2595 // Next, call with an invalid imageSharingMode:
2596 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
2597 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2599 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
2600 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002601 pass = (err != VK_SUCCESS);
2602 ASSERT_TRUE(pass);
2603 m_errorMonitor->VerifyFound();
2604 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002605 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2606 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002607 swapchain_create_info.queueFamilyIndexCount = 0;
2608 queueFamilyIndex[0] = 0;
2609 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2610
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002611 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002612 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002613 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002614 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002615 // Destroy the swapchain:
2616
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002617 // TODOs:
2618 //
2619 // - Try destroying the device without first destroying the swapchain
2620 //
2621 // - Try destroying the device without first destroying the surface
2622 //
2623 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002624
2625 // Destroy the surface:
2626 vkDestroySurfaceKHR(instance(), surface, NULL);
2627
Ian Elliott2c1daf52016-05-12 09:41:46 -06002628 // Tear down the window:
2629 xcb_destroy_window(connection, xcb_window);
2630 xcb_disconnect(connection);
2631
2632#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002633 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002634#endif // VK_USE_PLATFORM_XCB_KHR
2635}
2636
Karl Schultz6addd812016-02-02 17:17:23 -07002637TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2638 VkResult err;
2639 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002640
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2642 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002643
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002644 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002645
2646 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002647 VkImage image;
2648 VkDeviceMemory mem;
2649 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002650
Karl Schultz6addd812016-02-02 17:17:23 -07002651 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2652 const int32_t tex_width = 32;
2653 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002654
Tony Barboureb254902015-07-15 12:50:33 -06002655 VkImageCreateInfo image_create_info = {};
2656 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002657 image_create_info.pNext = NULL;
2658 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2659 image_create_info.format = tex_format;
2660 image_create_info.extent.width = tex_width;
2661 image_create_info.extent.height = tex_height;
2662 image_create_info.extent.depth = 1;
2663 image_create_info.mipLevels = 1;
2664 image_create_info.arrayLayers = 1;
2665 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2666 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2667 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2668 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002669
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002670 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002671 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002672 mem_alloc.pNext = NULL;
2673 mem_alloc.allocationSize = 0;
2674 // Introduce failure, do NOT set memProps to
2675 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
2676 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002677
Chia-I Wuf7458c52015-10-26 21:10:41 +08002678 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002679 ASSERT_VK_SUCCESS(err);
2680
Karl Schultz6addd812016-02-02 17:17:23 -07002681 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002682
Mark Lobodzinski23065352015-05-29 09:32:35 -05002683 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002684
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002685 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 -07002686 if (!pass) { // If we can't find any unmappable memory this test doesn't
2687 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002688 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002689 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002690 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002691
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002692 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002693 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002694 ASSERT_VK_SUCCESS(err);
2695
2696 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002697 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002698 ASSERT_VK_SUCCESS(err);
2699
2700 // Map memory as if to initialize the image
2701 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002702 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002703
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002704 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002705
Chia-I Wuf7458c52015-10-26 21:10:41 +08002706 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002707 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002708}
2709
Karl Schultz6addd812016-02-02 17:17:23 -07002710TEST_F(VkLayerTest, RebindMemory) {
2711 VkResult err;
2712 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002713
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002715
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002716 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002717
2718 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002719 VkImage image;
2720 VkDeviceMemory mem1;
2721 VkDeviceMemory mem2;
2722 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002723
Karl Schultz6addd812016-02-02 17:17:23 -07002724 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2725 const int32_t tex_width = 32;
2726 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002727
Tony Barboureb254902015-07-15 12:50:33 -06002728 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002729 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2730 image_create_info.pNext = NULL;
2731 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2732 image_create_info.format = tex_format;
2733 image_create_info.extent.width = tex_width;
2734 image_create_info.extent.height = tex_height;
2735 image_create_info.extent.depth = 1;
2736 image_create_info.mipLevels = 1;
2737 image_create_info.arrayLayers = 1;
2738 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2739 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2740 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2741 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002742
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002743 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002744 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2745 mem_alloc.pNext = NULL;
2746 mem_alloc.allocationSize = 0;
2747 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002748
Karl Schultz6addd812016-02-02 17:17:23 -07002749 // Introduce failure, do NOT set memProps to
2750 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002751 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002752 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002753 ASSERT_VK_SUCCESS(err);
2754
Karl Schultz6addd812016-02-02 17:17:23 -07002755 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002756
2757 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002758 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002759 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002760
2761 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002762 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002763 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002764 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002765 ASSERT_VK_SUCCESS(err);
2766
2767 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002768 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002769 ASSERT_VK_SUCCESS(err);
2770
Karl Schultz6addd812016-02-02 17:17:23 -07002771 // Introduce validation failure, try to bind a different memory object to
2772 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002773 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002774
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002775 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002776
Chia-I Wuf7458c52015-10-26 21:10:41 +08002777 vkDestroyImage(m_device->device(), image, NULL);
2778 vkFreeMemory(m_device->device(), mem1, NULL);
2779 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002780}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002781
Karl Schultz6addd812016-02-02 17:17:23 -07002782TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002783 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002784
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2786 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002787
2788 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002789 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2790 fenceInfo.pNext = NULL;
2791 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002792
Tony Barbour300a6082015-04-07 13:44:53 -06002793 ASSERT_NO_FATAL_FAILURE(InitState());
2794 ASSERT_NO_FATAL_FAILURE(InitViewport());
2795 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2796
Tony Barbourfe3351b2015-07-28 10:17:20 -06002797 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002798 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002799 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002800
2801 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002802
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002803 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002804 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2805 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002806 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002807 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002808 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002809 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002810 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002811 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002812 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002813
2814 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002815 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002816
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002817 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002818}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002819// This is a positive test. We used to expect error in this case but spec now
2820// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002821TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002822 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002823 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002824 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002825 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2826 fenceInfo.pNext = NULL;
2827
Tony Barbour0b4d9562015-04-09 10:48:04 -06002828 ASSERT_NO_FATAL_FAILURE(InitState());
2829 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002830 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002831 VkResult result = vkResetFences(m_device->device(), 1, fences);
2832 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002833
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002834 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002835}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002836#if 0 // A few devices have issues with this test so disabling for now
Chris Forbese70b7d32016-06-15 15:49:12 +12002837TEST_F(VkLayerTest, LongFenceChain)
2838{
2839 m_errorMonitor->ExpectSuccess();
2840
2841 ASSERT_NO_FATAL_FAILURE(InitState());
2842 VkResult err;
2843
2844 std::vector<VkFence> fences;
2845
2846 const int chainLength = 32768;
2847
2848 for (int i = 0; i < chainLength; i++) {
2849 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2850 VkFence fence;
2851 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2852 ASSERT_VK_SUCCESS(err);
2853
2854 fences.push_back(fence);
2855
2856 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2857 0, nullptr, 0, nullptr };
2858 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2859 ASSERT_VK_SUCCESS(err);
2860
2861 }
2862
2863 // BOOM, stack overflow.
2864 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
2865
2866 for (auto fence : fences)
2867 vkDestroyFence(m_device->device(), fence, nullptr);
2868
2869 m_errorMonitor->VerifyNotFound();
2870}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002871#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002872TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) {
Chris Forbes18127d12016-06-08 16:52:28 +12002873 m_errorMonitor->ExpectSuccess();
2874
2875 ASSERT_NO_FATAL_FAILURE(InitState());
2876 VkResult err;
2877
2878 // Record (empty!) command buffer that can be submitted multiple times
2879 // simultaneously.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002880 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
2881 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Chris Forbes18127d12016-06-08 16:52:28 +12002882 m_commandBuffer->BeginCommandBuffer(&cbbi);
2883 m_commandBuffer->EndCommandBuffer();
2884
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002885 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002886 VkFence fence;
2887 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2888 ASSERT_VK_SUCCESS(err);
2889
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002890 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002891 VkSemaphore s1, s2;
2892 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
2893 ASSERT_VK_SUCCESS(err);
2894 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
2895 ASSERT_VK_SUCCESS(err);
2896
2897 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002898 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Chris Forbes18127d12016-06-08 16:52:28 +12002899 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2900 ASSERT_VK_SUCCESS(err);
2901
2902 // Submit CB again, signaling s2.
2903 si.pSignalSemaphores = &s2;
2904 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
2905 ASSERT_VK_SUCCESS(err);
2906
2907 // Wait for fence.
2908 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2909 ASSERT_VK_SUCCESS(err);
2910
2911 // CB is still in flight from second submission, but semaphore s1 is no
2912 // longer in flight. delete it.
2913 vkDestroySemaphore(m_device->device(), s1, nullptr);
2914
2915 m_errorMonitor->VerifyNotFound();
2916
2917 // Force device idle and clean up remaining objects
2918 vkDeviceWaitIdle(m_device->device());
2919 vkDestroySemaphore(m_device->device(), s2, nullptr);
2920 vkDestroyFence(m_device->device(), fence, nullptr);
2921}
2922
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002923TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling) {
Chris Forbes4e44c912016-06-16 10:20:00 +12002924 m_errorMonitor->ExpectSuccess();
2925
2926 ASSERT_NO_FATAL_FAILURE(InitState());
2927 VkResult err;
2928
2929 // A fence created signaled
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002930 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Chris Forbes4e44c912016-06-16 10:20:00 +12002931 VkFence f1;
2932 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
2933 ASSERT_VK_SUCCESS(err);
2934
2935 // A fence created not
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002936 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes4e44c912016-06-16 10:20:00 +12002937 VkFence f2;
2938 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
2939 ASSERT_VK_SUCCESS(err);
2940
2941 // Submit the unsignaled fence
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002942 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Chris Forbes4e44c912016-06-16 10:20:00 +12002943 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
2944
2945 // Wait on both fences, with signaled first.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002946 VkFence fences[] = {f1, f2};
Chris Forbes4e44c912016-06-16 10:20:00 +12002947 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
2948
2949 // Should have both retired!
2950 vkDestroyFence(m_device->device(), f1, nullptr);
2951 vkDestroyFence(m_device->device(), f2, nullptr);
2952
2953 m_errorMonitor->VerifyNotFound();
2954}
2955
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002956TEST_F(VkLayerTest, InvalidUsageBits) {
2957 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
2958 "Initialize buffer with wrong usage then perform copy expecting errors "
2959 "from both the image and the buffer (2 calls)");
2960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002961
2962 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002963 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002964 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002965 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 -06002966 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002967
Tony Barbourf92621a2016-05-02 14:28:12 -06002968 VkImageView dsv;
2969 VkImageViewCreateInfo dsvci = {};
2970 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2971 dsvci.image = image.handle();
2972 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2973 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2974 dsvci.subresourceRange.layerCount = 1;
2975 dsvci.subresourceRange.baseMipLevel = 0;
2976 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002977 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002978
Tony Barbourf92621a2016-05-02 14:28:12 -06002979 // Create a view with depth / stencil aspect for image with different usage
2980 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002981
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002982 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002983
2984 // Initialize buffer with TRANSFER_DST usage
2985 vk_testing::Buffer buffer;
2986 VkMemoryPropertyFlags reqs = 0;
2987 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2988 VkBufferImageCopy region = {};
2989 region.bufferRowLength = 128;
2990 region.bufferImageHeight = 128;
2991 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2992 region.imageSubresource.layerCount = 1;
2993 region.imageExtent.height = 16;
2994 region.imageExtent.width = 16;
2995 region.imageExtent.depth = 1;
2996
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for buffer ");
Tony Barbourf92621a2016-05-02 14:28:12 -06002998 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2999 // TRANSFER_DST
3000 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003001 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3002 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003003 m_errorMonitor->VerifyFound();
3004
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
3006 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3007 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003008 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06003009}
Tony Barbour75d79f02016-08-30 09:39:07 -06003010
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003011TEST_F(VkLayerTest, ValidUsage) {
3012 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
3013 "doesn't generate validation errors");
Tony Barbour75d79f02016-08-30 09:39:07 -06003014
3015 ASSERT_NO_FATAL_FAILURE(InitState());
3016
3017 m_errorMonitor->ExpectSuccess();
3018 // Verify that we can create a view with usage INPUT_ATTACHMENT
3019 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003020 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 -06003021 ASSERT_TRUE(image.initialized());
3022 VkImageView imageView;
3023 VkImageViewCreateInfo ivci = {};
3024 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3025 ivci.image = image.handle();
3026 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3027 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
3028 ivci.subresourceRange.layerCount = 1;
3029 ivci.subresourceRange.baseMipLevel = 0;
3030 ivci.subresourceRange.levelCount = 1;
3031 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3032
3033 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
3034 m_errorMonitor->VerifyNotFound();
3035 vkDestroyImageView(m_device->device(), imageView, NULL);
3036}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003037#endif // MEM_TRACKER_TESTS
3038
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06003039#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003040
3041TEST_F(VkLayerTest, LeakAnObject) {
3042 VkResult err;
3043
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003044 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003045
3046 // Note that we have to create a new device since destroying the
3047 // framework's device causes Teardown() to fail and just calling Teardown
3048 // will destroy the errorMonitor.
3049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003051
3052 ASSERT_NO_FATAL_FAILURE(InitState());
3053
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003054 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003055 std::vector<VkDeviceQueueCreateInfo> queue_info;
3056 queue_info.reserve(queue_props.size());
3057 std::vector<std::vector<float>> queue_priorities;
3058 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
3059 VkDeviceQueueCreateInfo qi = {};
3060 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
3061 qi.pNext = NULL;
3062 qi.queueFamilyIndex = i;
3063 qi.queueCount = queue_props[i].queueCount;
3064 queue_priorities.emplace_back(qi.queueCount, 0.0f);
3065 qi.pQueuePriorities = queue_priorities[i].data();
3066 queue_info.push_back(qi);
3067 }
3068
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003069 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003070
3071 // The sacrificial device object
3072 VkDevice testDevice;
3073 VkDeviceCreateInfo device_create_info = {};
3074 auto features = m_device->phy().features();
3075 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
3076 device_create_info.pNext = NULL;
3077 device_create_info.queueCreateInfoCount = queue_info.size();
3078 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06003079 device_create_info.enabledLayerCount = 0;
3080 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003081 device_create_info.pEnabledFeatures = &features;
3082 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
3083 ASSERT_VK_SUCCESS(err);
3084
3085 VkFence fence;
3086 VkFenceCreateInfo fence_create_info = {};
3087 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3088 fence_create_info.pNext = NULL;
3089 fence_create_info.flags = 0;
3090 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
3091 ASSERT_VK_SUCCESS(err);
3092
3093 // Induce failure by not calling vkDestroyFence
3094 vkDestroyDevice(testDevice, NULL);
3095 m_errorMonitor->VerifyFound();
3096}
3097
3098TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
3099
3100 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
3101 "attempt to delete them from another.");
3102
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003104
Cody Northropc31a84f2016-08-22 10:41:47 -06003105 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003106 VkCommandPool command_pool_one;
3107 VkCommandPool command_pool_two;
3108
3109 VkCommandPoolCreateInfo pool_create_info{};
3110 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3111 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3112 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3113
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003114 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003115
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003116 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003117
3118 VkCommandBuffer command_buffer[9];
3119 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003120 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003121 command_buffer_allocate_info.commandPool = command_pool_one;
3122 command_buffer_allocate_info.commandBufferCount = 9;
3123 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003124 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003125
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003126 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003127
3128 m_errorMonitor->VerifyFound();
3129
3130 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
3131 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
3132}
3133
3134TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
3135 VkResult err;
3136
3137 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003138 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003139
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003141
3142 ASSERT_NO_FATAL_FAILURE(InitState());
3143 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3144
3145 VkDescriptorPoolSize ds_type_count = {};
3146 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3147 ds_type_count.descriptorCount = 1;
3148
3149 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3150 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3151 ds_pool_ci.pNext = NULL;
3152 ds_pool_ci.flags = 0;
3153 ds_pool_ci.maxSets = 1;
3154 ds_pool_ci.poolSizeCount = 1;
3155 ds_pool_ci.pPoolSizes = &ds_type_count;
3156
3157 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003158 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003159 ASSERT_VK_SUCCESS(err);
3160
3161 // Create a second descriptor pool
3162 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003163 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003164 ASSERT_VK_SUCCESS(err);
3165
3166 VkDescriptorSetLayoutBinding dsl_binding = {};
3167 dsl_binding.binding = 0;
3168 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3169 dsl_binding.descriptorCount = 1;
3170 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3171 dsl_binding.pImmutableSamplers = NULL;
3172
3173 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3174 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3175 ds_layout_ci.pNext = NULL;
3176 ds_layout_ci.bindingCount = 1;
3177 ds_layout_ci.pBindings = &dsl_binding;
3178
3179 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003180 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003181 ASSERT_VK_SUCCESS(err);
3182
3183 VkDescriptorSet descriptorSet;
3184 VkDescriptorSetAllocateInfo alloc_info = {};
3185 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3186 alloc_info.descriptorSetCount = 1;
3187 alloc_info.descriptorPool = ds_pool_one;
3188 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003189 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003190 ASSERT_VK_SUCCESS(err);
3191
3192 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
3193
3194 m_errorMonitor->VerifyFound();
3195
3196 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3197 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
3198 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
3199}
3200
3201TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003203
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003204 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003205
3206 ASSERT_NO_FATAL_FAILURE(InitState());
3207
3208 // Pass bogus handle into GetImageMemoryRequirements
3209 VkMemoryRequirements mem_reqs;
3210 uint64_t fakeImageHandle = 0xCADECADE;
3211 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
3212
3213 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
3214
3215 m_errorMonitor->VerifyFound();
3216}
3217
Karl Schultz6addd812016-02-02 17:17:23 -07003218TEST_F(VkLayerTest, PipelineNotBound) {
3219 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003220
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003221 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003222
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003224
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003225 ASSERT_NO_FATAL_FAILURE(InitState());
3226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003227
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003228 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003229 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3230 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003231
3232 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003233 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3234 ds_pool_ci.pNext = NULL;
3235 ds_pool_ci.maxSets = 1;
3236 ds_pool_ci.poolSizeCount = 1;
3237 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003238
3239 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003240 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003241 ASSERT_VK_SUCCESS(err);
3242
3243 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003244 dsl_binding.binding = 0;
3245 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3246 dsl_binding.descriptorCount = 1;
3247 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3248 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003249
3250 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003251 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3252 ds_layout_ci.pNext = NULL;
3253 ds_layout_ci.bindingCount = 1;
3254 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003255
3256 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003257 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003258 ASSERT_VK_SUCCESS(err);
3259
3260 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003261 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003262 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003263 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003264 alloc_info.descriptorPool = ds_pool;
3265 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003266 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003267 ASSERT_VK_SUCCESS(err);
3268
3269 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003270 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3271 pipeline_layout_ci.pNext = NULL;
3272 pipeline_layout_ci.setLayoutCount = 1;
3273 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003274
3275 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003276 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003277 ASSERT_VK_SUCCESS(err);
3278
Mark Youngad779052016-01-06 14:26:04 -07003279 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003280
3281 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003282 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003283
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003284 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003285
Chia-I Wuf7458c52015-10-26 21:10:41 +08003286 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3287 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3288 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003289}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003290
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003291TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
3292 VkResult err;
3293
3294 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
3295 "during bind[Buffer|Image]Memory time");
3296
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003297 ASSERT_NO_FATAL_FAILURE(InitState());
3298
3299 // Create an image, allocate memory, set a bad typeIndex and then try to
3300 // bind it
3301 VkImage image;
3302 VkDeviceMemory mem;
3303 VkMemoryRequirements mem_reqs;
3304 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3305 const int32_t tex_width = 32;
3306 const int32_t tex_height = 32;
3307
3308 VkImageCreateInfo image_create_info = {};
3309 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3310 image_create_info.pNext = NULL;
3311 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3312 image_create_info.format = tex_format;
3313 image_create_info.extent.width = tex_width;
3314 image_create_info.extent.height = tex_height;
3315 image_create_info.extent.depth = 1;
3316 image_create_info.mipLevels = 1;
3317 image_create_info.arrayLayers = 1;
3318 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3319 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3320 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3321 image_create_info.flags = 0;
3322
3323 VkMemoryAllocateInfo mem_alloc = {};
3324 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3325 mem_alloc.pNext = NULL;
3326 mem_alloc.allocationSize = 0;
3327 mem_alloc.memoryTypeIndex = 0;
3328
3329 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
3330 ASSERT_VK_SUCCESS(err);
3331
3332 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
3333 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003334
3335 // Introduce Failure, select invalid TypeIndex
3336 VkPhysicalDeviceMemoryProperties memory_info;
3337
3338 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
3339 unsigned int i;
3340 for (i = 0; i < memory_info.memoryTypeCount; i++) {
3341 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
3342 mem_alloc.memoryTypeIndex = i;
3343 break;
3344 }
3345 }
3346 if (i >= memory_info.memoryTypeCount) {
3347 printf("No invalid memory type index could be found; skipped.\n");
3348 vkDestroyImage(m_device->device(), image, NULL);
3349 return;
3350 }
3351
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003352 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 -06003353
3354 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3355 ASSERT_VK_SUCCESS(err);
3356
3357 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3358 (void)err;
3359
3360 m_errorMonitor->VerifyFound();
3361
3362 vkDestroyImage(m_device->device(), image, NULL);
3363 vkFreeMemory(m_device->device(), mem, NULL);
3364}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003365
Karl Schultz6addd812016-02-02 17:17:23 -07003366TEST_F(VkLayerTest, BindInvalidMemory) {
3367 VkResult err;
3368 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003369
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003371
Tobin Ehlisec598302015-09-15 15:02:17 -06003372 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003373
3374 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07003375 VkImage image;
3376 VkDeviceMemory mem;
3377 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003378
Karl Schultz6addd812016-02-02 17:17:23 -07003379 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3380 const int32_t tex_width = 32;
3381 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003382
3383 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003384 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3385 image_create_info.pNext = NULL;
3386 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3387 image_create_info.format = tex_format;
3388 image_create_info.extent.width = tex_width;
3389 image_create_info.extent.height = tex_height;
3390 image_create_info.extent.depth = 1;
3391 image_create_info.mipLevels = 1;
3392 image_create_info.arrayLayers = 1;
3393 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3394 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3395 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3396 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003397
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003398 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003399 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3400 mem_alloc.pNext = NULL;
3401 mem_alloc.allocationSize = 0;
3402 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003403
Chia-I Wuf7458c52015-10-26 21:10:41 +08003404 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003405 ASSERT_VK_SUCCESS(err);
3406
Karl Schultz6addd812016-02-02 17:17:23 -07003407 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003408
3409 mem_alloc.allocationSize = mem_reqs.size;
3410
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003411 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003412 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003413
3414 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003415 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003416 ASSERT_VK_SUCCESS(err);
3417
3418 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003419 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003420
3421 // Try to bind free memory that has been freed
3422 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3423 // This may very well return an error.
3424 (void)err;
3425
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003426 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003427
Chia-I Wuf7458c52015-10-26 21:10:41 +08003428 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003429}
3430
Karl Schultz6addd812016-02-02 17:17:23 -07003431TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
3432 VkResult err;
3433 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003434
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003436
Tobin Ehlisec598302015-09-15 15:02:17 -06003437 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003438
Karl Schultz6addd812016-02-02 17:17:23 -07003439 // Create an image object, allocate memory, destroy the object and then try
3440 // to bind it
3441 VkImage image;
3442 VkDeviceMemory mem;
3443 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003444
Karl Schultz6addd812016-02-02 17:17:23 -07003445 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3446 const int32_t tex_width = 32;
3447 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003448
3449 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003450 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3451 image_create_info.pNext = NULL;
3452 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3453 image_create_info.format = tex_format;
3454 image_create_info.extent.width = tex_width;
3455 image_create_info.extent.height = tex_height;
3456 image_create_info.extent.depth = 1;
3457 image_create_info.mipLevels = 1;
3458 image_create_info.arrayLayers = 1;
3459 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3460 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3461 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3462 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003463
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003464 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003465 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3466 mem_alloc.pNext = NULL;
3467 mem_alloc.allocationSize = 0;
3468 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003469
Chia-I Wuf7458c52015-10-26 21:10:41 +08003470 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003471 ASSERT_VK_SUCCESS(err);
3472
Karl Schultz6addd812016-02-02 17:17:23 -07003473 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003474
3475 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003476 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003477 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003478
3479 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003480 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003481 ASSERT_VK_SUCCESS(err);
3482
3483 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003484 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003485 ASSERT_VK_SUCCESS(err);
3486
3487 // Now Try to bind memory to this destroyed object
3488 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3489 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07003490 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003491
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003492 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003493
Chia-I Wuf7458c52015-10-26 21:10:41 +08003494 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003495}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003496
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003497#endif // OBJ_TRACKER_TESTS
3498
Tobin Ehlis0788f522015-05-26 16:11:58 -06003499#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003500
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003501TEST_F(VkLayerTest, ImageSampleCounts) {
3502
3503 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
3504 "validation errors.");
3505 ASSERT_NO_FATAL_FAILURE(InitState());
3506
3507 VkMemoryPropertyFlags reqs = 0;
3508 VkImageCreateInfo image_create_info = {};
3509 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3510 image_create_info.pNext = NULL;
3511 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3512 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3513 image_create_info.extent.width = 256;
3514 image_create_info.extent.height = 256;
3515 image_create_info.extent.depth = 1;
3516 image_create_info.mipLevels = 1;
3517 image_create_info.arrayLayers = 1;
3518 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3519 image_create_info.flags = 0;
3520
3521 VkImageBlit blit_region = {};
3522 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3523 blit_region.srcSubresource.baseArrayLayer = 0;
3524 blit_region.srcSubresource.layerCount = 1;
3525 blit_region.srcSubresource.mipLevel = 0;
3526 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3527 blit_region.dstSubresource.baseArrayLayer = 0;
3528 blit_region.dstSubresource.layerCount = 1;
3529 blit_region.dstSubresource.mipLevel = 0;
3530
3531 // Create two images, the source with sampleCount = 2, and attempt to blit
3532 // between them
3533 {
3534 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003535 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003536 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003537 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003538 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003539 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003540 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003541 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003542 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3544 "of VK_SAMPLE_COUNT_2_BIT but "
3545 "must be VK_SAMPLE_COUNT_1_BIT");
3546 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3547 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003548 m_errorMonitor->VerifyFound();
3549 m_commandBuffer->EndCommandBuffer();
3550 }
3551
3552 // Create two images, the dest with sampleCount = 4, and attempt to blit
3553 // between them
3554 {
3555 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003556 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003557 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003558 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003559 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003560 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003561 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003562 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003563 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3565 "of VK_SAMPLE_COUNT_4_BIT but "
3566 "must be VK_SAMPLE_COUNT_1_BIT");
3567 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3568 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003569 m_errorMonitor->VerifyFound();
3570 m_commandBuffer->EndCommandBuffer();
3571 }
3572
3573 VkBufferImageCopy copy_region = {};
3574 copy_region.bufferRowLength = 128;
3575 copy_region.bufferImageHeight = 128;
3576 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3577 copy_region.imageSubresource.layerCount = 1;
3578 copy_region.imageExtent.height = 64;
3579 copy_region.imageExtent.width = 64;
3580 copy_region.imageExtent.depth = 1;
3581
3582 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3583 // buffer to image
3584 {
3585 vk_testing::Buffer src_buffer;
3586 VkMemoryPropertyFlags reqs = 0;
3587 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3588 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003589 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003590 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003591 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003592 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3594 "of VK_SAMPLE_COUNT_8_BIT but "
3595 "must be VK_SAMPLE_COUNT_1_BIT");
3596 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3597 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003598 m_errorMonitor->VerifyFound();
3599 m_commandBuffer->EndCommandBuffer();
3600 }
3601
3602 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3603 // image to buffer
3604 {
3605 vk_testing::Buffer dst_buffer;
3606 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3607 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003608 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003609 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003610 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003611 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3613 "of VK_SAMPLE_COUNT_2_BIT but "
3614 "must be VK_SAMPLE_COUNT_1_BIT");
3615 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003616 dst_buffer.handle(), 1, &copy_region);
3617 m_errorMonitor->VerifyFound();
3618 m_commandBuffer->EndCommandBuffer();
3619 }
3620}
3621
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003622TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3623 VkResult err;
3624 bool pass;
3625
3626 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3627 ASSERT_NO_FATAL_FAILURE(InitState());
3628
3629 // If w/d/h granularity is 1, test is not meaningful
3630 // TODO: When virtual device limits are available, create a set of limits for this test that
3631 // will always have a granularity of > 1 for w, h, and d
3632 auto index = m_device->graphics_queue_node_index_;
3633 auto queue_family_properties = m_device->phy().queue_properties();
3634
3635 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3636 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3637 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3638 return;
3639 }
3640
3641 // Create two images of different types and try to copy between them
3642 VkImage srcImage;
3643 VkImage dstImage;
3644 VkDeviceMemory srcMem;
3645 VkDeviceMemory destMem;
3646 VkMemoryRequirements memReqs;
3647
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003648 VkImageCreateInfo image_create_info = {};
3649 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3650 image_create_info.pNext = NULL;
3651 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3652 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3653 image_create_info.extent.width = 32;
3654 image_create_info.extent.height = 32;
3655 image_create_info.extent.depth = 1;
3656 image_create_info.mipLevels = 1;
3657 image_create_info.arrayLayers = 4;
3658 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3659 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3660 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3661 image_create_info.flags = 0;
3662
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003663 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003664 ASSERT_VK_SUCCESS(err);
3665
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003666 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003667 ASSERT_VK_SUCCESS(err);
3668
3669 // Allocate memory
3670 VkMemoryAllocateInfo memAlloc = {};
3671 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3672 memAlloc.pNext = NULL;
3673 memAlloc.allocationSize = 0;
3674 memAlloc.memoryTypeIndex = 0;
3675
3676 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3677 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003678 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003679 ASSERT_TRUE(pass);
3680 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3681 ASSERT_VK_SUCCESS(err);
3682
3683 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3684 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003685 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003686 ASSERT_VK_SUCCESS(err);
3687 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3688 ASSERT_VK_SUCCESS(err);
3689
3690 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3691 ASSERT_VK_SUCCESS(err);
3692 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3693 ASSERT_VK_SUCCESS(err);
3694
3695 BeginCommandBuffer();
3696 VkImageCopy copyRegion;
3697 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3698 copyRegion.srcSubresource.mipLevel = 0;
3699 copyRegion.srcSubresource.baseArrayLayer = 0;
3700 copyRegion.srcSubresource.layerCount = 1;
3701 copyRegion.srcOffset.x = 0;
3702 copyRegion.srcOffset.y = 0;
3703 copyRegion.srcOffset.z = 0;
3704 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3705 copyRegion.dstSubresource.mipLevel = 0;
3706 copyRegion.dstSubresource.baseArrayLayer = 0;
3707 copyRegion.dstSubresource.layerCount = 1;
3708 copyRegion.dstOffset.x = 0;
3709 copyRegion.dstOffset.y = 0;
3710 copyRegion.dstOffset.z = 0;
3711 copyRegion.extent.width = 1;
3712 copyRegion.extent.height = 1;
3713 copyRegion.extent.depth = 1;
3714
3715 // Introduce failure by setting srcOffset to a bad granularity value
3716 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3718 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003719 m_errorMonitor->VerifyFound();
3720
3721 // Introduce failure by setting extent to a bad granularity value
3722 copyRegion.srcOffset.y = 0;
3723 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3725 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003726 m_errorMonitor->VerifyFound();
3727
3728 // Now do some buffer/image copies
3729 vk_testing::Buffer buffer;
3730 VkMemoryPropertyFlags reqs = 0;
3731 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3732 VkBufferImageCopy region = {};
3733 region.bufferOffset = 0;
3734 region.bufferRowLength = 3;
3735 region.bufferImageHeight = 128;
3736 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3737 region.imageSubresource.layerCount = 1;
3738 region.imageExtent.height = 16;
3739 region.imageExtent.width = 16;
3740 region.imageExtent.depth = 1;
3741 region.imageOffset.x = 0;
3742 region.imageOffset.y = 0;
3743 region.imageOffset.z = 0;
3744
3745 // Introduce failure by setting bufferRowLength to a bad granularity value
3746 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3748 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3749 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003750 m_errorMonitor->VerifyFound();
3751 region.bufferRowLength = 128;
3752
3753 // Introduce failure by setting bufferOffset to a bad granularity value
3754 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3756 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3757 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003758 m_errorMonitor->VerifyFound();
3759 region.bufferOffset = 0;
3760
3761 // Introduce failure by setting bufferImageHeight to a bad granularity value
3762 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3764 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3765 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003766 m_errorMonitor->VerifyFound();
3767 region.bufferImageHeight = 128;
3768
3769 // Introduce failure by setting imageExtent to a bad granularity value
3770 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3772 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3773 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003774 m_errorMonitor->VerifyFound();
3775 region.imageExtent.width = 16;
3776
3777 // Introduce failure by setting imageOffset to a bad granularity value
3778 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3780 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3781 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003782 m_errorMonitor->VerifyFound();
3783
3784 EndCommandBuffer();
3785
3786 vkDestroyImage(m_device->device(), srcImage, NULL);
3787 vkDestroyImage(m_device->device(), dstImage, NULL);
3788 vkFreeMemory(m_device->device(), srcMem, NULL);
3789 vkFreeMemory(m_device->device(), destMem, NULL);
3790}
3791
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003792TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003793 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
3794 "attempt to submit them on a queue created in a different "
3795 "queue family.");
3796
Cody Northropc31a84f2016-08-22 10:41:47 -06003797 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003798 // This test is meaningless unless we have multiple queue families
3799 auto queue_family_properties = m_device->phy().queue_properties();
3800 if (queue_family_properties.size() < 2) {
3801 return;
3802 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003804 // Get safe index of another queue family
3805 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3806 ASSERT_NO_FATAL_FAILURE(InitState());
3807 // Create a second queue using a different queue family
3808 VkQueue other_queue;
3809 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3810
3811 // Record an empty cmd buffer
3812 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3813 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3814 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3815 vkEndCommandBuffer(m_commandBuffer->handle());
3816
3817 // And submit on the wrong queue
3818 VkSubmitInfo submit_info = {};
3819 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3820 submit_info.commandBufferCount = 1;
3821 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003822 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003823
3824 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003825}
3826
Chris Forbes48a53902016-06-30 11:46:27 +12003827TEST_F(VkLayerTest, RenderPassInitialLayoutUndefined) {
3828 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
3829 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
3830 "the command buffer has prior knowledge of that "
3831 "attachment's layout.");
3832
3833 m_errorMonitor->ExpectSuccess();
3834
3835 ASSERT_NO_FATAL_FAILURE(InitState());
3836
3837 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003838 VkAttachmentDescription attachment = {0,
3839 VK_FORMAT_R8G8B8A8_UNORM,
3840 VK_SAMPLE_COUNT_1_BIT,
3841 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3842 VK_ATTACHMENT_STORE_OP_STORE,
3843 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3844 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3845 VK_IMAGE_LAYOUT_UNDEFINED,
3846 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003847
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003848 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003849
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003850 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003851
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003852 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003853
3854 VkRenderPass rp;
3855 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3856 ASSERT_VK_SUCCESS(err);
3857
3858 // A compatible framebuffer.
3859 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003860 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 +12003861 ASSERT_TRUE(image.initialized());
3862
3863 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003864 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3865 nullptr,
3866 0,
3867 image.handle(),
3868 VK_IMAGE_VIEW_TYPE_2D,
3869 VK_FORMAT_R8G8B8A8_UNORM,
3870 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3871 VK_COMPONENT_SWIZZLE_IDENTITY},
3872 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes48a53902016-06-30 11:46:27 +12003873 };
3874 VkImageView view;
3875 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3876 ASSERT_VK_SUCCESS(err);
3877
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003878 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes48a53902016-06-30 11:46:27 +12003879 VkFramebuffer fb;
3880 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3881 ASSERT_VK_SUCCESS(err);
3882
3883 // Record a single command buffer which uses this renderpass twice. The
3884 // bug is triggered at the beginning of the second renderpass, when the
3885 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003886 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 +12003887 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003888 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003889 vkCmdEndRenderPass(m_commandBuffer->handle());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003890 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003891
3892 m_errorMonitor->VerifyNotFound();
3893
3894 vkCmdEndRenderPass(m_commandBuffer->handle());
3895 EndCommandBuffer();
3896
3897 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3898 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3899 vkDestroyImageView(m_device->device(), view, nullptr);
3900}
3901
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003902TEST_F(VkLayerTest, FramebufferBindingDestroyCommandPool) {
3903 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
3904 "command buffer, bind them together, then destroy "
3905 "command pool and framebuffer and verify there are no "
3906 "errors.");
3907
3908 m_errorMonitor->ExpectSuccess();
3909
3910 ASSERT_NO_FATAL_FAILURE(InitState());
3911
3912 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003913 VkAttachmentDescription attachment = {0,
3914 VK_FORMAT_R8G8B8A8_UNORM,
3915 VK_SAMPLE_COUNT_1_BIT,
3916 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3917 VK_ATTACHMENT_STORE_OP_STORE,
3918 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3919 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3920 VK_IMAGE_LAYOUT_UNDEFINED,
3921 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003922
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003923 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003924
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003925 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003926
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003927 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003928
3929 VkRenderPass rp;
3930 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3931 ASSERT_VK_SUCCESS(err);
3932
3933 // A compatible framebuffer.
3934 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003935 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 -06003936 ASSERT_TRUE(image.initialized());
3937
3938 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003939 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3940 nullptr,
3941 0,
3942 image.handle(),
3943 VK_IMAGE_VIEW_TYPE_2D,
3944 VK_FORMAT_R8G8B8A8_UNORM,
3945 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3946 VK_COMPONENT_SWIZZLE_IDENTITY},
3947 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003948 };
3949 VkImageView view;
3950 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3951 ASSERT_VK_SUCCESS(err);
3952
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003953 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003954 VkFramebuffer fb;
3955 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3956 ASSERT_VK_SUCCESS(err);
3957
3958 // Explicitly create a command buffer to bind the FB to so that we can then
3959 // destroy the command pool in order to implicitly free command buffer
3960 VkCommandPool command_pool;
3961 VkCommandPoolCreateInfo pool_create_info{};
3962 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3963 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3964 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003965 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003966
3967 VkCommandBuffer command_buffer;
3968 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003969 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003970 command_buffer_allocate_info.commandPool = command_pool;
3971 command_buffer_allocate_info.commandBufferCount = 1;
3972 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003973 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003974
3975 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003976 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 -06003977 VkCommandBufferBeginInfo begin_info{};
3978 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3979 vkBeginCommandBuffer(command_buffer, &begin_info);
3980
3981 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3982 vkCmdEndRenderPass(command_buffer);
3983 vkEndCommandBuffer(command_buffer);
Mark Lobodzinski7d10a822016-08-03 14:08:40 -06003984 vkDestroyImageView(m_device->device(), view, nullptr);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003985 // Destroy command pool to implicitly free command buffer
3986 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3987 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3988 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3989 m_errorMonitor->VerifyNotFound();
3990}
3991
Chris Forbes51bf7c92016-06-30 15:22:08 +12003992TEST_F(VkLayerTest, RenderPassSubpassZeroTransitionsApplied) {
3993 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
3994 "transitions for the first subpass");
3995
3996 m_errorMonitor->ExpectSuccess();
3997
3998 ASSERT_NO_FATAL_FAILURE(InitState());
3999
4000 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004001 VkAttachmentDescription attachment = {0,
4002 VK_FORMAT_R8G8B8A8_UNORM,
4003 VK_SAMPLE_COUNT_1_BIT,
4004 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4005 VK_ATTACHMENT_STORE_OP_STORE,
4006 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4007 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4008 VK_IMAGE_LAYOUT_UNDEFINED,
4009 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004010
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004011 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004012
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004013 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004014
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004015 VkSubpassDependency dep = {0,
4016 0,
4017 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4018 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4019 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4020 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4021 VK_DEPENDENCY_BY_REGION_BIT};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004022
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004023 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004024
4025 VkResult err;
4026 VkRenderPass rp;
4027 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4028 ASSERT_VK_SUCCESS(err);
4029
4030 // A compatible framebuffer.
4031 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004032 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 +12004033 ASSERT_TRUE(image.initialized());
4034
4035 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004036 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4037 nullptr,
4038 0,
4039 image.handle(),
4040 VK_IMAGE_VIEW_TYPE_2D,
4041 VK_FORMAT_R8G8B8A8_UNORM,
4042 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
4043 VK_COMPONENT_SWIZZLE_IDENTITY},
4044 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes51bf7c92016-06-30 15:22:08 +12004045 };
4046 VkImageView view;
4047 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4048 ASSERT_VK_SUCCESS(err);
4049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004050 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004051 VkFramebuffer fb;
4052 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4053 ASSERT_VK_SUCCESS(err);
4054
4055 // Record a single command buffer which issues a pipeline barrier w/
4056 // image memory barrier for the attachment. This detects the previously
4057 // missing tracking of the subpass layout by throwing a validation error
4058 // if it doesn't occur.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004059 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 +12004060 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004061 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004062
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004063 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
4064 nullptr,
4065 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4066 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4067 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4068 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4069 VK_QUEUE_FAMILY_IGNORED,
4070 VK_QUEUE_FAMILY_IGNORED,
4071 image.handle(),
4072 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
4073 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4074 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
4075 &imb);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004076
4077 vkCmdEndRenderPass(m_commandBuffer->handle());
4078 m_errorMonitor->VerifyNotFound();
4079 EndCommandBuffer();
4080
4081 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4082 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4083 vkDestroyImageView(m_device->device(), view, nullptr);
4084}
4085
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004086TEST_F(VkLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
4087 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
4088 "is used as a depth/stencil framebuffer attachment, the "
4089 "aspectMask is ignored and both depth and stencil image "
4090 "subresources are used.");
4091
4092 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004093 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
4094 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004095 return;
4096 }
4097
4098 m_errorMonitor->ExpectSuccess();
4099
4100 ASSERT_NO_FATAL_FAILURE(InitState());
4101
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004102 VkAttachmentDescription attachment = {0,
4103 VK_FORMAT_D32_SFLOAT_S8_UINT,
4104 VK_SAMPLE_COUNT_1_BIT,
4105 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4106 VK_ATTACHMENT_STORE_OP_STORE,
4107 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4108 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4109 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
4110 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004111
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004112 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004113
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004114 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004115
4116 VkSubpassDependency dep = {0,
4117 0,
4118 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4119 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4120 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4121 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4122 VK_DEPENDENCY_BY_REGION_BIT};
4123
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004124 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004125
4126 VkResult err;
4127 VkRenderPass rp;
4128 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4129 ASSERT_VK_SUCCESS(err);
4130
4131 VkImageObj image(m_device);
4132 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
4133 0x26, // usage
4134 VK_IMAGE_TILING_OPTIMAL, 0);
4135 ASSERT_TRUE(image.initialized());
4136 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
4137
4138 VkImageViewCreateInfo ivci = {
4139 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4140 nullptr,
4141 0,
4142 image.handle(),
4143 VK_IMAGE_VIEW_TYPE_2D,
4144 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004145 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004146 {0x2, 0, 1, 0, 1},
4147 };
4148 VkImageView view;
4149 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4150 ASSERT_VK_SUCCESS(err);
4151
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004152 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004153 VkFramebuffer fb;
4154 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4155 ASSERT_VK_SUCCESS(err);
4156
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004157 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 -06004158 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004159 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004160
4161 VkImageMemoryBarrier imb = {};
4162 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
4163 imb.pNext = nullptr;
4164 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4165 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
4166 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4167 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4168 imb.srcQueueFamilyIndex = 0;
4169 imb.dstQueueFamilyIndex = 0;
4170 imb.image = image.handle();
4171 imb.subresourceRange.aspectMask = 0x6;
4172 imb.subresourceRange.baseMipLevel = 0;
4173 imb.subresourceRange.levelCount = 0x1;
4174 imb.subresourceRange.baseArrayLayer = 0;
4175 imb.subresourceRange.layerCount = 0x1;
4176
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004177 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4178 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004179 &imb);
4180
4181 vkCmdEndRenderPass(m_commandBuffer->handle());
4182 EndCommandBuffer();
4183 QueueCommandBuffer(false);
4184 m_errorMonitor->VerifyNotFound();
4185
4186 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4187 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4188 vkDestroyImageView(m_device->device(), view, nullptr);
4189}
Tony Barbourd5f7b822016-08-02 15:39:33 -06004190
Tony Barbour4e919972016-08-09 13:27:40 -06004191TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
4192 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
4193 "with extent outside of framebuffer");
4194 ASSERT_NO_FATAL_FAILURE(InitState());
4195 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4196
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
4198 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06004199
4200 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
4201 m_renderPassBeginInfo.renderArea.extent.width = 257;
4202 m_renderPassBeginInfo.renderArea.extent.height = 257;
4203 BeginCommandBuffer();
4204 m_errorMonitor->VerifyFound();
4205}
4206
4207TEST_F(VkLayerTest, DisabledIndependentBlend) {
4208 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
4209 "blend and then specifying different blend states for two "
4210 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06004211 VkPhysicalDeviceFeatures features = {};
4212 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06004213 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06004214
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4216 "Invalid Pipeline CreateInfo: If independent blend feature not "
4217 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06004218
Cody Northropc31a84f2016-08-22 10:41:47 -06004219 VkDescriptorSetObj descriptorSet(m_device);
4220 descriptorSet.AppendDummy();
4221 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06004222
Cody Northropc31a84f2016-08-22 10:41:47 -06004223 VkPipelineObj pipeline(m_device);
4224 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004225 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06004226 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06004227
Cody Northropc31a84f2016-08-22 10:41:47 -06004228 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
4229 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4230 att_state1.blendEnable = VK_TRUE;
4231 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4232 att_state2.blendEnable = VK_FALSE;
4233 pipeline.AddColorAttachment(0, &att_state1);
4234 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004235 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06004236 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06004237}
4238
4239TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
4240 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
4241 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06004242 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06004243
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4245 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06004246
4247 // Create a renderPass with a single color attachment
4248 VkAttachmentReference attach = {};
4249 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4250 VkSubpassDescription subpass = {};
4251 VkRenderPassCreateInfo rpci = {};
4252 rpci.subpassCount = 1;
4253 rpci.pSubpasses = &subpass;
4254 rpci.attachmentCount = 1;
4255 VkAttachmentDescription attach_desc = {};
4256 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4257 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4258 rpci.pAttachments = &attach_desc;
4259 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4260 VkRenderPass rp;
4261 subpass.pDepthStencilAttachment = &attach;
4262 subpass.pColorAttachments = NULL;
4263 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4264 m_errorMonitor->VerifyFound();
4265}
4266
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004267TEST_F(VkLayerTest, RenderPassTransitionsAttachmentUnused) {
4268 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
4269 "errors, when an attachment reference is "
4270 "VK_ATTACHMENT_UNUSED");
4271
4272 m_errorMonitor->ExpectSuccess();
4273
4274 ASSERT_NO_FATAL_FAILURE(InitState());
4275
4276 // A renderpass with no attachments
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004277 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004278
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004279 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004280
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004281 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004282
4283 VkRenderPass rp;
4284 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4285 ASSERT_VK_SUCCESS(err);
4286
4287 // A compatible framebuffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004288 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004289 VkFramebuffer fb;
4290 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4291 ASSERT_VK_SUCCESS(err);
4292
4293 // Record a command buffer which just begins and ends the renderpass. The
4294 // bug manifests in BeginRenderPass.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004295 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 +12004296 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004297 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004298 vkCmdEndRenderPass(m_commandBuffer->handle());
4299 m_errorMonitor->VerifyNotFound();
4300 EndCommandBuffer();
4301
4302 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4303 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4304}
4305
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004306// This is a positive test. No errors are expected.
4307TEST_F(VkLayerTest, StencilLoadOp) {
4308 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
4309 "CLEAR. stencil[Load|Store]Op used to be ignored.");
4310 VkResult result = VK_SUCCESS;
4311 VkImageFormatProperties formatProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004312 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
4313 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
4314 &formatProps);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004315 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
4316 return;
4317 }
4318
4319 ASSERT_NO_FATAL_FAILURE(InitState());
4320 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
4321 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004322 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004323 VkAttachmentDescription att = {};
4324 VkAttachmentReference ref = {};
4325 att.format = depth_stencil_fmt;
4326 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
4327 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
4328 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
4329 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
4330 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4331 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4332
4333 VkClearValue clear;
4334 clear.depthStencil.depth = 1.0;
4335 clear.depthStencil.stencil = 0;
4336 ref.attachment = 0;
4337 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4338
4339 VkSubpassDescription subpass = {};
4340 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
4341 subpass.flags = 0;
4342 subpass.inputAttachmentCount = 0;
4343 subpass.pInputAttachments = NULL;
4344 subpass.colorAttachmentCount = 0;
4345 subpass.pColorAttachments = NULL;
4346 subpass.pResolveAttachments = NULL;
4347 subpass.pDepthStencilAttachment = &ref;
4348 subpass.preserveAttachmentCount = 0;
4349 subpass.pPreserveAttachments = NULL;
4350
4351 VkRenderPass rp;
4352 VkRenderPassCreateInfo rp_info = {};
4353 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4354 rp_info.attachmentCount = 1;
4355 rp_info.pAttachments = &att;
4356 rp_info.subpassCount = 1;
4357 rp_info.pSubpasses = &subpass;
4358 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
4359 ASSERT_VK_SUCCESS(result);
4360
4361 VkImageView *depthView = m_depthStencil->BindInfo();
4362 VkFramebufferCreateInfo fb_info = {};
4363 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4364 fb_info.pNext = NULL;
4365 fb_info.renderPass = rp;
4366 fb_info.attachmentCount = 1;
4367 fb_info.pAttachments = depthView;
4368 fb_info.width = 100;
4369 fb_info.height = 100;
4370 fb_info.layers = 1;
4371 VkFramebuffer fb;
4372 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4373 ASSERT_VK_SUCCESS(result);
4374
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004375 VkRenderPassBeginInfo rpbinfo = {};
4376 rpbinfo.clearValueCount = 1;
4377 rpbinfo.pClearValues = &clear;
4378 rpbinfo.pNext = NULL;
4379 rpbinfo.renderPass = rp;
4380 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
4381 rpbinfo.renderArea.extent.width = 100;
4382 rpbinfo.renderArea.extent.height = 100;
4383 rpbinfo.renderArea.offset.x = 0;
4384 rpbinfo.renderArea.offset.y = 0;
4385 rpbinfo.framebuffer = fb;
4386
4387 VkFence fence = {};
4388 VkFenceCreateInfo fence_ci = {};
4389 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4390 fence_ci.pNext = nullptr;
4391 fence_ci.flags = 0;
4392 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
4393 ASSERT_VK_SUCCESS(result);
4394
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004395 m_commandBuffer->BeginCommandBuffer();
4396 m_commandBuffer->BeginRenderPass(rpbinfo);
4397 m_commandBuffer->EndRenderPass();
4398 m_commandBuffer->EndCommandBuffer();
4399 m_commandBuffer->QueueCommandBuffer(fence);
4400
4401 VkImageObj destImage(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004402 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 -06004403 VK_IMAGE_TILING_OPTIMAL, 0);
4404 VkImageMemoryBarrier barrier = {};
4405 VkImageSubresourceRange range;
4406 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004407 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4408 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004409 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4410 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4411 barrier.image = m_depthStencil->handle();
4412 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
4413 range.baseMipLevel = 0;
4414 range.levelCount = 1;
4415 range.baseArrayLayer = 0;
4416 range.layerCount = 1;
4417 barrier.subresourceRange = range;
4418 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4419 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
4420 cmdbuf.BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004421 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4422 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004423 barrier.srcAccessMask = 0;
4424 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4425 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4426 barrier.image = destImage.handle();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004427 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4428 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4429 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004430 VkImageCopy cregion;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004431 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004432 cregion.srcSubresource.mipLevel = 0;
4433 cregion.srcSubresource.baseArrayLayer = 0;
4434 cregion.srcSubresource.layerCount = 1;
4435 cregion.srcOffset.x = 0;
4436 cregion.srcOffset.y = 0;
4437 cregion.srcOffset.z = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004438 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004439 cregion.dstSubresource.mipLevel = 0;
4440 cregion.dstSubresource.baseArrayLayer = 0;
4441 cregion.dstSubresource.layerCount = 1;
4442 cregion.dstOffset.x = 0;
4443 cregion.dstOffset.y = 0;
4444 cregion.dstOffset.z = 0;
4445 cregion.extent.width = 100;
4446 cregion.extent.height = 100;
4447 cregion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004448 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004449 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
4450 cmdbuf.EndCommandBuffer();
4451
4452 VkSubmitInfo submit_info;
4453 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4454 submit_info.pNext = NULL;
4455 submit_info.waitSemaphoreCount = 0;
4456 submit_info.pWaitSemaphores = NULL;
4457 submit_info.pWaitDstStageMask = NULL;
4458 submit_info.commandBufferCount = 1;
4459 submit_info.pCommandBuffers = &cmdbuf.handle();
4460 submit_info.signalSemaphoreCount = 0;
4461 submit_info.pSignalSemaphores = NULL;
4462
4463 m_errorMonitor->ExpectSuccess();
4464 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4465 m_errorMonitor->VerifyNotFound();
4466
Mark Lobodzinskid0440da2016-06-17 15:10:03 -06004467 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004468 vkDestroyFence(m_device->device(), fence, nullptr);
4469 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4470 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4471}
4472
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004473TEST_F(VkLayerTest, UnusedPreserveAttachment) {
4474 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
4475 "attachment reference of VK_ATTACHMENT_UNUSED");
4476
4477 ASSERT_NO_FATAL_FAILURE(InitState());
4478 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4479
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004481
4482 VkAttachmentReference color_attach = {};
4483 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4484 color_attach.attachment = 0;
4485 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
4486 VkSubpassDescription subpass = {};
4487 subpass.colorAttachmentCount = 1;
4488 subpass.pColorAttachments = &color_attach;
4489 subpass.preserveAttachmentCount = 1;
4490 subpass.pPreserveAttachments = &preserve_attachment;
4491
4492 VkRenderPassCreateInfo rpci = {};
4493 rpci.subpassCount = 1;
4494 rpci.pSubpasses = &subpass;
4495 rpci.attachmentCount = 1;
4496 VkAttachmentDescription attach_desc = {};
4497 attach_desc.format = VK_FORMAT_UNDEFINED;
4498 rpci.pAttachments = &attach_desc;
4499 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4500 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004501 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004502
4503 m_errorMonitor->VerifyFound();
4504
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004505 if (result == VK_SUCCESS) {
4506 vkDestroyRenderPass(m_device->device(), rp, NULL);
4507 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004508}
4509
Chris Forbesc5389742016-06-29 11:49:23 +12004510TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004511 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
4512 "when the source of a subpass multisample resolve "
4513 "does not have multiple samples.");
4514
Chris Forbesc5389742016-06-29 11:49:23 +12004515 ASSERT_NO_FATAL_FAILURE(InitState());
4516
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4518 "Subpass 0 requests multisample resolve from attachment 0 which has "
4519 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004520
4521 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004522 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4523 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4524 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4525 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4526 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4527 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004528 };
4529
4530 VkAttachmentReference color = {
4531 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4532 };
4533
4534 VkAttachmentReference resolve = {
4535 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4536 };
4537
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004538 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004539
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004540 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004541
4542 VkRenderPass rp;
4543 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4544
4545 m_errorMonitor->VerifyFound();
4546
4547 if (err == VK_SUCCESS)
4548 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4549}
4550
4551TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004552 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4553 "when a subpass multisample resolve operation is "
4554 "requested, and the destination of that resolve has "
4555 "multiple samples.");
4556
Chris Forbesc5389742016-06-29 11:49:23 +12004557 ASSERT_NO_FATAL_FAILURE(InitState());
4558
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4560 "Subpass 0 requests multisample resolve into attachment 1, which "
4561 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004562
4563 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004564 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4565 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4566 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4567 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4568 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4569 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004570 };
4571
4572 VkAttachmentReference color = {
4573 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4574 };
4575
4576 VkAttachmentReference resolve = {
4577 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4578 };
4579
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004580 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004581
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004582 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004583
4584 VkRenderPass rp;
4585 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4586
4587 m_errorMonitor->VerifyFound();
4588
4589 if (err == VK_SUCCESS)
4590 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4591}
4592
Chris Forbes3f128ef2016-06-29 14:58:53 +12004593TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004594 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4595 "when the color and depth attachments used by a subpass "
4596 "have inconsistent sample counts");
4597
Chris Forbes3f128ef2016-06-29 14:58:53 +12004598 ASSERT_NO_FATAL_FAILURE(InitState());
4599
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4601 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12004602
4603 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004604 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4605 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4606 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4607 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4608 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4609 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12004610 };
4611
4612 VkAttachmentReference color[] = {
4613 {
4614 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4615 },
4616 {
4617 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4618 },
4619 };
4620
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004621 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004622
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004623 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004624
4625 VkRenderPass rp;
4626 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4627
4628 m_errorMonitor->VerifyFound();
4629
4630 if (err == VK_SUCCESS)
4631 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4632}
4633
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004634TEST_F(VkLayerTest, FramebufferCreateErrors) {
4635 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
4636 " 1. Mismatch between fb & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004637 " 2. Use a color image as depthStencil attachment\n"
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004638 " 3. Mismatch fb & renderPass attachment formats\n"
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004639 " 4. Mismatch fb & renderPass attachment #samples\n"
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004640 " 5. FB attachment w/ non-1 mip-levels\n"
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004641 " 6. FB attachment where dimensions don't match\n"
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004642 " 7. FB attachment w/o identity swizzle\n"
4643 " 8. FB dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004644
4645 ASSERT_NO_FATAL_FAILURE(InitState());
4646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4647
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4649 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
4650 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004651
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004652 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004653 VkAttachmentReference attach = {};
4654 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4655 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004656 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004657 VkRenderPassCreateInfo rpci = {};
4658 rpci.subpassCount = 1;
4659 rpci.pSubpasses = &subpass;
4660 rpci.attachmentCount = 1;
4661 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004662 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004663 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004664 rpci.pAttachments = &attach_desc;
4665 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4666 VkRenderPass rp;
4667 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4668 ASSERT_VK_SUCCESS(err);
4669
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004670 VkImageView ivs[2];
4671 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
4672 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004673 VkFramebufferCreateInfo fb_info = {};
4674 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4675 fb_info.pNext = NULL;
4676 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004677 // Set mis-matching attachmentCount
4678 fb_info.attachmentCount = 2;
4679 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004680 fb_info.width = 100;
4681 fb_info.height = 100;
4682 fb_info.layers = 1;
4683
4684 VkFramebuffer fb;
4685 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4686
4687 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004688 if (err == VK_SUCCESS) {
4689 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4690 }
4691 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004692
4693 // Create a renderPass with a depth-stencil attachment created with
4694 // IMAGE_USAGE_COLOR_ATTACHMENT
4695 // Add our color attachment to pDepthStencilAttachment
4696 subpass.pDepthStencilAttachment = &attach;
4697 subpass.pColorAttachments = NULL;
4698 VkRenderPass rp_ds;
4699 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
4700 ASSERT_VK_SUCCESS(err);
4701 // Set correct attachment count, but attachment has COLOR usage bit set
4702 fb_info.attachmentCount = 1;
4703 fb_info.renderPass = rp_ds;
4704
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004706 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4707
4708 m_errorMonitor->VerifyFound();
4709 if (err == VK_SUCCESS) {
4710 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4711 }
4712 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004713
4714 // Create new renderpass with alternate attachment format from fb
4715 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
4716 subpass.pDepthStencilAttachment = NULL;
4717 subpass.pColorAttachments = &attach;
4718 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4719 ASSERT_VK_SUCCESS(err);
4720
4721 // Cause error due to mis-matched formats between rp & fb
4722 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
4723 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4725 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004726 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4727
4728 m_errorMonitor->VerifyFound();
4729 if (err == VK_SUCCESS) {
4730 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4731 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004732 vkDestroyRenderPass(m_device->device(), rp, NULL);
4733
4734 // Create new renderpass with alternate sample count from fb
4735 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4736 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
4737 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4738 ASSERT_VK_SUCCESS(err);
4739
4740 // Cause error due to mis-matched sample count between rp & fb
4741 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
4743 "that do not match the "
4744 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004745 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4746
4747 m_errorMonitor->VerifyFound();
4748 if (err == VK_SUCCESS) {
4749 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4750 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004751
4752 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004753
4754 // Create a custom imageView with non-1 mip levels
4755 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004756 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 -06004757 ASSERT_TRUE(image.initialized());
4758
4759 VkImageView view;
4760 VkImageViewCreateInfo ivci = {};
4761 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4762 ivci.image = image.handle();
4763 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4764 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4765 ivci.subresourceRange.layerCount = 1;
4766 ivci.subresourceRange.baseMipLevel = 0;
4767 // Set level count 2 (only 1 is allowed for FB attachment)
4768 ivci.subresourceRange.levelCount = 2;
4769 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4770 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4771 ASSERT_VK_SUCCESS(err);
4772 // Re-create renderpass to have matching sample count
4773 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4774 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4775 ASSERT_VK_SUCCESS(err);
4776
4777 fb_info.renderPass = rp;
4778 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004780 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4781
4782 m_errorMonitor->VerifyFound();
4783 if (err == VK_SUCCESS) {
4784 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4785 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004786 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004787 // Update view to original color buffer and grow FB dimensions too big
4788 fb_info.pAttachments = ivs;
4789 fb_info.height = 1024;
4790 fb_info.width = 1024;
4791 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
4793 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004794 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4795
4796 m_errorMonitor->VerifyFound();
4797 if (err == VK_SUCCESS) {
4798 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4799 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004800 // Create view attachment with non-identity swizzle
4801 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4802 ivci.image = image.handle();
4803 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4804 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4805 ivci.subresourceRange.layerCount = 1;
4806 ivci.subresourceRange.baseMipLevel = 0;
4807 ivci.subresourceRange.levelCount = 1;
4808 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4809 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4810 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4811 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4812 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4813 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4814 ASSERT_VK_SUCCESS(err);
4815
4816 fb_info.pAttachments = &view;
4817 fb_info.height = 100;
4818 fb_info.width = 100;
4819 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
4821 "framebuffer attachments must have "
4822 "been created with the identity "
4823 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004824 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4825
4826 m_errorMonitor->VerifyFound();
4827 if (err == VK_SUCCESS) {
4828 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4829 }
4830 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004831 // Request fb that exceeds max dimensions
4832 // reset attachment to color attachment
4833 fb_info.pAttachments = ivs;
4834 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
4835 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
4836 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
4838 "dimensions exceed physical device "
4839 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004840 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4841
4842 m_errorMonitor->VerifyFound();
4843 if (err == VK_SUCCESS) {
4844 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4845 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004846
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004847 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004848}
4849
Mark Lobodzinskic808d442016-04-14 10:57:23 -06004850// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05004851TEST_F(VkLayerTest, WaitEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004852 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05004853
Michael Lentine860b0fe2016-05-20 10:14:00 -05004854 m_errorMonitor->ExpectSuccess();
Cody Northropc31a84f2016-08-22 10:41:47 -06004855 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05004856
4857 VkEvent event;
4858 VkEventCreateInfo event_create_info{};
4859 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4860 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
4861
4862 VkCommandPool command_pool;
4863 VkCommandPoolCreateInfo pool_create_info{};
4864 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4865 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4866 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004867 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004868
4869 VkCommandBuffer command_buffer;
4870 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004871 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05004872 command_buffer_allocate_info.commandPool = command_pool;
4873 command_buffer_allocate_info.commandBufferCount = 1;
4874 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004875 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004876
4877 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004878 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004879
4880 {
4881 VkCommandBufferBeginInfo begin_info{};
4882 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4883 vkBeginCommandBuffer(command_buffer, &begin_info);
4884
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004885 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 -05004886 nullptr, 0, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004887 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004888 vkEndCommandBuffer(command_buffer);
4889 }
4890 {
4891 VkSubmitInfo submit_info{};
4892 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4893 submit_info.commandBufferCount = 1;
4894 submit_info.pCommandBuffers = &command_buffer;
4895 submit_info.signalSemaphoreCount = 0;
4896 submit_info.pSignalSemaphores = nullptr;
4897 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
4898 }
4899 { vkSetEvent(m_device->device(), event); }
4900
4901 vkQueueWaitIdle(queue);
4902
4903 vkDestroyEvent(m_device->device(), event, nullptr);
4904 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
4905 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4906
4907 m_errorMonitor->VerifyNotFound();
4908}
Michael Lentine5627e692016-05-20 17:45:02 -05004909// This is a positive test. No errors should be generated.
Michael Lentinef01fb382016-07-21 17:24:56 -05004910TEST_F(VkLayerTest, QueryAndCopySecondaryCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004911 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
Michael Lentinef01fb382016-07-21 17:24:56 -05004912
Cody Northropc31a84f2016-08-22 10:41:47 -06004913 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004914 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentinef01fb382016-07-21 17:24:56 -05004915 return;
4916
4917 m_errorMonitor->ExpectSuccess();
4918
4919 VkQueryPool query_pool;
4920 VkQueryPoolCreateInfo query_pool_create_info{};
4921 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4922 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
4923 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004924 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004925
4926 VkCommandPool command_pool;
4927 VkCommandPoolCreateInfo pool_create_info{};
4928 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4929 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4930 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004931 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004932
4933 VkCommandBuffer command_buffer;
4934 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004935 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentinef01fb382016-07-21 17:24:56 -05004936 command_buffer_allocate_info.commandPool = command_pool;
4937 command_buffer_allocate_info.commandBufferCount = 1;
4938 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004939 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004940
4941 VkCommandBuffer secondary_command_buffer;
4942 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004943 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004944
4945 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004946 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentinef01fb382016-07-21 17:24:56 -05004947
4948 uint32_t qfi = 0;
4949 VkBufferCreateInfo buff_create_info = {};
4950 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4951 buff_create_info.size = 1024;
4952 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
4953 buff_create_info.queueFamilyIndexCount = 1;
4954 buff_create_info.pQueueFamilyIndices = &qfi;
4955
4956 VkResult err;
4957 VkBuffer buffer;
4958 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
4959 ASSERT_VK_SUCCESS(err);
4960 VkMemoryAllocateInfo mem_alloc = {};
4961 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4962 mem_alloc.pNext = NULL;
4963 mem_alloc.allocationSize = 1024;
4964 mem_alloc.memoryTypeIndex = 0;
4965
4966 VkMemoryRequirements memReqs;
4967 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004968 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05004969 if (!pass) {
4970 vkDestroyBuffer(m_device->device(), buffer, NULL);
4971 return;
4972 }
4973
4974 VkDeviceMemory mem;
4975 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4976 ASSERT_VK_SUCCESS(err);
4977 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4978 ASSERT_VK_SUCCESS(err);
4979
4980 VkCommandBufferInheritanceInfo hinfo = {};
4981 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
4982 hinfo.renderPass = VK_NULL_HANDLE;
4983 hinfo.subpass = 0;
4984 hinfo.framebuffer = VK_NULL_HANDLE;
4985 hinfo.occlusionQueryEnable = VK_FALSE;
4986 hinfo.queryFlags = 0;
4987 hinfo.pipelineStatistics = 0;
4988
4989 {
4990 VkCommandBufferBeginInfo begin_info{};
4991 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4992 begin_info.pInheritanceInfo = &hinfo;
4993 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
4994
4995 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004996 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05004997
4998 vkEndCommandBuffer(secondary_command_buffer);
4999
5000 begin_info.pInheritanceInfo = nullptr;
5001 vkBeginCommandBuffer(command_buffer, &begin_info);
5002
5003 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005004 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05005005
5006 vkEndCommandBuffer(command_buffer);
5007 }
5008 {
5009 VkSubmitInfo submit_info{};
5010 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5011 submit_info.commandBufferCount = 1;
5012 submit_info.pCommandBuffers = &command_buffer;
5013 submit_info.signalSemaphoreCount = 0;
5014 submit_info.pSignalSemaphores = nullptr;
5015 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5016 }
5017
5018 vkQueueWaitIdle(queue);
5019
5020 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5021 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5022 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
5023 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5024 vkDestroyBuffer(m_device->device(), buffer, NULL);
5025 vkFreeMemory(m_device->device(), mem, NULL);
5026
5027 m_errorMonitor->VerifyNotFound();
5028}
5029
5030// This is a positive test. No errors should be generated.
Michael Lentine5627e692016-05-20 17:45:02 -05005031TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005032 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
Michael Lentine5627e692016-05-20 17:45:02 -05005033
Cody Northropc31a84f2016-08-22 10:41:47 -06005034 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005035 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentine5627e692016-05-20 17:45:02 -05005036 return;
5037
5038 m_errorMonitor->ExpectSuccess();
5039
5040 VkQueryPool query_pool;
5041 VkQueryPoolCreateInfo query_pool_create_info{};
5042 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5043 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
5044 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005045 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005046
5047 VkCommandPool command_pool;
5048 VkCommandPoolCreateInfo pool_create_info{};
5049 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5050 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5051 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005052 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005053
5054 VkCommandBuffer command_buffer[2];
5055 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005056 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine5627e692016-05-20 17:45:02 -05005057 command_buffer_allocate_info.commandPool = command_pool;
5058 command_buffer_allocate_info.commandBufferCount = 2;
5059 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005060 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Michael Lentine5627e692016-05-20 17:45:02 -05005061
5062 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005063 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentine5627e692016-05-20 17:45:02 -05005064
5065 uint32_t qfi = 0;
5066 VkBufferCreateInfo buff_create_info = {};
5067 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5068 buff_create_info.size = 1024;
5069 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
5070 buff_create_info.queueFamilyIndexCount = 1;
5071 buff_create_info.pQueueFamilyIndices = &qfi;
5072
5073 VkResult err;
5074 VkBuffer buffer;
5075 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
5076 ASSERT_VK_SUCCESS(err);
5077 VkMemoryAllocateInfo mem_alloc = {};
5078 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5079 mem_alloc.pNext = NULL;
5080 mem_alloc.allocationSize = 1024;
5081 mem_alloc.memoryTypeIndex = 0;
5082
5083 VkMemoryRequirements memReqs;
5084 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005085 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005086 if (!pass) {
5087 vkDestroyBuffer(m_device->device(), buffer, NULL);
5088 return;
5089 }
5090
5091 VkDeviceMemory mem;
5092 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5093 ASSERT_VK_SUCCESS(err);
5094 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5095 ASSERT_VK_SUCCESS(err);
5096
5097 {
5098 VkCommandBufferBeginInfo begin_info{};
5099 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5100 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5101
5102 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005103 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005104
5105 vkEndCommandBuffer(command_buffer[0]);
5106
5107 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5108
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005109 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005110
5111 vkEndCommandBuffer(command_buffer[1]);
5112 }
5113 {
5114 VkSubmitInfo submit_info{};
5115 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5116 submit_info.commandBufferCount = 2;
5117 submit_info.pCommandBuffers = command_buffer;
5118 submit_info.signalSemaphoreCount = 0;
5119 submit_info.pSignalSemaphores = nullptr;
5120 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5121 }
5122
5123 vkQueueWaitIdle(queue);
5124
5125 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5126 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
5127 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005128 vkDestroyBuffer(m_device->device(), buffer, NULL);
5129 vkFreeMemory(m_device->device(), mem, NULL);
Michael Lentine5627e692016-05-20 17:45:02 -05005130
5131 m_errorMonitor->VerifyNotFound();
5132}
Michael Lentine860b0fe2016-05-20 10:14:00 -05005133
5134TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005135 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005136
Michael Lentine860b0fe2016-05-20 10:14:00 -05005137 m_errorMonitor->ExpectSuccess();
5138
Cody Northropc31a84f2016-08-22 10:41:47 -06005139 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05005140 VkEvent event;
5141 VkEventCreateInfo event_create_info{};
5142 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5143 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
5144
5145 VkCommandPool command_pool;
5146 VkCommandPoolCreateInfo pool_create_info{};
5147 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5148 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5149 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005150 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005151
5152 VkCommandBuffer command_buffer;
5153 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005154 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05005155 command_buffer_allocate_info.commandPool = command_pool;
5156 command_buffer_allocate_info.commandBufferCount = 1;
5157 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005158 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005159
5160 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005161 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005162
5163 {
5164 VkCommandBufferBeginInfo begin_info{};
5165 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5166 vkBeginCommandBuffer(command_buffer, &begin_info);
5167
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005168 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
5169 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
5170 nullptr, 0, nullptr, 0, nullptr);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005171 vkEndCommandBuffer(command_buffer);
5172 }
5173 {
5174 VkSubmitInfo submit_info{};
5175 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5176 submit_info.commandBufferCount = 1;
5177 submit_info.pCommandBuffers = &command_buffer;
5178 submit_info.signalSemaphoreCount = 0;
5179 submit_info.pSignalSemaphores = nullptr;
5180 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5181 }
5182 {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
5184 "command buffer.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005185 vkSetEvent(m_device->device(), event);
5186 m_errorMonitor->VerifyFound();
5187 }
5188
5189 vkQueueWaitIdle(queue);
5190
5191 vkDestroyEvent(m_device->device(), event, nullptr);
5192 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5193 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5194}
5195
5196// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005197TEST_F(VkLayerTest, TwoFencesThreeFrames) {
5198 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
5199 "run through a Submit & WaitForFences cycle 3 times. This "
5200 "previously revealed a bug so running this positive test "
5201 "to prevent a regression.");
5202 m_errorMonitor->ExpectSuccess();
5203
5204 ASSERT_NO_FATAL_FAILURE(InitState());
5205 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005206 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005207
5208 static const uint32_t NUM_OBJECTS = 2;
5209 static const uint32_t NUM_FRAMES = 3;
5210 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
5211 VkFence fences[NUM_OBJECTS] = {};
5212
5213 VkCommandPool cmd_pool;
5214 VkCommandPoolCreateInfo cmd_pool_ci = {};
5215 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5216 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
5217 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005218 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005219 ASSERT_VK_SUCCESS(err);
5220
5221 VkCommandBufferAllocateInfo cmd_buf_info = {};
5222 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
5223 cmd_buf_info.commandPool = cmd_pool;
5224 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
5225 cmd_buf_info.commandBufferCount = 1;
5226
5227 VkFenceCreateInfo fence_ci = {};
5228 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5229 fence_ci.pNext = nullptr;
5230 fence_ci.flags = 0;
5231
5232 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005233 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005234 ASSERT_VK_SUCCESS(err);
5235 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
5236 ASSERT_VK_SUCCESS(err);
5237 }
5238
5239 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06005240 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
5241 // Create empty cmd buffer
5242 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
5243 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005244
Tobin Ehlisf9025162016-05-26 06:55:21 -06005245 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
5246 ASSERT_VK_SUCCESS(err);
5247 err = vkEndCommandBuffer(cmd_buffers[obj]);
5248 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005249
Tobin Ehlisf9025162016-05-26 06:55:21 -06005250 VkSubmitInfo submit_info = {};
5251 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5252 submit_info.commandBufferCount = 1;
5253 submit_info.pCommandBuffers = &cmd_buffers[obj];
5254 // Submit cmd buffer and wait for fence
5255 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
5256 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005257 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
Tobin Ehlisf9025162016-05-26 06:55:21 -06005258 ASSERT_VK_SUCCESS(err);
5259 err = vkResetFences(m_device->device(), 1, &fences[obj]);
5260 ASSERT_VK_SUCCESS(err);
5261 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005262 }
5263 m_errorMonitor->VerifyNotFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06005264 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
5265 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
5266 vkDestroyFence(m_device->device(), fences[i], nullptr);
5267 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005268}
5269// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005270TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
5271
5272 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005273 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005274
Cody Northropc31a84f2016-08-22 10:41:47 -06005275 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005276 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005277 return;
5278
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005279 m_errorMonitor->ExpectSuccess();
5280
5281 VkSemaphore semaphore;
5282 VkSemaphoreCreateInfo semaphore_create_info{};
5283 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005284 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005285
5286 VkCommandPool command_pool;
5287 VkCommandPoolCreateInfo pool_create_info{};
5288 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5289 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5290 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005291 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005292
5293 VkCommandBuffer command_buffer[2];
5294 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005295 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005296 command_buffer_allocate_info.commandPool = command_pool;
5297 command_buffer_allocate_info.commandBufferCount = 2;
5298 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005299 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005300
5301 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005302 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005303
5304 {
5305 VkCommandBufferBeginInfo begin_info{};
5306 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5307 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5308
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005309 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5310 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005311
5312 VkViewport viewport{};
5313 viewport.maxDepth = 1.0f;
5314 viewport.minDepth = 0.0f;
5315 viewport.width = 512;
5316 viewport.height = 512;
5317 viewport.x = 0;
5318 viewport.y = 0;
5319 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5320 vkEndCommandBuffer(command_buffer[0]);
5321 }
5322 {
5323 VkCommandBufferBeginInfo begin_info{};
5324 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5325 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5326
5327 VkViewport viewport{};
5328 viewport.maxDepth = 1.0f;
5329 viewport.minDepth = 0.0f;
5330 viewport.width = 512;
5331 viewport.height = 512;
5332 viewport.x = 0;
5333 viewport.y = 0;
5334 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5335 vkEndCommandBuffer(command_buffer[1]);
5336 }
5337 {
5338 VkSubmitInfo submit_info{};
5339 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5340 submit_info.commandBufferCount = 1;
5341 submit_info.pCommandBuffers = &command_buffer[0];
5342 submit_info.signalSemaphoreCount = 1;
5343 submit_info.pSignalSemaphores = &semaphore;
5344 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5345 }
5346 {
5347 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5348 VkSubmitInfo submit_info{};
5349 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5350 submit_info.commandBufferCount = 1;
5351 submit_info.pCommandBuffers = &command_buffer[1];
5352 submit_info.waitSemaphoreCount = 1;
5353 submit_info.pWaitSemaphores = &semaphore;
5354 submit_info.pWaitDstStageMask = flags;
5355 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5356 }
5357
5358 vkQueueWaitIdle(m_device->m_queue);
5359
5360 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005361 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005362 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5363
5364 m_errorMonitor->VerifyNotFound();
5365}
5366
5367// This is a positive test. No errors should be generated.
5368TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
5369
5370 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5371 "submitted on separate queues, the second having a fence"
5372 "followed by a QueueWaitIdle.");
5373
Cody Northropc31a84f2016-08-22 10:41:47 -06005374 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005375 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005376 return;
5377
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005378 m_errorMonitor->ExpectSuccess();
5379
5380 VkFence fence;
5381 VkFenceCreateInfo fence_create_info{};
5382 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5383 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5384
5385 VkSemaphore semaphore;
5386 VkSemaphoreCreateInfo semaphore_create_info{};
5387 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005388 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005389
5390 VkCommandPool command_pool;
5391 VkCommandPoolCreateInfo pool_create_info{};
5392 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5393 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5394 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005395 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005396
5397 VkCommandBuffer command_buffer[2];
5398 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005399 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005400 command_buffer_allocate_info.commandPool = command_pool;
5401 command_buffer_allocate_info.commandBufferCount = 2;
5402 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005403 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005404
5405 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005406 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005407
5408 {
5409 VkCommandBufferBeginInfo begin_info{};
5410 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5411 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5412
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005413 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5414 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005415
5416 VkViewport viewport{};
5417 viewport.maxDepth = 1.0f;
5418 viewport.minDepth = 0.0f;
5419 viewport.width = 512;
5420 viewport.height = 512;
5421 viewport.x = 0;
5422 viewport.y = 0;
5423 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5424 vkEndCommandBuffer(command_buffer[0]);
5425 }
5426 {
5427 VkCommandBufferBeginInfo begin_info{};
5428 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5429 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5430
5431 VkViewport viewport{};
5432 viewport.maxDepth = 1.0f;
5433 viewport.minDepth = 0.0f;
5434 viewport.width = 512;
5435 viewport.height = 512;
5436 viewport.x = 0;
5437 viewport.y = 0;
5438 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5439 vkEndCommandBuffer(command_buffer[1]);
5440 }
5441 {
5442 VkSubmitInfo submit_info{};
5443 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5444 submit_info.commandBufferCount = 1;
5445 submit_info.pCommandBuffers = &command_buffer[0];
5446 submit_info.signalSemaphoreCount = 1;
5447 submit_info.pSignalSemaphores = &semaphore;
5448 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5449 }
5450 {
5451 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5452 VkSubmitInfo submit_info{};
5453 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5454 submit_info.commandBufferCount = 1;
5455 submit_info.pCommandBuffers = &command_buffer[1];
5456 submit_info.waitSemaphoreCount = 1;
5457 submit_info.pWaitSemaphores = &semaphore;
5458 submit_info.pWaitDstStageMask = flags;
5459 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5460 }
5461
5462 vkQueueWaitIdle(m_device->m_queue);
5463
5464 vkDestroyFence(m_device->device(), fence, nullptr);
5465 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005466 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005467 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5468
5469 m_errorMonitor->VerifyNotFound();
5470}
5471
5472// This is a positive test. No errors should be generated.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005473TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005474
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005475 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5476 "submitted on separate queues, the second having a fence"
5477 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005478
Cody Northropc31a84f2016-08-22 10:41:47 -06005479 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005480 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005481 return;
5482
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005483 m_errorMonitor->ExpectSuccess();
5484
5485 VkFence fence;
5486 VkFenceCreateInfo fence_create_info{};
5487 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5488 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5489
5490 VkSemaphore semaphore;
5491 VkSemaphoreCreateInfo semaphore_create_info{};
5492 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005493 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005494
5495 VkCommandPool command_pool;
5496 VkCommandPoolCreateInfo pool_create_info{};
5497 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5498 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5499 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005500 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005501
5502 VkCommandBuffer command_buffer[2];
5503 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005504 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005505 command_buffer_allocate_info.commandPool = command_pool;
5506 command_buffer_allocate_info.commandBufferCount = 2;
5507 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005508 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005509
5510 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005511 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005512
5513 {
5514 VkCommandBufferBeginInfo begin_info{};
5515 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5516 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5517
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005518 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5519 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005520
5521 VkViewport viewport{};
5522 viewport.maxDepth = 1.0f;
5523 viewport.minDepth = 0.0f;
5524 viewport.width = 512;
5525 viewport.height = 512;
5526 viewport.x = 0;
5527 viewport.y = 0;
5528 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5529 vkEndCommandBuffer(command_buffer[0]);
5530 }
5531 {
5532 VkCommandBufferBeginInfo begin_info{};
5533 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5534 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5535
5536 VkViewport viewport{};
5537 viewport.maxDepth = 1.0f;
5538 viewport.minDepth = 0.0f;
5539 viewport.width = 512;
5540 viewport.height = 512;
5541 viewport.x = 0;
5542 viewport.y = 0;
5543 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5544 vkEndCommandBuffer(command_buffer[1]);
5545 }
5546 {
5547 VkSubmitInfo submit_info{};
5548 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5549 submit_info.commandBufferCount = 1;
5550 submit_info.pCommandBuffers = &command_buffer[0];
5551 submit_info.signalSemaphoreCount = 1;
5552 submit_info.pSignalSemaphores = &semaphore;
5553 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5554 }
5555 {
5556 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5557 VkSubmitInfo submit_info{};
5558 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5559 submit_info.commandBufferCount = 1;
5560 submit_info.pCommandBuffers = &command_buffer[1];
5561 submit_info.waitSemaphoreCount = 1;
5562 submit_info.pWaitSemaphores = &semaphore;
5563 submit_info.pWaitDstStageMask = flags;
5564 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5565 }
5566
5567 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5568 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5569
5570 vkDestroyFence(m_device->device(), fence, nullptr);
5571 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005572 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005573 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5574
5575 m_errorMonitor->VerifyNotFound();
5576}
5577
Chris Forbes0f8126b2016-06-20 17:48:22 +12005578TEST_F(VkLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Cody Northropc31a84f2016-08-22 10:41:47 -06005579
5580 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005581 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Chris Forbes0f8126b2016-06-20 17:48:22 +12005582 printf("Test requires two queues, skipping\n");
5583 return;
5584 }
5585
5586 VkResult err;
5587
5588 m_errorMonitor->ExpectSuccess();
5589
5590 VkQueue q0 = m_device->m_queue;
5591 VkQueue q1 = nullptr;
5592 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
5593 ASSERT_NE(q1, nullptr);
5594
5595 // An (empty) command buffer. We must have work in the first submission --
5596 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005597 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005598 VkCommandPool pool;
5599 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
5600 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005601 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
5602 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005603 VkCommandBuffer cb;
5604 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
5605 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005606 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005607 err = vkBeginCommandBuffer(cb, &cbbi);
5608 ASSERT_VK_SUCCESS(err);
5609 err = vkEndCommandBuffer(cb);
5610 ASSERT_VK_SUCCESS(err);
5611
5612 // A semaphore
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005613 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005614 VkSemaphore s;
5615 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
5616 ASSERT_VK_SUCCESS(err);
5617
5618 // First submission, to q0
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005619 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005620
5621 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
5622 ASSERT_VK_SUCCESS(err);
5623
5624 // Second submission, to q1, waiting on s
5625 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005626 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005627
5628 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
5629 ASSERT_VK_SUCCESS(err);
5630
5631 // Wait for q0 idle
5632 err = vkQueueWaitIdle(q0);
5633 ASSERT_VK_SUCCESS(err);
5634
5635 // Command buffer should have been completed (it was on q0); reset the pool.
5636 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
5637
5638 m_errorMonitor->VerifyNotFound();
5639
5640 // Force device completely idle and clean up resources
5641 vkDeviceWaitIdle(m_device->device());
5642 vkDestroyCommandPool(m_device->device(), pool, nullptr);
5643 vkDestroySemaphore(m_device->device(), s, nullptr);
5644}
Chris Forbes0f8126b2016-06-20 17:48:22 +12005645
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005646// This is a positive test. No errors should be generated.
5647TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
5648
5649 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5650 "submitted on separate queues, the second having a fence, "
5651 "followed by a WaitForFences call.");
5652
Cody Northropc31a84f2016-08-22 10:41:47 -06005653 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005654 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005655 return;
5656
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005657 m_errorMonitor->ExpectSuccess();
5658
Cody Northropc31a84f2016-08-22 10:41:47 -06005659 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005660 VkFence fence;
5661 VkFenceCreateInfo fence_create_info{};
5662 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5663 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5664
5665 VkSemaphore semaphore;
5666 VkSemaphoreCreateInfo semaphore_create_info{};
5667 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005668 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005669
5670 VkCommandPool command_pool;
5671 VkCommandPoolCreateInfo pool_create_info{};
5672 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5673 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5674 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005675 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005676
5677 VkCommandBuffer command_buffer[2];
5678 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005679 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005680 command_buffer_allocate_info.commandPool = command_pool;
5681 command_buffer_allocate_info.commandBufferCount = 2;
5682 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005683 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005684
5685 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005686 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005687
5688 {
5689 VkCommandBufferBeginInfo begin_info{};
5690 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5691 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5692
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005693 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5694 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005695
5696 VkViewport viewport{};
5697 viewport.maxDepth = 1.0f;
5698 viewport.minDepth = 0.0f;
5699 viewport.width = 512;
5700 viewport.height = 512;
5701 viewport.x = 0;
5702 viewport.y = 0;
5703 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5704 vkEndCommandBuffer(command_buffer[0]);
5705 }
5706 {
5707 VkCommandBufferBeginInfo begin_info{};
5708 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5709 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5710
5711 VkViewport viewport{};
5712 viewport.maxDepth = 1.0f;
5713 viewport.minDepth = 0.0f;
5714 viewport.width = 512;
5715 viewport.height = 512;
5716 viewport.x = 0;
5717 viewport.y = 0;
5718 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5719 vkEndCommandBuffer(command_buffer[1]);
5720 }
5721 {
5722 VkSubmitInfo submit_info{};
5723 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5724 submit_info.commandBufferCount = 1;
5725 submit_info.pCommandBuffers = &command_buffer[0];
5726 submit_info.signalSemaphoreCount = 1;
5727 submit_info.pSignalSemaphores = &semaphore;
5728 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5729 }
5730 {
5731 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5732 VkSubmitInfo submit_info{};
5733 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5734 submit_info.commandBufferCount = 1;
5735 submit_info.pCommandBuffers = &command_buffer[1];
5736 submit_info.waitSemaphoreCount = 1;
5737 submit_info.pWaitSemaphores = &semaphore;
5738 submit_info.pWaitDstStageMask = flags;
5739 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5740 }
5741
5742 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5743
5744 vkDestroyFence(m_device->device(), fence, nullptr);
5745 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005746 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005747 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5748
5749 m_errorMonitor->VerifyNotFound();
5750}
5751
5752// This is a positive test. No errors should be generated.
5753TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
5754
5755 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5756 "on the same queue, sharing a signal/wait semaphore, the "
5757 "second having a fence, "
5758 "followed by a WaitForFences call.");
5759
5760 m_errorMonitor->ExpectSuccess();
5761
Cody Northropc31a84f2016-08-22 10:41:47 -06005762 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005763 VkFence fence;
5764 VkFenceCreateInfo fence_create_info{};
5765 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5766 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5767
5768 VkSemaphore semaphore;
5769 VkSemaphoreCreateInfo semaphore_create_info{};
5770 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005771 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005772
5773 VkCommandPool command_pool;
5774 VkCommandPoolCreateInfo pool_create_info{};
5775 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5776 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5777 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005778 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005779
5780 VkCommandBuffer command_buffer[2];
5781 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005782 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005783 command_buffer_allocate_info.commandPool = command_pool;
5784 command_buffer_allocate_info.commandBufferCount = 2;
5785 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005786 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005787
5788 {
5789 VkCommandBufferBeginInfo begin_info{};
5790 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5791 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5792
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005793 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5794 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005795
5796 VkViewport viewport{};
5797 viewport.maxDepth = 1.0f;
5798 viewport.minDepth = 0.0f;
5799 viewport.width = 512;
5800 viewport.height = 512;
5801 viewport.x = 0;
5802 viewport.y = 0;
5803 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5804 vkEndCommandBuffer(command_buffer[0]);
5805 }
5806 {
5807 VkCommandBufferBeginInfo begin_info{};
5808 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5809 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5810
5811 VkViewport viewport{};
5812 viewport.maxDepth = 1.0f;
5813 viewport.minDepth = 0.0f;
5814 viewport.width = 512;
5815 viewport.height = 512;
5816 viewport.x = 0;
5817 viewport.y = 0;
5818 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5819 vkEndCommandBuffer(command_buffer[1]);
5820 }
5821 {
5822 VkSubmitInfo submit_info{};
5823 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5824 submit_info.commandBufferCount = 1;
5825 submit_info.pCommandBuffers = &command_buffer[0];
5826 submit_info.signalSemaphoreCount = 1;
5827 submit_info.pSignalSemaphores = &semaphore;
5828 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5829 }
5830 {
5831 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5832 VkSubmitInfo submit_info{};
5833 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5834 submit_info.commandBufferCount = 1;
5835 submit_info.pCommandBuffers = &command_buffer[1];
5836 submit_info.waitSemaphoreCount = 1;
5837 submit_info.pWaitSemaphores = &semaphore;
5838 submit_info.pWaitDstStageMask = flags;
5839 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5840 }
5841
5842 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5843
5844 vkDestroyFence(m_device->device(), fence, nullptr);
5845 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005846 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005847 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5848
5849 m_errorMonitor->VerifyNotFound();
5850}
5851
5852// This is a positive test. No errors should be generated.
5853TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
5854
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005855 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5856 "on the same queue, no fences, followed by a third QueueSubmit with NO "
5857 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005858
5859 m_errorMonitor->ExpectSuccess();
5860
Cody Northropc31a84f2016-08-22 10:41:47 -06005861 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005862 VkFence fence;
5863 VkFenceCreateInfo fence_create_info{};
5864 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5865 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5866
5867 VkCommandPool command_pool;
5868 VkCommandPoolCreateInfo pool_create_info{};
5869 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5870 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5871 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005872 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005873
5874 VkCommandBuffer command_buffer[2];
5875 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005876 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005877 command_buffer_allocate_info.commandPool = command_pool;
5878 command_buffer_allocate_info.commandBufferCount = 2;
5879 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005880 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005881
5882 {
5883 VkCommandBufferBeginInfo begin_info{};
5884 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5885 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5886
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005887 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5888 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005889
5890 VkViewport viewport{};
5891 viewport.maxDepth = 1.0f;
5892 viewport.minDepth = 0.0f;
5893 viewport.width = 512;
5894 viewport.height = 512;
5895 viewport.x = 0;
5896 viewport.y = 0;
5897 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5898 vkEndCommandBuffer(command_buffer[0]);
5899 }
5900 {
5901 VkCommandBufferBeginInfo begin_info{};
5902 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5903 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5904
5905 VkViewport viewport{};
5906 viewport.maxDepth = 1.0f;
5907 viewport.minDepth = 0.0f;
5908 viewport.width = 512;
5909 viewport.height = 512;
5910 viewport.x = 0;
5911 viewport.y = 0;
5912 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5913 vkEndCommandBuffer(command_buffer[1]);
5914 }
5915 {
5916 VkSubmitInfo submit_info{};
5917 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5918 submit_info.commandBufferCount = 1;
5919 submit_info.pCommandBuffers = &command_buffer[0];
5920 submit_info.signalSemaphoreCount = 0;
5921 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
5922 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5923 }
5924 {
5925 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5926 VkSubmitInfo submit_info{};
5927 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5928 submit_info.commandBufferCount = 1;
5929 submit_info.pCommandBuffers = &command_buffer[1];
5930 submit_info.waitSemaphoreCount = 0;
5931 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
5932 submit_info.pWaitDstStageMask = flags;
5933 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5934 }
5935
5936 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
5937
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005938 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
Mike Stroyancd1c3e52016-06-21 09:20:01 -06005939 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005940
5941 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005942 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005943 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5944
5945 m_errorMonitor->VerifyNotFound();
5946}
5947
5948// This is a positive test. No errors should be generated.
5949TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
5950
5951 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5952 "on the same queue, the second having a fence, followed "
5953 "by a WaitForFences call.");
5954
5955 m_errorMonitor->ExpectSuccess();
5956
Cody Northropc31a84f2016-08-22 10:41:47 -06005957 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005958 VkFence fence;
5959 VkFenceCreateInfo fence_create_info{};
5960 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5961 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5962
5963 VkCommandPool command_pool;
5964 VkCommandPoolCreateInfo pool_create_info{};
5965 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5966 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5967 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005968 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005969
5970 VkCommandBuffer command_buffer[2];
5971 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005972 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005973 command_buffer_allocate_info.commandPool = command_pool;
5974 command_buffer_allocate_info.commandBufferCount = 2;
5975 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005976 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005977
5978 {
5979 VkCommandBufferBeginInfo begin_info{};
5980 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5981 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5982
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005983 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5984 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005985
5986 VkViewport viewport{};
5987 viewport.maxDepth = 1.0f;
5988 viewport.minDepth = 0.0f;
5989 viewport.width = 512;
5990 viewport.height = 512;
5991 viewport.x = 0;
5992 viewport.y = 0;
5993 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5994 vkEndCommandBuffer(command_buffer[0]);
5995 }
5996 {
5997 VkCommandBufferBeginInfo begin_info{};
5998 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5999 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6000
6001 VkViewport viewport{};
6002 viewport.maxDepth = 1.0f;
6003 viewport.minDepth = 0.0f;
6004 viewport.width = 512;
6005 viewport.height = 512;
6006 viewport.x = 0;
6007 viewport.y = 0;
6008 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6009 vkEndCommandBuffer(command_buffer[1]);
6010 }
6011 {
6012 VkSubmitInfo submit_info{};
6013 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6014 submit_info.commandBufferCount = 1;
6015 submit_info.pCommandBuffers = &command_buffer[0];
6016 submit_info.signalSemaphoreCount = 0;
6017 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
6018 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6019 }
6020 {
6021 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6022 VkSubmitInfo submit_info{};
6023 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6024 submit_info.commandBufferCount = 1;
6025 submit_info.pCommandBuffers = &command_buffer[1];
6026 submit_info.waitSemaphoreCount = 0;
6027 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
6028 submit_info.pWaitDstStageMask = flags;
6029 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
6030 }
6031
6032 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6033
6034 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006035 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006036 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
6037
6038 m_errorMonitor->VerifyNotFound();
6039}
6040
6041// This is a positive test. No errors should be generated.
6042TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
6043
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006044 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
6045 "QueueSubmit call followed by a WaitForFences call.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006046 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006047
6048 m_errorMonitor->ExpectSuccess();
6049
6050 VkFence fence;
6051 VkFenceCreateInfo fence_create_info{};
6052 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
6053 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
6054
6055 VkSemaphore semaphore;
6056 VkSemaphoreCreateInfo semaphore_create_info{};
6057 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006058 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006059
6060 VkCommandPool command_pool;
6061 VkCommandPoolCreateInfo pool_create_info{};
6062 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
6063 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
6064 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006065 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006066
6067 VkCommandBuffer command_buffer[2];
6068 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006069 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006070 command_buffer_allocate_info.commandPool = command_pool;
6071 command_buffer_allocate_info.commandBufferCount = 2;
6072 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006073 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006074
6075 {
6076 VkCommandBufferBeginInfo begin_info{};
6077 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6078 vkBeginCommandBuffer(command_buffer[0], &begin_info);
6079
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006080 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
6081 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006082
6083 VkViewport viewport{};
6084 viewport.maxDepth = 1.0f;
6085 viewport.minDepth = 0.0f;
6086 viewport.width = 512;
6087 viewport.height = 512;
6088 viewport.x = 0;
6089 viewport.y = 0;
6090 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
6091 vkEndCommandBuffer(command_buffer[0]);
6092 }
6093 {
6094 VkCommandBufferBeginInfo begin_info{};
6095 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6096 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6097
6098 VkViewport viewport{};
6099 viewport.maxDepth = 1.0f;
6100 viewport.minDepth = 0.0f;
6101 viewport.width = 512;
6102 viewport.height = 512;
6103 viewport.x = 0;
6104 viewport.y = 0;
6105 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6106 vkEndCommandBuffer(command_buffer[1]);
6107 }
6108 {
6109 VkSubmitInfo submit_info[2];
6110 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6111
6112 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6113 submit_info[0].pNext = NULL;
6114 submit_info[0].commandBufferCount = 1;
6115 submit_info[0].pCommandBuffers = &command_buffer[0];
6116 submit_info[0].signalSemaphoreCount = 1;
6117 submit_info[0].pSignalSemaphores = &semaphore;
6118 submit_info[0].waitSemaphoreCount = 0;
6119 submit_info[0].pWaitSemaphores = NULL;
6120 submit_info[0].pWaitDstStageMask = 0;
6121
6122 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6123 submit_info[1].pNext = NULL;
6124 submit_info[1].commandBufferCount = 1;
6125 submit_info[1].pCommandBuffers = &command_buffer[1];
6126 submit_info[1].waitSemaphoreCount = 1;
6127 submit_info[1].pWaitSemaphores = &semaphore;
6128 submit_info[1].pWaitDstStageMask = flags;
6129 submit_info[1].signalSemaphoreCount = 0;
6130 submit_info[1].pSignalSemaphores = NULL;
6131 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
6132 }
6133
6134 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6135
6136 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006137 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006138 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006139 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006140
6141 m_errorMonitor->VerifyNotFound();
6142}
6143
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006144TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006145 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
6146 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006147
Cody Northropc31a84f2016-08-22 10:41:47 -06006148 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006149 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
6151 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006152 m_errorMonitor->VerifyFound();
6153}
6154
6155TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006156 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
6157 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006158
Cody Northropc31a84f2016-08-22 10:41:47 -06006159 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006160 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
6162 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006163 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006164}
6165
6166TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006167 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
6168 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006169
Cody Northropc31a84f2016-08-22 10:41:47 -06006170 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006171 // Dynamic viewport state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport state not set for this command buffer");
6173 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006174 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006175}
6176
6177TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006178 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
6179 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006180
Cody Northropc31a84f2016-08-22 10:41:47 -06006181 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006182 // Dynamic scissor state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor state not set for this command buffer");
6184 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006185 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006186}
6187
Cortd713fe82016-07-27 09:51:27 -07006188TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006189 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
6190 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006191
6192 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006193 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6195 "Dynamic blend constants state not set for this command buffer");
6196 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06006197 m_errorMonitor->VerifyFound();
6198}
6199
6200TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006201 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
6202 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006203
6204 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006205 if (!m_device->phy().features().depthBounds) {
6206 printf("Device does not support depthBounds test; skipped.\n");
6207 return;
6208 }
6209 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6211 "Dynamic depth bounds state not set for this command buffer");
6212 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006213 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006214}
6215
6216TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006217 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
6218 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006219
6220 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006221 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6223 "Dynamic stencil read mask state not set for this command buffer");
6224 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006225 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006226}
6227
6228TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006229 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
6230 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006231
6232 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006233 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6235 "Dynamic stencil write mask state not set for this command buffer");
6236 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006237 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006238}
6239
6240TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006241 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
6242 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006243
6244 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006245 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6247 "Dynamic stencil reference state not set for this command buffer");
6248 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006249 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06006250}
6251
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006252TEST_F(VkLayerTest, IndexBufferNotBound) {
6253 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006254
6255 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6257 "Index buffer object not bound to this command buffer when Indexed ");
6258 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006259 m_errorMonitor->VerifyFound();
6260}
6261
Karl Schultz6addd812016-02-02 17:17:23 -07006262TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6264 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
6265 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006266
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006267 ASSERT_NO_FATAL_FAILURE(InitState());
6268 ASSERT_NO_FATAL_FAILURE(InitViewport());
6269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6270
Karl Schultz6addd812016-02-02 17:17:23 -07006271 // We luck out b/c by default the framework creates CB w/ the
6272 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006273 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006274 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006275 EndCommandBuffer();
6276
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006277 // Bypass framework since it does the waits automatically
6278 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006279 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08006280 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6281 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006282 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006283 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07006284 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006285 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006286 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08006287 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006288 submit_info.pSignalSemaphores = NULL;
6289
Chris Forbes40028e22016-06-13 09:59:34 +12006290 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07006291 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006292
Karl Schultz6addd812016-02-02 17:17:23 -07006293 // Cause validation error by re-submitting cmd buffer that should only be
6294 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12006295 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006296
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006297 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006298}
6299
Karl Schultz6addd812016-02-02 17:17:23 -07006300TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006301 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07006302 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006303
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
6305 "type "
6306 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006307
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006308 ASSERT_NO_FATAL_FAILURE(InitState());
6309 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006310
Karl Schultz6addd812016-02-02 17:17:23 -07006311 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
6312 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006313 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006314 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
6315 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006316
6317 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006318 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6319 ds_pool_ci.pNext = NULL;
6320 ds_pool_ci.flags = 0;
6321 ds_pool_ci.maxSets = 1;
6322 ds_pool_ci.poolSizeCount = 1;
6323 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006324
6325 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006326 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006327 ASSERT_VK_SUCCESS(err);
6328
6329 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006330 dsl_binding.binding = 0;
6331 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6332 dsl_binding.descriptorCount = 1;
6333 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6334 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006335
6336 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006337 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6338 ds_layout_ci.pNext = NULL;
6339 ds_layout_ci.bindingCount = 1;
6340 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006341
6342 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006343 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006344 ASSERT_VK_SUCCESS(err);
6345
6346 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006347 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006348 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006349 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006350 alloc_info.descriptorPool = ds_pool;
6351 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006352 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006353
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006354 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006355
Chia-I Wuf7458c52015-10-26 21:10:41 +08006356 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6357 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006358}
6359
Karl Schultz6addd812016-02-02 17:17:23 -07006360TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
6361 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06006362
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6364 "It is invalid to call vkFreeDescriptorSets() with a pool created "
6365 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006366
Tobin Ehlise735c692015-10-08 13:13:50 -06006367 ASSERT_NO_FATAL_FAILURE(InitState());
6368 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06006369
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006370 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006371 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6372 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06006373
6374 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006375 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6376 ds_pool_ci.pNext = NULL;
6377 ds_pool_ci.maxSets = 1;
6378 ds_pool_ci.poolSizeCount = 1;
6379 ds_pool_ci.flags = 0;
6380 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
6381 // app can only call vkResetDescriptorPool on this pool.;
6382 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06006383
6384 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006385 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06006386 ASSERT_VK_SUCCESS(err);
6387
6388 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006389 dsl_binding.binding = 0;
6390 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6391 dsl_binding.descriptorCount = 1;
6392 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6393 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06006394
6395 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006396 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6397 ds_layout_ci.pNext = NULL;
6398 ds_layout_ci.bindingCount = 1;
6399 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06006400
6401 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006402 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06006403 ASSERT_VK_SUCCESS(err);
6404
6405 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006406 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006407 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006408 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006409 alloc_info.descriptorPool = ds_pool;
6410 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006411 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06006412 ASSERT_VK_SUCCESS(err);
6413
6414 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006415 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06006416
Chia-I Wuf7458c52015-10-26 21:10:41 +08006417 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6418 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06006419}
6420
Karl Schultz6addd812016-02-02 17:17:23 -07006421TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006422 // Attempt to clear Descriptor Pool with bad object.
6423 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06006424
6425 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006427 uint64_t fake_pool_handle = 0xbaad6001;
6428 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
6429 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06006430 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006431}
6432
Karl Schultz6addd812016-02-02 17:17:23 -07006433TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006434 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
6435 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006436 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06006437 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006438
6439 uint64_t fake_set_handle = 0xbaad6001;
6440 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006441 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06006443
6444 ASSERT_NO_FATAL_FAILURE(InitState());
6445
6446 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
6447 layout_bindings[0].binding = 0;
6448 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6449 layout_bindings[0].descriptorCount = 1;
6450 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
6451 layout_bindings[0].pImmutableSamplers = NULL;
6452
6453 VkDescriptorSetLayout descriptor_set_layout;
6454 VkDescriptorSetLayoutCreateInfo dslci = {};
6455 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6456 dslci.pNext = NULL;
6457 dslci.bindingCount = 1;
6458 dslci.pBindings = layout_bindings;
6459 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006460 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006461
6462 VkPipelineLayout pipeline_layout;
6463 VkPipelineLayoutCreateInfo plci = {};
6464 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6465 plci.pNext = NULL;
6466 plci.setLayoutCount = 1;
6467 plci.pSetLayouts = &descriptor_set_layout;
6468 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006469 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006470
6471 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006472 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
6473 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06006474 m_errorMonitor->VerifyFound();
6475 EndCommandBuffer();
6476 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
6477 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006478}
6479
Karl Schultz6addd812016-02-02 17:17:23 -07006480TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006481 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
6482 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006483 uint64_t fake_layout_handle = 0xbaad6001;
6484 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06006486 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06006487 VkPipelineLayout pipeline_layout;
6488 VkPipelineLayoutCreateInfo plci = {};
6489 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6490 plci.pNext = NULL;
6491 plci.setLayoutCount = 1;
6492 plci.pSetLayouts = &bad_layout;
6493 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
6494
6495 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006496}
6497
Mark Muellerd4914412016-06-13 17:52:06 -06006498TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
6499 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
6500 "1) A uniform buffer update must have a valid buffer index."
6501 "2) When using an array of descriptors in a single WriteDescriptor,"
6502 " the descriptor types and stageflags must all be the same."
6503 "3) Immutable Sampler state must match across descriptors");
6504
6505 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006506 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
6507 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
6508 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
6509 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
6510 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06006511
Mark Muellerd4914412016-06-13 17:52:06 -06006512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
6513
6514 ASSERT_NO_FATAL_FAILURE(InitState());
6515 VkDescriptorPoolSize ds_type_count[4] = {};
6516 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6517 ds_type_count[0].descriptorCount = 1;
6518 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6519 ds_type_count[1].descriptorCount = 1;
6520 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6521 ds_type_count[2].descriptorCount = 1;
6522 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6523 ds_type_count[3].descriptorCount = 1;
6524
6525 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6526 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6527 ds_pool_ci.maxSets = 1;
6528 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
6529 ds_pool_ci.pPoolSizes = ds_type_count;
6530
6531 VkDescriptorPool ds_pool;
6532 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6533 ASSERT_VK_SUCCESS(err);
6534
Mark Muellerb9896722016-06-16 09:54:29 -06006535 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006536 layout_binding[0].binding = 0;
6537 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6538 layout_binding[0].descriptorCount = 1;
6539 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6540 layout_binding[0].pImmutableSamplers = NULL;
6541
6542 layout_binding[1].binding = 1;
6543 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6544 layout_binding[1].descriptorCount = 1;
6545 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6546 layout_binding[1].pImmutableSamplers = NULL;
6547
6548 VkSamplerCreateInfo sampler_ci = {};
6549 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6550 sampler_ci.pNext = NULL;
6551 sampler_ci.magFilter = VK_FILTER_NEAREST;
6552 sampler_ci.minFilter = VK_FILTER_NEAREST;
6553 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6554 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6555 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6556 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6557 sampler_ci.mipLodBias = 1.0;
6558 sampler_ci.anisotropyEnable = VK_FALSE;
6559 sampler_ci.maxAnisotropy = 1;
6560 sampler_ci.compareEnable = VK_FALSE;
6561 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6562 sampler_ci.minLod = 1.0;
6563 sampler_ci.maxLod = 1.0;
6564 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6565 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6566 VkSampler sampler;
6567
6568 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6569 ASSERT_VK_SUCCESS(err);
6570
6571 layout_binding[2].binding = 2;
6572 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6573 layout_binding[2].descriptorCount = 1;
6574 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6575 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
6576
Mark Muellerd4914412016-06-13 17:52:06 -06006577 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6578 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6579 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
6580 ds_layout_ci.pBindings = layout_binding;
6581 VkDescriptorSetLayout ds_layout;
6582 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6583 ASSERT_VK_SUCCESS(err);
6584
6585 VkDescriptorSetAllocateInfo alloc_info = {};
6586 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6587 alloc_info.descriptorSetCount = 1;
6588 alloc_info.descriptorPool = ds_pool;
6589 alloc_info.pSetLayouts = &ds_layout;
6590 VkDescriptorSet descriptorSet;
6591 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6592 ASSERT_VK_SUCCESS(err);
6593
6594 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6595 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6596 pipeline_layout_ci.pNext = NULL;
6597 pipeline_layout_ci.setLayoutCount = 1;
6598 pipeline_layout_ci.pSetLayouts = &ds_layout;
6599
6600 VkPipelineLayout pipeline_layout;
6601 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6602 ASSERT_VK_SUCCESS(err);
6603
Mark Mueller5c838ce2016-06-16 09:54:29 -06006604 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006605 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6606 descriptor_write.dstSet = descriptorSet;
6607 descriptor_write.dstBinding = 0;
6608 descriptor_write.descriptorCount = 1;
6609 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6610
Mark Mueller5c838ce2016-06-16 09:54:29 -06006611 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06006612 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6613 m_errorMonitor->VerifyFound();
6614
6615 // Create a buffer to update the descriptor with
6616 uint32_t qfi = 0;
6617 VkBufferCreateInfo buffCI = {};
6618 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6619 buffCI.size = 1024;
6620 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6621 buffCI.queueFamilyIndexCount = 1;
6622 buffCI.pQueueFamilyIndices = &qfi;
6623
6624 VkBuffer dyub;
6625 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6626 ASSERT_VK_SUCCESS(err);
6627 VkDescriptorBufferInfo buffInfo = {};
6628 buffInfo.buffer = dyub;
6629 buffInfo.offset = 0;
6630 buffInfo.range = 1024;
6631
6632 descriptor_write.pBufferInfo = &buffInfo;
6633 descriptor_write.descriptorCount = 2;
6634
Mark Mueller5c838ce2016-06-16 09:54:29 -06006635 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06006636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
6637 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6638 m_errorMonitor->VerifyFound();
6639
Mark Mueller5c838ce2016-06-16 09:54:29 -06006640 // 3) The second descriptor has a null_ptr pImmutableSamplers and
6641 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06006642 descriptor_write.dstBinding = 1;
6643 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06006644
Mark Mueller5c838ce2016-06-16 09:54:29 -06006645 // Make pImageInfo index non-null to avoid complaints of it missing
6646 VkDescriptorImageInfo imageInfo = {};
6647 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6648 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06006649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
6650 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6651 m_errorMonitor->VerifyFound();
6652
Mark Muellerd4914412016-06-13 17:52:06 -06006653 vkDestroyBuffer(m_device->device(), dyub, NULL);
6654 vkDestroySampler(m_device->device(), sampler, NULL);
6655 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6656 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6657 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6658}
6659
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006660TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
6661 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6662 "due to a buffer dependency being destroyed.");
6663 ASSERT_NO_FATAL_FAILURE(InitState());
6664
6665 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006666 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 -06006667 VK_IMAGE_TILING_OPTIMAL, 0);
6668 ASSERT_TRUE(image.initialized());
6669
6670 VkBuffer buffer;
6671 VkDeviceMemory mem;
6672 VkMemoryRequirements mem_reqs;
6673
6674 VkBufferCreateInfo buf_info = {};
6675 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6676 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6677 buf_info.size = 256;
6678 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6679 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
6680 ASSERT_VK_SUCCESS(err);
6681
6682 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
6683
6684 VkMemoryAllocateInfo alloc_info = {};
6685 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6686 alloc_info.allocationSize = 256;
6687 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006688 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 -06006689 if (!pass) {
6690 vkDestroyBuffer(m_device->device(), buffer, NULL);
6691 return;
6692 }
6693 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
6694 ASSERT_VK_SUCCESS(err);
6695
6696 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
6697 ASSERT_VK_SUCCESS(err);
6698
6699 VkBufferImageCopy region = {};
6700 region.bufferRowLength = 128;
6701 region.bufferImageHeight = 128;
6702 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6703
6704 region.imageSubresource.layerCount = 1;
6705 region.imageExtent.height = 4;
6706 region.imageExtent.width = 4;
6707 region.imageExtent.depth = 1;
6708 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006709 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
6710 &region);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006711 m_commandBuffer->EndCommandBuffer();
6712
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006714 // Destroy buffer dependency prior to submit to cause ERROR
6715 vkDestroyBuffer(m_device->device(), buffer, NULL);
6716
6717 VkSubmitInfo submit_info = {};
6718 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6719 submit_info.commandBufferCount = 1;
6720 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6721 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6722
6723 m_errorMonitor->VerifyFound();
6724 vkFreeMemory(m_device->handle(), mem, NULL);
6725}
6726
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006727TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
6728 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6729 "due to an image dependency being destroyed.");
6730 ASSERT_NO_FATAL_FAILURE(InitState());
6731
6732 VkImage image;
6733 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6734 VkImageCreateInfo image_create_info = {};
6735 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6736 image_create_info.pNext = NULL;
6737 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6738 image_create_info.format = tex_format;
6739 image_create_info.extent.width = 32;
6740 image_create_info.extent.height = 32;
6741 image_create_info.extent.depth = 1;
6742 image_create_info.mipLevels = 1;
6743 image_create_info.arrayLayers = 1;
6744 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6745 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006746 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006747 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006748 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006749 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006750 // Have to bind memory to image before recording cmd in cmd buffer using it
6751 VkMemoryRequirements mem_reqs;
6752 VkDeviceMemory image_mem;
6753 bool pass;
6754 VkMemoryAllocateInfo mem_alloc = {};
6755 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6756 mem_alloc.pNext = NULL;
6757 mem_alloc.memoryTypeIndex = 0;
6758 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6759 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006760 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006761 ASSERT_TRUE(pass);
6762 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6763 ASSERT_VK_SUCCESS(err);
6764 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
6765 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006766
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006767 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06006768 VkClearColorValue ccv;
6769 ccv.float32[0] = 1.0f;
6770 ccv.float32[1] = 1.0f;
6771 ccv.float32[2] = 1.0f;
6772 ccv.float32[3] = 1.0f;
6773 VkImageSubresourceRange isr = {};
6774 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006775 isr.baseArrayLayer = 0;
6776 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06006777 isr.layerCount = 1;
6778 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006779 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006780 m_commandBuffer->EndCommandBuffer();
6781
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006783 // Destroy image dependency prior to submit to cause ERROR
6784 vkDestroyImage(m_device->device(), image, NULL);
6785
6786 VkSubmitInfo submit_info = {};
6787 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6788 submit_info.commandBufferCount = 1;
6789 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6790 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6791
6792 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006793 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006794}
6795
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006796TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
6797 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6798 "due to a framebuffer image dependency being destroyed.");
6799 VkFormatProperties format_properties;
6800 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006801 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
6802 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006803 return;
6804 }
6805
6806 ASSERT_NO_FATAL_FAILURE(InitState());
6807 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6808
6809 VkImageCreateInfo image_ci = {};
6810 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6811 image_ci.pNext = NULL;
6812 image_ci.imageType = VK_IMAGE_TYPE_2D;
6813 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
6814 image_ci.extent.width = 32;
6815 image_ci.extent.height = 32;
6816 image_ci.extent.depth = 1;
6817 image_ci.mipLevels = 1;
6818 image_ci.arrayLayers = 1;
6819 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
6820 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006821 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006822 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6823 image_ci.flags = 0;
6824 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006825 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006826
6827 VkMemoryRequirements memory_reqs;
6828 VkDeviceMemory image_memory;
6829 bool pass;
6830 VkMemoryAllocateInfo memory_info = {};
6831 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6832 memory_info.pNext = NULL;
6833 memory_info.allocationSize = 0;
6834 memory_info.memoryTypeIndex = 0;
6835 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6836 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006837 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006838 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006839 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006840 ASSERT_VK_SUCCESS(err);
6841 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6842 ASSERT_VK_SUCCESS(err);
6843
6844 VkImageViewCreateInfo ivci = {
6845 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
6846 nullptr,
6847 0,
6848 image,
6849 VK_IMAGE_VIEW_TYPE_2D,
6850 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006851 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006852 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
6853 };
6854 VkImageView view;
6855 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
6856 ASSERT_VK_SUCCESS(err);
6857
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006858 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006859 VkFramebuffer fb;
6860 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
6861 ASSERT_VK_SUCCESS(err);
6862
6863 // Just use default renderpass with our framebuffer
6864 m_renderPassBeginInfo.framebuffer = fb;
6865 // Create Null cmd buffer for submit
6866 BeginCommandBuffer();
6867 EndCommandBuffer();
6868 // Destroy image attached to framebuffer to invalidate cmd buffer
6869 vkDestroyImage(m_device->device(), image, NULL);
6870 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006872 QueueCommandBuffer(false);
6873 m_errorMonitor->VerifyFound();
6874
6875 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
6876 vkDestroyImageView(m_device->device(), view, nullptr);
6877 vkFreeMemory(m_device->device(), image_memory, nullptr);
6878}
6879
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006880TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006881 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006882 ASSERT_NO_FATAL_FAILURE(InitState());
6883
6884 VkImage image;
6885 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6886 VkImageCreateInfo image_create_info = {};
6887 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6888 image_create_info.pNext = NULL;
6889 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6890 image_create_info.format = tex_format;
6891 image_create_info.extent.width = 32;
6892 image_create_info.extent.height = 32;
6893 image_create_info.extent.depth = 1;
6894 image_create_info.mipLevels = 1;
6895 image_create_info.arrayLayers = 1;
6896 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6897 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006898 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006899 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006900 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006901 ASSERT_VK_SUCCESS(err);
6902 // Have to bind memory to image before recording cmd in cmd buffer using it
6903 VkMemoryRequirements mem_reqs;
6904 VkDeviceMemory image_mem;
6905 bool pass;
6906 VkMemoryAllocateInfo mem_alloc = {};
6907 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6908 mem_alloc.pNext = NULL;
6909 mem_alloc.memoryTypeIndex = 0;
6910 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6911 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006912 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006913 ASSERT_TRUE(pass);
6914 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6915 ASSERT_VK_SUCCESS(err);
6916
6917 // Introduce error, do not call vkBindImageMemory(m_device->device(), image,
6918 // image_mem, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindImageMemory");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006920
6921 m_commandBuffer->BeginCommandBuffer();
6922 VkClearColorValue ccv;
6923 ccv.float32[0] = 1.0f;
6924 ccv.float32[1] = 1.0f;
6925 ccv.float32[2] = 1.0f;
6926 ccv.float32[3] = 1.0f;
6927 VkImageSubresourceRange isr = {};
6928 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6929 isr.baseArrayLayer = 0;
6930 isr.baseMipLevel = 0;
6931 isr.layerCount = 1;
6932 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006933 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006934 m_commandBuffer->EndCommandBuffer();
6935
6936 m_errorMonitor->VerifyFound();
6937 vkDestroyImage(m_device->device(), image, NULL);
6938 vkFreeMemory(m_device->device(), image_mem, nullptr);
6939}
6940
6941TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006942 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006943 ASSERT_NO_FATAL_FAILURE(InitState());
6944
6945 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006946 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 -06006947 VK_IMAGE_TILING_OPTIMAL, 0);
6948 ASSERT_TRUE(image.initialized());
6949
6950 VkBuffer buffer;
6951 VkDeviceMemory mem;
6952 VkMemoryRequirements mem_reqs;
6953
6954 VkBufferCreateInfo buf_info = {};
6955 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6956 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6957 buf_info.size = 256;
6958 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6959 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
6960 ASSERT_VK_SUCCESS(err);
6961
6962 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
6963
6964 VkMemoryAllocateInfo alloc_info = {};
6965 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6966 alloc_info.allocationSize = 256;
6967 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006968 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 -06006969 if (!pass) {
6970 vkDestroyBuffer(m_device->device(), buffer, NULL);
6971 return;
6972 }
6973 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
6974 ASSERT_VK_SUCCESS(err);
6975
6976 // Introduce failure by not calling vkBindBufferMemory(m_device->device(),
6977 // buffer, mem, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindBufferMemory");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006979 VkBufferImageCopy region = {};
6980 region.bufferRowLength = 128;
6981 region.bufferImageHeight = 128;
6982 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6983
6984 region.imageSubresource.layerCount = 1;
6985 region.imageExtent.height = 4;
6986 region.imageExtent.width = 4;
6987 region.imageExtent.depth = 1;
6988 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006989 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
6990 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006991 m_commandBuffer->EndCommandBuffer();
6992
6993 m_errorMonitor->VerifyFound();
6994
6995 vkDestroyBuffer(m_device->device(), buffer, NULL);
6996 vkFreeMemory(m_device->handle(), mem, NULL);
6997}
6998
Tobin Ehlis85940f52016-07-07 16:57:21 -06006999TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
7000 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7001 "due to an event dependency being destroyed.");
7002 ASSERT_NO_FATAL_FAILURE(InitState());
7003
7004 VkEvent event;
7005 VkEventCreateInfo evci = {};
7006 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
7007 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
7008 ASSERT_VK_SUCCESS(result);
7009
7010 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007011 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06007012 m_commandBuffer->EndCommandBuffer();
7013
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06007015 // Destroy event dependency prior to submit to cause ERROR
7016 vkDestroyEvent(m_device->device(), event, NULL);
7017
7018 VkSubmitInfo submit_info = {};
7019 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7020 submit_info.commandBufferCount = 1;
7021 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7022 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7023
7024 m_errorMonitor->VerifyFound();
7025}
7026
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007027TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
7028 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7029 "due to a query pool dependency being destroyed.");
7030 ASSERT_NO_FATAL_FAILURE(InitState());
7031
7032 VkQueryPool query_pool;
7033 VkQueryPoolCreateInfo qpci{};
7034 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
7035 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
7036 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007037 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007038 ASSERT_VK_SUCCESS(result);
7039
7040 m_commandBuffer->BeginCommandBuffer();
7041 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
7042 m_commandBuffer->EndCommandBuffer();
7043
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007045 // Destroy query pool dependency prior to submit to cause ERROR
7046 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
7047
7048 VkSubmitInfo submit_info = {};
7049 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7050 submit_info.commandBufferCount = 1;
7051 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7052 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7053
7054 m_errorMonitor->VerifyFound();
7055}
7056
Tobin Ehlis24130d92016-07-08 15:50:53 -06007057TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
7058 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7059 "due to a pipeline dependency being destroyed.");
7060 ASSERT_NO_FATAL_FAILURE(InitState());
7061 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7062
7063 VkResult err;
7064
7065 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7066 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7067
7068 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007069 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007070 ASSERT_VK_SUCCESS(err);
7071
7072 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7073 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7074 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007075 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06007076 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007077 vp_state_ci.scissorCount = 1;
7078 VkRect2D scissors = {}; // Dummy scissors to point to
7079 vp_state_ci.pScissors = &scissors;
7080 // No dynamic state
7081 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7082 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7083
7084 VkPipelineShaderStageCreateInfo shaderStages[2];
7085 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7086
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007087 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7088 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7089 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06007090 shaderStages[0] = vs.GetStageCreateInfo();
7091 shaderStages[1] = fs.GetStageCreateInfo();
7092
7093 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7094 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7095
7096 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7097 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7098 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7099
7100 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7101 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7102
7103 VkPipelineColorBlendAttachmentState att = {};
7104 att.blendEnable = VK_FALSE;
7105 att.colorWriteMask = 0xf;
7106
7107 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7108 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7109 cb_ci.attachmentCount = 1;
7110 cb_ci.pAttachments = &att;
7111
7112 VkGraphicsPipelineCreateInfo gp_ci = {};
7113 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7114 gp_ci.stageCount = 2;
7115 gp_ci.pStages = shaderStages;
7116 gp_ci.pVertexInputState = &vi_ci;
7117 gp_ci.pInputAssemblyState = &ia_ci;
7118 gp_ci.pViewportState = &vp_state_ci;
7119 gp_ci.pRasterizationState = &rs_ci;
7120 gp_ci.pColorBlendState = &cb_ci;
7121 gp_ci.pDynamicState = &dyn_state_ci;
7122 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7123 gp_ci.layout = pipeline_layout;
7124 gp_ci.renderPass = renderPass();
7125
7126 VkPipelineCacheCreateInfo pc_ci = {};
7127 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7128
7129 VkPipeline pipeline;
7130 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007131 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007132 ASSERT_VK_SUCCESS(err);
7133
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007134 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007135 ASSERT_VK_SUCCESS(err);
7136
7137 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007138 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007139 m_commandBuffer->EndCommandBuffer();
7140 // Now destroy pipeline in order to cause error when submitting
7141 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
7142
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06007144
7145 VkSubmitInfo submit_info = {};
7146 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7147 submit_info.commandBufferCount = 1;
7148 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7149 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7150
7151 m_errorMonitor->VerifyFound();
7152 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7153 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7154}
7155
Tobin Ehlis31289162016-08-17 14:57:58 -06007156TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
7157 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7158 "due to a bound descriptor set with a buffer dependency "
7159 "being destroyed.");
7160 ASSERT_NO_FATAL_FAILURE(InitState());
7161 ASSERT_NO_FATAL_FAILURE(InitViewport());
7162 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7163
7164 VkDescriptorPoolSize ds_type_count = {};
7165 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7166 ds_type_count.descriptorCount = 1;
7167
7168 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7169 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7170 ds_pool_ci.pNext = NULL;
7171 ds_pool_ci.maxSets = 1;
7172 ds_pool_ci.poolSizeCount = 1;
7173 ds_pool_ci.pPoolSizes = &ds_type_count;
7174
7175 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007176 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06007177 ASSERT_VK_SUCCESS(err);
7178
7179 VkDescriptorSetLayoutBinding dsl_binding = {};
7180 dsl_binding.binding = 0;
7181 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7182 dsl_binding.descriptorCount = 1;
7183 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7184 dsl_binding.pImmutableSamplers = NULL;
7185
7186 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7187 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7188 ds_layout_ci.pNext = NULL;
7189 ds_layout_ci.bindingCount = 1;
7190 ds_layout_ci.pBindings = &dsl_binding;
7191 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007192 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007193 ASSERT_VK_SUCCESS(err);
7194
7195 VkDescriptorSet descriptorSet;
7196 VkDescriptorSetAllocateInfo alloc_info = {};
7197 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7198 alloc_info.descriptorSetCount = 1;
7199 alloc_info.descriptorPool = ds_pool;
7200 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007201 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06007202 ASSERT_VK_SUCCESS(err);
7203
7204 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7205 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7206 pipeline_layout_ci.pNext = NULL;
7207 pipeline_layout_ci.setLayoutCount = 1;
7208 pipeline_layout_ci.pSetLayouts = &ds_layout;
7209
7210 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007211 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007212 ASSERT_VK_SUCCESS(err);
7213
7214 // Create a buffer to update the descriptor with
7215 uint32_t qfi = 0;
7216 VkBufferCreateInfo buffCI = {};
7217 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7218 buffCI.size = 1024;
7219 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7220 buffCI.queueFamilyIndexCount = 1;
7221 buffCI.pQueueFamilyIndices = &qfi;
7222
7223 VkBuffer buffer;
7224 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
7225 ASSERT_VK_SUCCESS(err);
7226 // Allocate memory and bind to buffer so we can make it to the appropriate
7227 // error
7228 VkMemoryAllocateInfo mem_alloc = {};
7229 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7230 mem_alloc.pNext = NULL;
7231 mem_alloc.allocationSize = 1024;
7232 mem_alloc.memoryTypeIndex = 0;
7233
7234 VkMemoryRequirements memReqs;
7235 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007236 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06007237 if (!pass) {
7238 vkDestroyBuffer(m_device->device(), buffer, NULL);
7239 return;
7240 }
7241
7242 VkDeviceMemory mem;
7243 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7244 ASSERT_VK_SUCCESS(err);
7245 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
7246 ASSERT_VK_SUCCESS(err);
7247 // Correctly update descriptor to avoid "NOT_UPDATED" error
7248 VkDescriptorBufferInfo buffInfo = {};
7249 buffInfo.buffer = buffer;
7250 buffInfo.offset = 0;
7251 buffInfo.range = 1024;
7252
7253 VkWriteDescriptorSet descriptor_write;
7254 memset(&descriptor_write, 0, sizeof(descriptor_write));
7255 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7256 descriptor_write.dstSet = descriptorSet;
7257 descriptor_write.dstBinding = 0;
7258 descriptor_write.descriptorCount = 1;
7259 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7260 descriptor_write.pBufferInfo = &buffInfo;
7261
7262 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7263
7264 // Create PSO to be used for draw-time errors below
7265 char const *vsSource = "#version 450\n"
7266 "\n"
7267 "out gl_PerVertex { \n"
7268 " vec4 gl_Position;\n"
7269 "};\n"
7270 "void main(){\n"
7271 " gl_Position = vec4(1);\n"
7272 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007273 char const *fsSource = "#version 450\n"
7274 "\n"
7275 "layout(location=0) out vec4 x;\n"
7276 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7277 "void main(){\n"
7278 " x = vec4(bar.y);\n"
7279 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06007280 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7281 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7282 VkPipelineObj pipe(m_device);
7283 pipe.AddShader(&vs);
7284 pipe.AddShader(&fs);
7285 pipe.AddColorAttachment();
7286 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7287
7288 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007289 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7290 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7291 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06007292 Draw(1, 0, 0, 0);
7293 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06007295 // Destroy buffer should invalidate the cmd buffer, causing error on submit
7296 vkDestroyBuffer(m_device->device(), buffer, NULL);
7297 // Attempt to submit cmd buffer
7298 VkSubmitInfo submit_info = {};
7299 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7300 submit_info.commandBufferCount = 1;
7301 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7302 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7303 m_errorMonitor->VerifyFound();
7304 // Cleanup
7305 vkFreeMemory(m_device->device(), mem, NULL);
7306
7307 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7308 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7309 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7310}
7311
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007312TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
7313 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7314 "due to a bound descriptor sets with a combined image "
7315 "sampler having their image, sampler, and descriptor set "
7316 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06007317 "submit associated cmd buffers. Attempt to destroy a "
7318 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007319 ASSERT_NO_FATAL_FAILURE(InitState());
7320 ASSERT_NO_FATAL_FAILURE(InitViewport());
7321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7322
7323 VkDescriptorPoolSize ds_type_count = {};
7324 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7325 ds_type_count.descriptorCount = 1;
7326
7327 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7328 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7329 ds_pool_ci.pNext = NULL;
7330 ds_pool_ci.maxSets = 1;
7331 ds_pool_ci.poolSizeCount = 1;
7332 ds_pool_ci.pPoolSizes = &ds_type_count;
7333
7334 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007335 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007336 ASSERT_VK_SUCCESS(err);
7337
7338 VkDescriptorSetLayoutBinding dsl_binding = {};
7339 dsl_binding.binding = 0;
7340 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7341 dsl_binding.descriptorCount = 1;
7342 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7343 dsl_binding.pImmutableSamplers = NULL;
7344
7345 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7346 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7347 ds_layout_ci.pNext = NULL;
7348 ds_layout_ci.bindingCount = 1;
7349 ds_layout_ci.pBindings = &dsl_binding;
7350 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007351 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007352 ASSERT_VK_SUCCESS(err);
7353
7354 VkDescriptorSet descriptorSet;
7355 VkDescriptorSetAllocateInfo alloc_info = {};
7356 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7357 alloc_info.descriptorSetCount = 1;
7358 alloc_info.descriptorPool = ds_pool;
7359 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007360 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007361 ASSERT_VK_SUCCESS(err);
7362
7363 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7364 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7365 pipeline_layout_ci.pNext = NULL;
7366 pipeline_layout_ci.setLayoutCount = 1;
7367 pipeline_layout_ci.pSetLayouts = &ds_layout;
7368
7369 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007370 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007371 ASSERT_VK_SUCCESS(err);
7372
7373 // Create images to update the descriptor with
7374 VkImage image;
7375 VkImage image2;
7376 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7377 const int32_t tex_width = 32;
7378 const int32_t tex_height = 32;
7379 VkImageCreateInfo image_create_info = {};
7380 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7381 image_create_info.pNext = NULL;
7382 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7383 image_create_info.format = tex_format;
7384 image_create_info.extent.width = tex_width;
7385 image_create_info.extent.height = tex_height;
7386 image_create_info.extent.depth = 1;
7387 image_create_info.mipLevels = 1;
7388 image_create_info.arrayLayers = 1;
7389 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7390 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7391 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7392 image_create_info.flags = 0;
7393 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
7394 ASSERT_VK_SUCCESS(err);
7395 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
7396 ASSERT_VK_SUCCESS(err);
7397
7398 VkMemoryRequirements memory_reqs;
7399 VkDeviceMemory image_memory;
7400 bool pass;
7401 VkMemoryAllocateInfo memory_info = {};
7402 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7403 memory_info.pNext = NULL;
7404 memory_info.allocationSize = 0;
7405 memory_info.memoryTypeIndex = 0;
7406 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
7407 // Allocate enough memory for both images
7408 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007409 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007410 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007411 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007412 ASSERT_VK_SUCCESS(err);
7413 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
7414 ASSERT_VK_SUCCESS(err);
7415 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007416 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007417 ASSERT_VK_SUCCESS(err);
7418
7419 VkImageViewCreateInfo image_view_create_info = {};
7420 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7421 image_view_create_info.image = image;
7422 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
7423 image_view_create_info.format = tex_format;
7424 image_view_create_info.subresourceRange.layerCount = 1;
7425 image_view_create_info.subresourceRange.baseMipLevel = 0;
7426 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007427 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007428
7429 VkImageView view;
7430 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007431 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007432 ASSERT_VK_SUCCESS(err);
7433 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007434 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007435 ASSERT_VK_SUCCESS(err);
7436 // Create Samplers
7437 VkSamplerCreateInfo sampler_ci = {};
7438 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7439 sampler_ci.pNext = NULL;
7440 sampler_ci.magFilter = VK_FILTER_NEAREST;
7441 sampler_ci.minFilter = VK_FILTER_NEAREST;
7442 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7443 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7444 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7445 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7446 sampler_ci.mipLodBias = 1.0;
7447 sampler_ci.anisotropyEnable = VK_FALSE;
7448 sampler_ci.maxAnisotropy = 1;
7449 sampler_ci.compareEnable = VK_FALSE;
7450 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7451 sampler_ci.minLod = 1.0;
7452 sampler_ci.maxLod = 1.0;
7453 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7454 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7455 VkSampler sampler;
7456 VkSampler sampler2;
7457 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7458 ASSERT_VK_SUCCESS(err);
7459 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
7460 ASSERT_VK_SUCCESS(err);
7461 // Update descriptor with image and sampler
7462 VkDescriptorImageInfo img_info = {};
7463 img_info.sampler = sampler;
7464 img_info.imageView = view;
7465 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
7466
7467 VkWriteDescriptorSet descriptor_write;
7468 memset(&descriptor_write, 0, sizeof(descriptor_write));
7469 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7470 descriptor_write.dstSet = descriptorSet;
7471 descriptor_write.dstBinding = 0;
7472 descriptor_write.descriptorCount = 1;
7473 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7474 descriptor_write.pImageInfo = &img_info;
7475
7476 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7477
7478 // Create PSO to be used for draw-time errors below
7479 char const *vsSource = "#version 450\n"
7480 "\n"
7481 "out gl_PerVertex { \n"
7482 " vec4 gl_Position;\n"
7483 "};\n"
7484 "void main(){\n"
7485 " gl_Position = vec4(1);\n"
7486 "}\n";
7487 char const *fsSource = "#version 450\n"
7488 "\n"
7489 "layout(set=0, binding=0) uniform sampler2D s;\n"
7490 "layout(location=0) out vec4 x;\n"
7491 "void main(){\n"
7492 " x = texture(s, vec2(1));\n"
7493 "}\n";
7494 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7495 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7496 VkPipelineObj pipe(m_device);
7497 pipe.AddShader(&vs);
7498 pipe.AddShader(&fs);
7499 pipe.AddColorAttachment();
7500 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7501
7502 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007504 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007505 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7506 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7507 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007508 Draw(1, 0, 0, 0);
7509 EndCommandBuffer();
7510 // Destroy sampler invalidates the cmd buffer, causing error on submit
7511 vkDestroySampler(m_device->device(), sampler, NULL);
7512 // Attempt to submit cmd buffer
7513 VkSubmitInfo submit_info = {};
7514 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7515 submit_info.commandBufferCount = 1;
7516 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7517 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7518 m_errorMonitor->VerifyFound();
7519 // Now re-update descriptor with valid sampler and delete image
7520 img_info.sampler = sampler2;
7521 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007523 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007524 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7525 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7526 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007527 Draw(1, 0, 0, 0);
7528 EndCommandBuffer();
7529 // Destroy image invalidates the cmd buffer, causing error on submit
7530 vkDestroyImage(m_device->device(), image, NULL);
7531 // Attempt to submit cmd buffer
7532 submit_info = {};
7533 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7534 submit_info.commandBufferCount = 1;
7535 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7536 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7537 m_errorMonitor->VerifyFound();
7538 // Now update descriptor to be valid, but then free descriptor
7539 img_info.imageView = view2;
7540 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007542 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007543 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7544 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7545 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007546 Draw(1, 0, 0, 0);
7547 EndCommandBuffer();
7548 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007550 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06007551 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007552 // Attempt to submit cmd buffer
7553 submit_info = {};
7554 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7555 submit_info.commandBufferCount = 1;
7556 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7557 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7558 m_errorMonitor->VerifyFound();
7559 // Cleanup
7560 vkFreeMemory(m_device->device(), image_memory, NULL);
7561 vkDestroySampler(m_device->device(), sampler2, NULL);
7562 vkDestroyImage(m_device->device(), image2, NULL);
7563 vkDestroyImageView(m_device->device(), view, NULL);
7564 vkDestroyImageView(m_device->device(), view2, NULL);
7565 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7566 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7567 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7568}
7569
Karl Schultz6addd812016-02-02 17:17:23 -07007570TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06007571 // Attempt to bind an invalid Pipeline to a valid Command Buffer
7572 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007573 // Create a valid cmd buffer
7574 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06007575 uint64_t fake_pipeline_handle = 0xbaad6001;
7576 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06007578 ASSERT_NO_FATAL_FAILURE(InitState());
7579 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007580 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06007581 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007582 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007583 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 -06007584
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007585 BeginCommandBuffer();
7586 Draw(1, 0, 0, 0);
7587 m_errorMonitor->VerifyFound();
7588 // Finally same check once more but with Dispatch/Compute
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!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007590 BeginCommandBuffer();
7591 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
7592 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007593}
7594
Karl Schultz6addd812016-02-02 17:17:23 -07007595TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06007596 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07007597 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007598
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007600
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007601 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06007602 ASSERT_NO_FATAL_FAILURE(InitViewport());
7603 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007604 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007605 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7606 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007607
7608 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007609 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7610 ds_pool_ci.pNext = NULL;
7611 ds_pool_ci.maxSets = 1;
7612 ds_pool_ci.poolSizeCount = 1;
7613 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06007614
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007615 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007616 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007617 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007618
Tony Barboureb254902015-07-15 12:50:33 -06007619 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007620 dsl_binding.binding = 0;
7621 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7622 dsl_binding.descriptorCount = 1;
7623 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7624 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007625
Tony Barboureb254902015-07-15 12:50:33 -06007626 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007627 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7628 ds_layout_ci.pNext = NULL;
7629 ds_layout_ci.bindingCount = 1;
7630 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007631 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007632 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007633 ASSERT_VK_SUCCESS(err);
7634
7635 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007636 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007637 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007638 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007639 alloc_info.descriptorPool = ds_pool;
7640 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007641 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007642 ASSERT_VK_SUCCESS(err);
7643
Tony Barboureb254902015-07-15 12:50:33 -06007644 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007645 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7646 pipeline_layout_ci.pNext = NULL;
7647 pipeline_layout_ci.setLayoutCount = 1;
7648 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007649
7650 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007651 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007652 ASSERT_VK_SUCCESS(err);
7653
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007654 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06007655 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07007656 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007657 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007658
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007659 VkPipelineObj pipe(m_device);
7660 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007661 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06007662 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007663 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06007664
7665 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007666 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7667 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7668 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007669
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007670 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007671
Chia-I Wuf7458c52015-10-26 21:10:41 +08007672 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7673 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7674 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007675}
7676
Karl Schultz6addd812016-02-02 17:17:23 -07007677TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007678 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07007679 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007680
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
7682 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007683
7684 ASSERT_NO_FATAL_FAILURE(InitState());
7685 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007686 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7687 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007688
7689 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007690 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7691 ds_pool_ci.pNext = NULL;
7692 ds_pool_ci.maxSets = 1;
7693 ds_pool_ci.poolSizeCount = 1;
7694 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007695
7696 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007697 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007698 ASSERT_VK_SUCCESS(err);
7699
7700 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007701 dsl_binding.binding = 0;
7702 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7703 dsl_binding.descriptorCount = 1;
7704 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7705 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007706
7707 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007708 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7709 ds_layout_ci.pNext = NULL;
7710 ds_layout_ci.bindingCount = 1;
7711 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007712 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007713 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007714 ASSERT_VK_SUCCESS(err);
7715
7716 VkDescriptorSet descriptorSet;
7717 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007718 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007719 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007720 alloc_info.descriptorPool = ds_pool;
7721 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007722 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007723 ASSERT_VK_SUCCESS(err);
7724
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007725 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007726 VkWriteDescriptorSet descriptor_write;
7727 memset(&descriptor_write, 0, sizeof(descriptor_write));
7728 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7729 descriptor_write.dstSet = descriptorSet;
7730 descriptor_write.dstBinding = 0;
7731 descriptor_write.descriptorCount = 1;
7732 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7733 descriptor_write.pTexelBufferView = &view;
7734
7735 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7736
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007737 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007738
7739 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7740 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7741}
7742
Mark Youngd339ba32016-05-30 13:28:35 -06007743TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
7744 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has"
7745 " no memory bound to it.");
7746
7747 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindBufferMemory");
Mark Youngd339ba32016-05-30 13:28:35 -06007749
7750 ASSERT_NO_FATAL_FAILURE(InitState());
7751
7752 // Create a buffer with no bound memory and then attempt to create
7753 // a buffer view.
7754 VkBufferCreateInfo buff_ci = {};
7755 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7756 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7757 buff_ci.size = 256;
7758 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7759 VkBuffer buffer;
7760 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7761 ASSERT_VK_SUCCESS(err);
7762
7763 VkBufferViewCreateInfo buff_view_ci = {};
7764 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7765 buff_view_ci.buffer = buffer;
7766 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7767 buff_view_ci.range = VK_WHOLE_SIZE;
7768 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007769 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06007770
7771 m_errorMonitor->VerifyFound();
7772 vkDestroyBuffer(m_device->device(), buffer, NULL);
7773 // If last error is success, it still created the view, so delete it.
7774 if (err == VK_SUCCESS) {
7775 vkDestroyBufferView(m_device->device(), buff_view, NULL);
7776 }
7777}
7778
Karl Schultz6addd812016-02-02 17:17:23 -07007779TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
7780 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
7781 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07007782 // 1. No dynamicOffset supplied
7783 // 2. Too many dynamicOffsets supplied
7784 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07007785 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
7787 "0 dynamicOffsets are left in "
7788 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007789
7790 ASSERT_NO_FATAL_FAILURE(InitState());
7791 ASSERT_NO_FATAL_FAILURE(InitViewport());
7792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7793
7794 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007795 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7796 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007797
7798 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007799 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7800 ds_pool_ci.pNext = NULL;
7801 ds_pool_ci.maxSets = 1;
7802 ds_pool_ci.poolSizeCount = 1;
7803 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007804
7805 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007806 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007807 ASSERT_VK_SUCCESS(err);
7808
7809 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007810 dsl_binding.binding = 0;
7811 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7812 dsl_binding.descriptorCount = 1;
7813 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7814 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007815
7816 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007817 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7818 ds_layout_ci.pNext = NULL;
7819 ds_layout_ci.bindingCount = 1;
7820 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007821 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007822 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007823 ASSERT_VK_SUCCESS(err);
7824
7825 VkDescriptorSet descriptorSet;
7826 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007827 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007828 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007829 alloc_info.descriptorPool = ds_pool;
7830 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007831 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007832 ASSERT_VK_SUCCESS(err);
7833
7834 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007835 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7836 pipeline_layout_ci.pNext = NULL;
7837 pipeline_layout_ci.setLayoutCount = 1;
7838 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007839
7840 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007841 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007842 ASSERT_VK_SUCCESS(err);
7843
7844 // Create a buffer to update the descriptor with
7845 uint32_t qfi = 0;
7846 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007847 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7848 buffCI.size = 1024;
7849 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7850 buffCI.queueFamilyIndexCount = 1;
7851 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007852
7853 VkBuffer dyub;
7854 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
7855 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007856 // Allocate memory and bind to buffer so we can make it to the appropriate
7857 // error
7858 VkMemoryAllocateInfo mem_alloc = {};
7859 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7860 mem_alloc.pNext = NULL;
7861 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12007862 mem_alloc.memoryTypeIndex = 0;
7863
7864 VkMemoryRequirements memReqs;
7865 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007866 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12007867 if (!pass) {
7868 vkDestroyBuffer(m_device->device(), dyub, NULL);
7869 return;
7870 }
7871
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007872 VkDeviceMemory mem;
7873 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7874 ASSERT_VK_SUCCESS(err);
7875 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
7876 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007877 // Correctly update descriptor to avoid "NOT_UPDATED" error
7878 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007879 buffInfo.buffer = dyub;
7880 buffInfo.offset = 0;
7881 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007882
7883 VkWriteDescriptorSet descriptor_write;
7884 memset(&descriptor_write, 0, sizeof(descriptor_write));
7885 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7886 descriptor_write.dstSet = descriptorSet;
7887 descriptor_write.dstBinding = 0;
7888 descriptor_write.descriptorCount = 1;
7889 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7890 descriptor_write.pBufferInfo = &buffInfo;
7891
7892 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7893
7894 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007895 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7896 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007897 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007898 uint32_t pDynOff[2] = {512, 756};
7899 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7901 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
7902 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7903 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12007904 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007905 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
7907 "offset 0 and range 1024 that "
7908 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07007909 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007910 char const *vsSource = "#version 450\n"
7911 "\n"
7912 "out gl_PerVertex { \n"
7913 " vec4 gl_Position;\n"
7914 "};\n"
7915 "void main(){\n"
7916 " gl_Position = vec4(1);\n"
7917 "}\n";
7918 char const *fsSource = "#version 450\n"
7919 "\n"
7920 "layout(location=0) out vec4 x;\n"
7921 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7922 "void main(){\n"
7923 " x = vec4(bar.y);\n"
7924 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07007925 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7926 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7927 VkPipelineObj pipe(m_device);
7928 pipe.AddShader(&vs);
7929 pipe.AddShader(&fs);
7930 pipe.AddColorAttachment();
7931 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007933 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007934 // This update should succeed, but offset size of 512 will overstep buffer
7935 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007936 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7937 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07007938 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007939 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007940
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007941 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06007942 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007943
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007944 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007945 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007946 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7947}
7948
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007949TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
7950 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
7951 "that doesn't have memory bound");
7952 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " used without first calling vkBindBufferMemory.");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007954
7955 ASSERT_NO_FATAL_FAILURE(InitState());
7956 ASSERT_NO_FATAL_FAILURE(InitViewport());
7957 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7958
7959 VkDescriptorPoolSize ds_type_count = {};
7960 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7961 ds_type_count.descriptorCount = 1;
7962
7963 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7964 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7965 ds_pool_ci.pNext = NULL;
7966 ds_pool_ci.maxSets = 1;
7967 ds_pool_ci.poolSizeCount = 1;
7968 ds_pool_ci.pPoolSizes = &ds_type_count;
7969
7970 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007971 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007972 ASSERT_VK_SUCCESS(err);
7973
7974 VkDescriptorSetLayoutBinding dsl_binding = {};
7975 dsl_binding.binding = 0;
7976 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7977 dsl_binding.descriptorCount = 1;
7978 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7979 dsl_binding.pImmutableSamplers = NULL;
7980
7981 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7982 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7983 ds_layout_ci.pNext = NULL;
7984 ds_layout_ci.bindingCount = 1;
7985 ds_layout_ci.pBindings = &dsl_binding;
7986 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007987 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007988 ASSERT_VK_SUCCESS(err);
7989
7990 VkDescriptorSet descriptorSet;
7991 VkDescriptorSetAllocateInfo alloc_info = {};
7992 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7993 alloc_info.descriptorSetCount = 1;
7994 alloc_info.descriptorPool = ds_pool;
7995 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007996 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007997 ASSERT_VK_SUCCESS(err);
7998
7999 // Create a buffer to update the descriptor with
8000 uint32_t qfi = 0;
8001 VkBufferCreateInfo buffCI = {};
8002 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8003 buffCI.size = 1024;
8004 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8005 buffCI.queueFamilyIndexCount = 1;
8006 buffCI.pQueueFamilyIndices = &qfi;
8007
8008 VkBuffer dyub;
8009 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8010 ASSERT_VK_SUCCESS(err);
8011
8012 // Attempt to update descriptor without binding memory to it
8013 VkDescriptorBufferInfo buffInfo = {};
8014 buffInfo.buffer = dyub;
8015 buffInfo.offset = 0;
8016 buffInfo.range = 1024;
8017
8018 VkWriteDescriptorSet descriptor_write;
8019 memset(&descriptor_write, 0, sizeof(descriptor_write));
8020 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8021 descriptor_write.dstSet = descriptorSet;
8022 descriptor_write.dstBinding = 0;
8023 descriptor_write.descriptorCount = 1;
8024 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8025 descriptor_write.pBufferInfo = &buffInfo;
8026
8027 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8028 m_errorMonitor->VerifyFound();
8029
8030 vkDestroyBuffer(m_device->device(), dyub, NULL);
8031 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8032 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8033}
8034
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008035TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008036 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008037 ASSERT_NO_FATAL_FAILURE(InitState());
8038 ASSERT_NO_FATAL_FAILURE(InitViewport());
8039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8040
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008041 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008042 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008043 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8044 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8045 pipeline_layout_ci.pushConstantRangeCount = 1;
8046 pipeline_layout_ci.pPushConstantRanges = &pc_range;
8047
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008048 //
8049 // Check for invalid push constant ranges in pipeline layouts.
8050 //
8051 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008052 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008053 char const *msg;
8054 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008055
Karl Schultzc81037d2016-05-12 08:11:23 -06008056 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
8057 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
8058 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
8059 "vkCreatePipelineLayout() call has push constants index 0 with "
8060 "size 0."},
8061 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8062 "vkCreatePipelineLayout() call has push constants index 0 with "
8063 "size 1."},
8064 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
8065 "vkCreatePipelineLayout() call has push constants index 0 with "
8066 "size 1."},
8067 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
8068 "vkCreatePipelineLayout() call has push constants index 0 with "
8069 "size 0."},
8070 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8071 "vkCreatePipelineLayout() call has push constants index 0 with "
8072 "offset 1. Offset must"},
8073 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
8074 "vkCreatePipelineLayout() call has push constants index 0 "
8075 "with offset "},
8076 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
8077 "vkCreatePipelineLayout() call has push constants "
8078 "index 0 with offset "},
8079 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
8080 "vkCreatePipelineLayout() call has push constants index 0 "
8081 "with offset "},
8082 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
8083 "vkCreatePipelineLayout() call has push "
8084 "constants index 0 with offset "},
8085 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
8086 "vkCreatePipelineLayout() call has push "
8087 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008088 }};
8089
8090 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06008091 for (const auto &iter : range_tests) {
8092 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8094 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008095 m_errorMonitor->VerifyFound();
8096 if (VK_SUCCESS == err) {
8097 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8098 }
8099 }
8100
8101 // Check for invalid stage flag
8102 pc_range.offset = 0;
8103 pc_range.size = 16;
8104 pc_range.stageFlags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreatePipelineLayout() call has no stageFlags set.");
8106 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008107 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008108 if (VK_SUCCESS == err) {
8109 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8110 }
8111
8112 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06008113 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008114 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008115 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008116 char const *msg;
8117 };
8118
Karl Schultzc81037d2016-05-12 08:11:23 -06008119 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008120 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8121 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8122 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8123 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8124 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8125 "vkCreatePipelineLayout() call has push constants with overlapping "
8126 "ranges: 0:[0, 4), 1:[0, 4)"},
8127 {
8128 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8129 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8130 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8131 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8132 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
8133 "vkCreatePipelineLayout() call has push constants with "
8134 "overlapping "
8135 "ranges: 3:[12, 20), 4:[16, 20)",
8136 },
8137 {
8138 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8139 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8140 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8141 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8142 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8143 "vkCreatePipelineLayout() call has push constants with "
8144 "overlapping "
8145 "ranges: 0:[16, 20), 1:[12, 20)",
8146 },
8147 {
8148 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8149 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8150 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8151 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8152 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8153 "vkCreatePipelineLayout() call has push constants with "
8154 "overlapping "
8155 "ranges: 0:[16, 20), 3:[12, 20)",
8156 },
8157 {
8158 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8159 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
8160 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
8161 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
8162 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
8163 "vkCreatePipelineLayout() call has push constants with "
8164 "overlapping "
8165 "ranges: 0:[16, 20), 2:[4, 100)",
8166 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008167
Karl Schultzc81037d2016-05-12 08:11:23 -06008168 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008169 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06008170 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
8172 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008173 m_errorMonitor->VerifyFound();
8174 if (VK_SUCCESS == err) {
8175 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8176 }
8177 }
8178
8179 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008180 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8181 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8182 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8183 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
8184 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
8185 ""},
8186 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
8187 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
8188 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
8189 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
8190 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8191 ""}}};
Karl Schultzc81037d2016-05-12 08:11:23 -06008192 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008193 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
8194 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008195 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008196 m_errorMonitor->VerifyNotFound();
8197 if (VK_SUCCESS == err) {
8198 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8199 }
8200 }
8201
8202 //
8203 // CmdPushConstants tests
8204 //
Karl Schultzc81037d2016-05-12 08:11:23 -06008205 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008206
8207 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzc81037d2016-05-12 08:11:23 -06008208 const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{
8209 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
8210 "vkCmdPushConstants() call has push constants with size 0. Size "
8211 "must be greater than zero and a multiple of 4."},
8212 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8213 "vkCmdPushConstants() call has push constants with size 1. Size "
8214 "must be greater than zero and a multiple of 4."},
8215 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
8216 "vkCmdPushConstants() call has push constants with size 1. Size "
8217 "must be greater than zero and a multiple of 4."},
8218 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
8219 "vkCmdPushConstants() call has push constants with offset 1. "
8220 "Offset must be a multiple of 4."},
8221 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8222 "vkCmdPushConstants() call has push constants with offset 1. "
8223 "Offset must be a multiple of 4."},
8224 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8225 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8226 "0x1 not within flag-matching ranges in pipeline layout"},
8227 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
8228 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
8229 "0x1 not within flag-matching ranges in pipeline layout"},
8230 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
8231 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
8232 "0x1 not within flag-matching ranges in pipeline layout"},
8233 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
8234 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
8235 "0x1 not within flag-matching ranges in pipeline layout"},
8236 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
8237 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
8238 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008239 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06008240 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
8241 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008242 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, "vkCmdPushConstants() call has push constants with offset "},
8243 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, "vkCmdPushConstants() call has push constants with offset "},
8244 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, "vkCmdPushConstants() call has push constants with offset "},
8245 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, "vkCmdPushConstants() call has push constants with offset "},
8246 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008247 }};
8248
8249 // Two ranges for testing robustness
Karl Schultzc81037d2016-05-12 08:11:23 -06008250 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008251 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008252 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008253 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008254 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008255 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008256 ASSERT_VK_SUCCESS(err);
8257 BeginCommandBuffer();
Karl Schultzc81037d2016-05-12 08:11:23 -06008258 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8260 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008261 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008262 m_errorMonitor->VerifyFound();
8263 }
8264
8265 // Check for invalid stage flag
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants() call has no stageFlags set.");
8267 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008268 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06008269 EndCommandBuffer();
8270 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
8271 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008272
Karl Schultzc81037d2016-05-12 08:11:23 -06008273 // overlapping range tests with cmd
8274 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
8275 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8276 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8277 "0x1 not within flag-matching ranges in pipeline layout"},
8278 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8279 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
8280 "0x1 not within flag-matching ranges in pipeline layout"},
8281 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
8282 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
8283 "0x1 not within flag-matching ranges in pipeline layout"},
8284 }};
8285 const VkPushConstantRange pc_range3[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008286 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8287 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06008288 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
8289 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008290 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008291 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008292 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008293 ASSERT_VK_SUCCESS(err);
8294 BeginCommandBuffer();
8295 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8297 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008298 iter.range.size, dummy_values);
8299 m_errorMonitor->VerifyFound();
8300 }
8301 EndCommandBuffer();
8302 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
8303 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8304
8305 // positive overlapping range tests with cmd
8306 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
8307 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
8308 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
8309 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
8310 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
8311 }};
8312 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008313 {VK_SHADER_STAGE_VERTEX_BIT, 0, 64}, {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
8314 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
8315 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
Karl Schultzc81037d2016-05-12 08:11:23 -06008316 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008317 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008318 pipeline_layout_ci.pPushConstantRanges = pc_range4;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008319 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008320 ASSERT_VK_SUCCESS(err);
8321 BeginCommandBuffer();
8322 for (const auto &iter : cmd_overlap_tests_pos) {
8323 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008324 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008325 iter.range.size, dummy_values);
8326 m_errorMonitor->VerifyNotFound();
8327 }
8328 EndCommandBuffer();
8329 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008330 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8331}
8332
Karl Schultz6addd812016-02-02 17:17:23 -07008333TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008334 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07008335 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008336
8337 ASSERT_NO_FATAL_FAILURE(InitState());
8338 ASSERT_NO_FATAL_FAILURE(InitViewport());
8339 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8340
Mike Stroyanb8a61002016-06-20 16:00:28 -06008341 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
8342 VkImageTiling tiling;
8343 VkFormatProperties format_properties;
8344 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008345 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008346 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008347 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008348 tiling = VK_IMAGE_TILING_OPTIMAL;
8349 } else {
8350 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
8351 "skipped.\n");
8352 return;
8353 }
8354
Tobin Ehlis559c6382015-11-05 09:52:49 -07008355 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
8356 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008357 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8358 ds_type_count[0].descriptorCount = 10;
8359 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8360 ds_type_count[1].descriptorCount = 2;
8361 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8362 ds_type_count[2].descriptorCount = 2;
8363 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8364 ds_type_count[3].descriptorCount = 5;
8365 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
8366 // type
8367 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8368 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
8369 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008370
8371 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008372 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8373 ds_pool_ci.pNext = NULL;
8374 ds_pool_ci.maxSets = 5;
8375 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
8376 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008377
8378 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008379 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008380 ASSERT_VK_SUCCESS(err);
8381
8382 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
8383 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008384 dsl_binding[0].binding = 0;
8385 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8386 dsl_binding[0].descriptorCount = 5;
8387 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8388 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008389
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008390 // Create layout identical to set0 layout but w/ different stageFlags
8391 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008392 dsl_fs_stage_only.binding = 0;
8393 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8394 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008395 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
8396 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07008397 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008398 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008399 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8400 ds_layout_ci.pNext = NULL;
8401 ds_layout_ci.bindingCount = 1;
8402 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008403 static const uint32_t NUM_LAYOUTS = 4;
8404 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008405 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008406 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
8407 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008408 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008409 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008410 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008411 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008412 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008413 dsl_binding[0].binding = 0;
8414 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008415 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008416 dsl_binding[1].binding = 1;
8417 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8418 dsl_binding[1].descriptorCount = 2;
8419 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8420 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008421 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008422 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008423 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008424 ASSERT_VK_SUCCESS(err);
8425 dsl_binding[0].binding = 0;
8426 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008427 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008428 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008429 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008430 ASSERT_VK_SUCCESS(err);
8431 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008432 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008433 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008434 ASSERT_VK_SUCCESS(err);
8435
8436 static const uint32_t NUM_SETS = 4;
8437 VkDescriptorSet descriptorSet[NUM_SETS] = {};
8438 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008439 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008440 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008441 alloc_info.descriptorPool = ds_pool;
8442 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008443 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008444 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008445 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008446 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008447 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008448 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008449 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008450
8451 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008452 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8453 pipeline_layout_ci.pNext = NULL;
8454 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
8455 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008456
8457 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008458 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008459 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008460 // Create pipelineLayout with only one setLayout
8461 pipeline_layout_ci.setLayoutCount = 1;
8462 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008463 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008464 ASSERT_VK_SUCCESS(err);
8465 // Create pipelineLayout with 2 descriptor setLayout at index 0
8466 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
8467 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008468 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008469 ASSERT_VK_SUCCESS(err);
8470 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
8471 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
8472 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008473 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008474 ASSERT_VK_SUCCESS(err);
8475 // Create pipelineLayout with UB type, but stageFlags for FS only
8476 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
8477 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008478 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008479 ASSERT_VK_SUCCESS(err);
8480 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
8481 VkDescriptorSetLayout pl_bad_s0[2] = {};
8482 pl_bad_s0[0] = ds_layout_fs_only;
8483 pl_bad_s0[1] = ds_layout[1];
8484 pipeline_layout_ci.setLayoutCount = 2;
8485 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
8486 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008487 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008488 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008489
8490 // Create a buffer to update the descriptor with
8491 uint32_t qfi = 0;
8492 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008493 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8494 buffCI.size = 1024;
8495 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8496 buffCI.queueFamilyIndexCount = 1;
8497 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008498
8499 VkBuffer dyub;
8500 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8501 ASSERT_VK_SUCCESS(err);
8502 // Correctly update descriptor to avoid "NOT_UPDATED" error
8503 static const uint32_t NUM_BUFFS = 5;
8504 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008505 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008506 buffInfo[i].buffer = dyub;
8507 buffInfo[i].offset = 0;
8508 buffInfo[i].range = 1024;
8509 }
Karl Schultz6addd812016-02-02 17:17:23 -07008510 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07008511 const int32_t tex_width = 32;
8512 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008513 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008514 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8515 image_create_info.pNext = NULL;
8516 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8517 image_create_info.format = tex_format;
8518 image_create_info.extent.width = tex_width;
8519 image_create_info.extent.height = tex_height;
8520 image_create_info.extent.depth = 1;
8521 image_create_info.mipLevels = 1;
8522 image_create_info.arrayLayers = 1;
8523 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06008524 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008525 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07008526 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008527 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
8528 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008529
Karl Schultz6addd812016-02-02 17:17:23 -07008530 VkMemoryRequirements memReqs;
8531 VkDeviceMemory imageMem;
8532 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008533 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008534 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8535 memAlloc.pNext = NULL;
8536 memAlloc.allocationSize = 0;
8537 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008538 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
8539 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008540 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008541 ASSERT_TRUE(pass);
8542 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
8543 ASSERT_VK_SUCCESS(err);
8544 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
8545 ASSERT_VK_SUCCESS(err);
8546
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008547 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008548 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8549 image_view_create_info.image = image;
8550 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
8551 image_view_create_info.format = tex_format;
8552 image_view_create_info.subresourceRange.layerCount = 1;
8553 image_view_create_info.subresourceRange.baseMipLevel = 0;
8554 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008555 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008556
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008557 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008558 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008559 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008560 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008561 imageInfo[0].imageView = view;
8562 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8563 imageInfo[1].imageView = view;
8564 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008565 imageInfo[2].imageView = view;
8566 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8567 imageInfo[3].imageView = view;
8568 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008569
8570 static const uint32_t NUM_SET_UPDATES = 3;
8571 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
8572 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8573 descriptor_write[0].dstSet = descriptorSet[0];
8574 descriptor_write[0].dstBinding = 0;
8575 descriptor_write[0].descriptorCount = 5;
8576 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8577 descriptor_write[0].pBufferInfo = buffInfo;
8578 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8579 descriptor_write[1].dstSet = descriptorSet[1];
8580 descriptor_write[1].dstBinding = 0;
8581 descriptor_write[1].descriptorCount = 2;
8582 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8583 descriptor_write[1].pImageInfo = imageInfo;
8584 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8585 descriptor_write[2].dstSet = descriptorSet[1];
8586 descriptor_write[2].dstBinding = 1;
8587 descriptor_write[2].descriptorCount = 2;
8588 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008589 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008590
8591 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008592
Tobin Ehlis88452832015-12-03 09:40:56 -07008593 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008594 char const *vsSource = "#version 450\n"
8595 "\n"
8596 "out gl_PerVertex {\n"
8597 " vec4 gl_Position;\n"
8598 "};\n"
8599 "void main(){\n"
8600 " gl_Position = vec4(1);\n"
8601 "}\n";
8602 char const *fsSource = "#version 450\n"
8603 "\n"
8604 "layout(location=0) out vec4 x;\n"
8605 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8606 "void main(){\n"
8607 " x = vec4(bar.y);\n"
8608 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07008609 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8610 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008611 VkPipelineObj pipe(m_device);
8612 pipe.AddShader(&vs);
8613 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07008614 pipe.AddColorAttachment();
8615 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07008616
8617 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07008618
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008619 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008620 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
8621 // of PSO
8622 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
8623 // cmd_pipeline.c
8624 // due to the fact that cmd_alloc_dset_data() has not been called in
8625 // cmd_bind_graphics_pipeline()
8626 // TODO : Want to cause various binding incompatibility issues here to test
8627 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07008628 // First cause various verify_layout_compatibility() fails
8629 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008630 // verify_set_layout_compatibility fail cases:
8631 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
8633 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
8634 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008635 m_errorMonitor->VerifyFound();
8636
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008637 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
8639 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
8640 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008641 m_errorMonitor->VerifyFound();
8642
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008643 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008644 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
8645 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
8647 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
8648 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008649 m_errorMonitor->VerifyFound();
8650
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008651 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
8652 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
8654 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
8655 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008656 m_errorMonitor->VerifyFound();
8657
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008658 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
8659 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8661 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
8662 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8663 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008664 m_errorMonitor->VerifyFound();
8665
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008666 // Cause INFO messages due to disturbing previously bound Sets
8667 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008668 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8669 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008670 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
8672 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8673 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008674 m_errorMonitor->VerifyFound();
8675
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008676 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8677 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008678 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
8680 "any subsequent sets were disturbed ");
8681 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8682 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008683 m_errorMonitor->VerifyFound();
8684
Tobin Ehlis10fad692016-07-07 12:00:36 -06008685 // Now that we're done actively using the pipelineLayout that gfx pipeline
8686 // was created with, we should be able to delete it. Do that now to verify
8687 // that validation obeys pipelineLayout lifetime
8688 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
8689
Tobin Ehlis88452832015-12-03 09:40:56 -07008690 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07008691 // 1. Error due to not binding required set (we actually use same code as
8692 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008693 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8694 &descriptorSet[0], 0, NULL);
8695 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8696 &descriptorSet[1], 0, NULL);
8697 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 -07008698 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008699 m_errorMonitor->VerifyFound();
8700
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008701 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008702 // 2. Error due to bound set not being compatible with PSO's
8703 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008704 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8705 &descriptorSet[0], 0, NULL);
8706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07008707 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008708 m_errorMonitor->VerifyFound();
8709
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008710 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07008711 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008712 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
8713 }
8714 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06008715 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
8716 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008717 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008718 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8719 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008720 vkFreeMemory(m_device->device(), imageMem, NULL);
8721 vkDestroyImage(m_device->device(), image, NULL);
8722 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008723}
Tobin Ehlis559c6382015-11-05 09:52:49 -07008724
Karl Schultz6addd812016-02-02 17:17:23 -07008725TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008726
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8728 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008729
8730 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008731 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008732 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008733 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008734
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008735 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008736}
8737
Karl Schultz6addd812016-02-02 17:17:23 -07008738TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
8739 VkResult err;
8740 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008741
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008743
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008744 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008745
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008746 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008747 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008748 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008749 cmd.commandPool = m_commandPool;
8750 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008751 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06008752
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008753 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06008754 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008755
8756 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008757 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008758 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008759 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008760 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008761 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 -07008762 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008763
8764 // The error should be caught by validation of the BeginCommandBuffer call
8765 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
8766
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008767 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008768 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008769}
8770
Karl Schultz6addd812016-02-02 17:17:23 -07008771TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008772 // Cause error due to Begin while recording CB
8773 // Then cause 2 errors for attempting to reset CB w/o having
8774 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
8775 // which CBs were allocated. Note that this bit is off by default.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008777
8778 ASSERT_NO_FATAL_FAILURE(InitState());
8779
8780 // Calls AllocateCommandBuffers
8781 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
8782
Karl Schultz6addd812016-02-02 17:17:23 -07008783 // Force the failure by setting the Renderpass and Framebuffer fields with
8784 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008785 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008786 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008787 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8788 cmd_buf_info.pNext = NULL;
8789 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008790 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008791
8792 // Begin CB to transition to recording state
8793 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
8794 // Can't re-begin. This should trigger error
8795 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008796 m_errorMonitor->VerifyFound();
8797
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008799 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
8800 // Reset attempt will trigger error due to incorrect CommandPool state
8801 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008802 m_errorMonitor->VerifyFound();
8803
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008805 // Transition CB to RECORDED state
8806 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
8807 // Now attempting to Begin will implicitly reset, which triggers error
8808 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008809 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008810}
8811
Karl Schultz6addd812016-02-02 17:17:23 -07008812TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008813 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07008814 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008815
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vtx Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008817
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008818 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008820
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008821 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008822 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8823 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008824
8825 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008826 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8827 ds_pool_ci.pNext = NULL;
8828 ds_pool_ci.maxSets = 1;
8829 ds_pool_ci.poolSizeCount = 1;
8830 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008831
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008832 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008833 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008834 ASSERT_VK_SUCCESS(err);
8835
Tony Barboureb254902015-07-15 12:50:33 -06008836 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008837 dsl_binding.binding = 0;
8838 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8839 dsl_binding.descriptorCount = 1;
8840 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8841 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008842
Tony Barboureb254902015-07-15 12:50:33 -06008843 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008844 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8845 ds_layout_ci.pNext = NULL;
8846 ds_layout_ci.bindingCount = 1;
8847 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008848
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008849 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008850 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008851 ASSERT_VK_SUCCESS(err);
8852
8853 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008854 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008855 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008856 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008857 alloc_info.descriptorPool = ds_pool;
8858 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008859 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008860 ASSERT_VK_SUCCESS(err);
8861
Tony Barboureb254902015-07-15 12:50:33 -06008862 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008863 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8864 pipeline_layout_ci.setLayoutCount = 1;
8865 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008866
8867 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008868 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008869 ASSERT_VK_SUCCESS(err);
8870
Tobin Ehlise68360f2015-10-01 11:15:13 -06008871 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008872 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06008873
8874 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008875 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8876 vp_state_ci.scissorCount = 1;
8877 vp_state_ci.pScissors = &sc;
8878 vp_state_ci.viewportCount = 1;
8879 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008880
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008881 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8882 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8883 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8884 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8885 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8886 rs_state_ci.depthClampEnable = VK_FALSE;
8887 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8888 rs_state_ci.depthBiasEnable = VK_FALSE;
8889
Tony Barboureb254902015-07-15 12:50:33 -06008890 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008891 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8892 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008893 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008894 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8895 gp_ci.layout = pipeline_layout;
8896 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06008897
8898 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008899 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8900 pc_ci.initialDataSize = 0;
8901 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008902
8903 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06008904 VkPipelineCache pipelineCache;
8905
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008906 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06008907 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008908 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06008909
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008910 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008911
Chia-I Wuf7458c52015-10-26 21:10:41 +08008912 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8913 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8914 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8915 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008916}
Tobin Ehlis912df022015-09-17 08:46:18 -06008917/*// TODO : This test should be good, but needs Tess support in compiler to run
8918TEST_F(VkLayerTest, InvalidPatchControlPoints)
8919{
8920 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06008921 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008922
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008924 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
8925primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008926
Tobin Ehlis912df022015-09-17 08:46:18 -06008927 ASSERT_NO_FATAL_FAILURE(InitState());
8928 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06008929
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008930 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06008931 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008932 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008933
8934 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8935 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8936 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008937 ds_pool_ci.poolSizeCount = 1;
8938 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06008939
8940 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008941 err = vkCreateDescriptorPool(m_device->device(),
8942VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06008943 ASSERT_VK_SUCCESS(err);
8944
8945 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08008946 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06008947 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08008948 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008949 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8950 dsl_binding.pImmutableSamplers = NULL;
8951
8952 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008953 ds_layout_ci.sType =
8954VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06008955 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008956 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008957 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06008958
8959 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008960 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8961&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06008962 ASSERT_VK_SUCCESS(err);
8963
8964 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008965 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
8966VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06008967 ASSERT_VK_SUCCESS(err);
8968
8969 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008970 pipeline_layout_ci.sType =
8971VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06008972 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008973 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008974 pipeline_layout_ci.pSetLayouts = &ds_layout;
8975
8976 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008977 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8978&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06008979 ASSERT_VK_SUCCESS(err);
8980
8981 VkPipelineShaderStageCreateInfo shaderStages[3];
8982 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
8983
Karl Schultz6addd812016-02-02 17:17:23 -07008984 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
8985this);
Tobin Ehlis912df022015-09-17 08:46:18 -06008986 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07008987 VkShaderObj
8988tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
8989this);
8990 VkShaderObj
8991te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
8992this);
Tobin Ehlis912df022015-09-17 08:46:18 -06008993
Karl Schultz6addd812016-02-02 17:17:23 -07008994 shaderStages[0].sType =
8995VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008996 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06008997 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07008998 shaderStages[1].sType =
8999VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009000 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009001 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07009002 shaderStages[2].sType =
9003VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009004 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009005 shaderStages[2].shader = te.handle();
9006
9007 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009008 iaCI.sType =
9009VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08009010 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06009011
9012 VkPipelineTessellationStateCreateInfo tsCI = {};
9013 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
9014 tsCI.patchControlPoints = 0; // This will cause an error
9015
9016 VkGraphicsPipelineCreateInfo gp_ci = {};
9017 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9018 gp_ci.pNext = NULL;
9019 gp_ci.stageCount = 3;
9020 gp_ci.pStages = shaderStages;
9021 gp_ci.pVertexInputState = NULL;
9022 gp_ci.pInputAssemblyState = &iaCI;
9023 gp_ci.pTessellationState = &tsCI;
9024 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009025 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06009026 gp_ci.pMultisampleState = NULL;
9027 gp_ci.pDepthStencilState = NULL;
9028 gp_ci.pColorBlendState = NULL;
9029 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9030 gp_ci.layout = pipeline_layout;
9031 gp_ci.renderPass = renderPass();
9032
9033 VkPipelineCacheCreateInfo pc_ci = {};
9034 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9035 pc_ci.pNext = NULL;
9036 pc_ci.initialSize = 0;
9037 pc_ci.initialData = 0;
9038 pc_ci.maxSize = 0;
9039
9040 VkPipeline pipeline;
9041 VkPipelineCache pipelineCache;
9042
Karl Schultz6addd812016-02-02 17:17:23 -07009043 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
9044&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06009045 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009046 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
9047&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06009048
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009049 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009050
Chia-I Wuf7458c52015-10-26 21:10:41 +08009051 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9052 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9053 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9054 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06009055}
9056*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06009057// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07009058TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07009059 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009060
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9062 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009063
Tobin Ehlise68360f2015-10-01 11:15:13 -06009064 ASSERT_NO_FATAL_FAILURE(InitState());
9065 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009066
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009067 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009068 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9069 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009070
9071 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009072 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9073 ds_pool_ci.maxSets = 1;
9074 ds_pool_ci.poolSizeCount = 1;
9075 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009076
9077 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009078 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009079 ASSERT_VK_SUCCESS(err);
9080
9081 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009082 dsl_binding.binding = 0;
9083 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9084 dsl_binding.descriptorCount = 1;
9085 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009086
9087 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009088 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9089 ds_layout_ci.bindingCount = 1;
9090 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009091
9092 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009093 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009094 ASSERT_VK_SUCCESS(err);
9095
9096 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009097 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009098 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009099 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009100 alloc_info.descriptorPool = ds_pool;
9101 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009102 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009103 ASSERT_VK_SUCCESS(err);
9104
9105 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009106 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9107 pipeline_layout_ci.setLayoutCount = 1;
9108 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009109
9110 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009111 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009112 ASSERT_VK_SUCCESS(err);
9113
9114 VkViewport vp = {}; // Just need dummy vp to point to
9115
9116 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009117 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9118 vp_state_ci.scissorCount = 0;
9119 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
9120 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009121
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009122 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9123 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9124 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9125 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9126 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9127 rs_state_ci.depthClampEnable = VK_FALSE;
9128 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9129 rs_state_ci.depthBiasEnable = VK_FALSE;
9130
Cody Northropeb3a6c12015-10-05 14:44:45 -06009131 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009132 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009133
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009134 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9135 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9136 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009137 shaderStages[0] = vs.GetStageCreateInfo();
9138 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009139
9140 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009141 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9142 gp_ci.stageCount = 2;
9143 gp_ci.pStages = shaderStages;
9144 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009145 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009146 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9147 gp_ci.layout = pipeline_layout;
9148 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009149
9150 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009151 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009152
9153 VkPipeline pipeline;
9154 VkPipelineCache pipelineCache;
9155
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009156 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009157 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009158 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009159
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009160 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009161
Chia-I Wuf7458c52015-10-26 21:10:41 +08009162 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9163 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9164 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9165 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009166}
Karl Schultz6addd812016-02-02 17:17:23 -07009167// Don't set viewport state in PSO. This is an error b/c we always need this
9168// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06009169// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07009170TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06009171 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07009172 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009173
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009175
Tobin Ehlise68360f2015-10-01 11:15:13 -06009176 ASSERT_NO_FATAL_FAILURE(InitState());
9177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009178
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009179 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009180 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9181 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009182
9183 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009184 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9185 ds_pool_ci.maxSets = 1;
9186 ds_pool_ci.poolSizeCount = 1;
9187 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009188
9189 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009190 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009191 ASSERT_VK_SUCCESS(err);
9192
9193 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009194 dsl_binding.binding = 0;
9195 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9196 dsl_binding.descriptorCount = 1;
9197 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009198
9199 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009200 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9201 ds_layout_ci.bindingCount = 1;
9202 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009203
9204 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009205 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009206 ASSERT_VK_SUCCESS(err);
9207
9208 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009209 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009210 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009211 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009212 alloc_info.descriptorPool = ds_pool;
9213 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009214 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009215 ASSERT_VK_SUCCESS(err);
9216
9217 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009218 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9219 pipeline_layout_ci.setLayoutCount = 1;
9220 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009221
9222 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009223 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009224 ASSERT_VK_SUCCESS(err);
9225
9226 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9227 // Set scissor as dynamic to avoid second error
9228 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009229 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9230 dyn_state_ci.dynamicStateCount = 1;
9231 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009232
Cody Northropeb3a6c12015-10-05 14:44:45 -06009233 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009234 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009235
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009236 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9237 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9238 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009239 shaderStages[0] = vs.GetStageCreateInfo();
9240 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009241
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009242 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9243 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9244 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9245 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9246 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9247 rs_state_ci.depthClampEnable = VK_FALSE;
9248 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9249 rs_state_ci.depthBiasEnable = VK_FALSE;
9250
Tobin Ehlise68360f2015-10-01 11:15:13 -06009251 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009252 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9253 gp_ci.stageCount = 2;
9254 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009255 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009256 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
9257 // should cause validation error
9258 gp_ci.pDynamicState = &dyn_state_ci;
9259 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9260 gp_ci.layout = pipeline_layout;
9261 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009262
9263 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009264 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009265
9266 VkPipeline pipeline;
9267 VkPipelineCache pipelineCache;
9268
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009269 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009270 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009271 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009272
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009273 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009274
Chia-I Wuf7458c52015-10-26 21:10:41 +08009275 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9276 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9277 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9278 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009279}
9280// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07009281// Then run second test where dynamic scissor count doesn't match PSO scissor
9282// count
9283TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
9284 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009285
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9287 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009288
Tobin Ehlise68360f2015-10-01 11:15:13 -06009289 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009290
9291 if (!m_device->phy().features().multiViewport) {
9292 printf("Device does not support multiple viewports/scissors; skipped.\n");
9293 return;
9294 }
9295
Tobin Ehlise68360f2015-10-01 11:15:13 -06009296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009297
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009298 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009299 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9300 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009301
9302 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009303 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9304 ds_pool_ci.maxSets = 1;
9305 ds_pool_ci.poolSizeCount = 1;
9306 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009307
9308 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009309 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009310 ASSERT_VK_SUCCESS(err);
9311
9312 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009313 dsl_binding.binding = 0;
9314 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9315 dsl_binding.descriptorCount = 1;
9316 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009317
9318 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009319 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9320 ds_layout_ci.bindingCount = 1;
9321 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009322
9323 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009324 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009325 ASSERT_VK_SUCCESS(err);
9326
9327 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009328 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009329 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009330 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009331 alloc_info.descriptorPool = ds_pool;
9332 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009333 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009334 ASSERT_VK_SUCCESS(err);
9335
9336 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009337 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9338 pipeline_layout_ci.setLayoutCount = 1;
9339 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009340
9341 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009342 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009343 ASSERT_VK_SUCCESS(err);
9344
9345 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009346 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9347 vp_state_ci.viewportCount = 1;
9348 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
9349 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009350 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06009351
9352 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9353 // Set scissor as dynamic to avoid that error
9354 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009355 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9356 dyn_state_ci.dynamicStateCount = 1;
9357 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009358
Cody Northropeb3a6c12015-10-05 14:44:45 -06009359 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009360 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009361
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009362 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9363 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9364 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009365 shaderStages[0] = vs.GetStageCreateInfo();
9366 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009367
Cody Northropf6622dc2015-10-06 10:33:21 -06009368 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9369 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9370 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009371 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009372 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009373 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009374 vi_ci.pVertexAttributeDescriptions = nullptr;
9375
9376 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9377 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9378 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9379
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009380 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009381 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06009382 rs_ci.pNext = nullptr;
9383
Mark Youngc89c6312016-03-31 16:03:20 -06009384 VkPipelineColorBlendAttachmentState att = {};
9385 att.blendEnable = VK_FALSE;
9386 att.colorWriteMask = 0xf;
9387
Cody Northropf6622dc2015-10-06 10:33:21 -06009388 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9389 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9390 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009391 cb_ci.attachmentCount = 1;
9392 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06009393
Tobin Ehlise68360f2015-10-01 11:15:13 -06009394 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009395 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9396 gp_ci.stageCount = 2;
9397 gp_ci.pStages = shaderStages;
9398 gp_ci.pVertexInputState = &vi_ci;
9399 gp_ci.pInputAssemblyState = &ia_ci;
9400 gp_ci.pViewportState = &vp_state_ci;
9401 gp_ci.pRasterizationState = &rs_ci;
9402 gp_ci.pColorBlendState = &cb_ci;
9403 gp_ci.pDynamicState = &dyn_state_ci;
9404 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9405 gp_ci.layout = pipeline_layout;
9406 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009407
9408 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009409 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009410
9411 VkPipeline pipeline;
9412 VkPipelineCache pipelineCache;
9413
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009414 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009415 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009416 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009417
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009418 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009419
Tobin Ehlisd332f282015-10-02 11:00:56 -06009420 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07009421 // First need to successfully create the PSO from above by setting
9422 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by PSO, ");
Karl Schultz6addd812016-02-02 17:17:23 -07009424
9425 VkViewport vp = {}; // Just need dummy vp to point to
9426 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009427 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009428 ASSERT_VK_SUCCESS(err);
9429 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009430 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009431 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07009432 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009433 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07009434 Draw(1, 0, 0, 0);
9435
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009436 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009437
9438 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9439 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9440 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9441 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009442 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07009443}
9444// Create PSO w/o non-zero scissorCount but no scissor data
9445// Then run second test where dynamic viewportCount doesn't match PSO
9446// viewportCount
9447TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
9448 VkResult err;
9449
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009450 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 -07009451
9452 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009453
9454 if (!m_device->phy().features().multiViewport) {
9455 printf("Device does not support multiple viewports/scissors; skipped.\n");
9456 return;
9457 }
9458
Karl Schultz6addd812016-02-02 17:17:23 -07009459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9460
9461 VkDescriptorPoolSize ds_type_count = {};
9462 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9463 ds_type_count.descriptorCount = 1;
9464
9465 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9466 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9467 ds_pool_ci.maxSets = 1;
9468 ds_pool_ci.poolSizeCount = 1;
9469 ds_pool_ci.pPoolSizes = &ds_type_count;
9470
9471 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009472 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07009473 ASSERT_VK_SUCCESS(err);
9474
9475 VkDescriptorSetLayoutBinding dsl_binding = {};
9476 dsl_binding.binding = 0;
9477 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9478 dsl_binding.descriptorCount = 1;
9479 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9480
9481 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9482 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9483 ds_layout_ci.bindingCount = 1;
9484 ds_layout_ci.pBindings = &dsl_binding;
9485
9486 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009487 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009488 ASSERT_VK_SUCCESS(err);
9489
9490 VkDescriptorSet descriptorSet;
9491 VkDescriptorSetAllocateInfo alloc_info = {};
9492 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9493 alloc_info.descriptorSetCount = 1;
9494 alloc_info.descriptorPool = ds_pool;
9495 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009496 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07009497 ASSERT_VK_SUCCESS(err);
9498
9499 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9500 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9501 pipeline_layout_ci.setLayoutCount = 1;
9502 pipeline_layout_ci.pSetLayouts = &ds_layout;
9503
9504 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009505 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009506 ASSERT_VK_SUCCESS(err);
9507
9508 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9509 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9510 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009511 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009512 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009513 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009514
9515 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
9516 // Set scissor as dynamic to avoid that error
9517 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9518 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9519 dyn_state_ci.dynamicStateCount = 1;
9520 dyn_state_ci.pDynamicStates = &vp_state;
9521
9522 VkPipelineShaderStageCreateInfo shaderStages[2];
9523 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9524
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009525 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9526 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9527 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07009528 shaderStages[0] = vs.GetStageCreateInfo();
9529 shaderStages[1] = fs.GetStageCreateInfo();
9530
9531 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9532 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9533 vi_ci.pNext = nullptr;
9534 vi_ci.vertexBindingDescriptionCount = 0;
9535 vi_ci.pVertexBindingDescriptions = nullptr;
9536 vi_ci.vertexAttributeDescriptionCount = 0;
9537 vi_ci.pVertexAttributeDescriptions = nullptr;
9538
9539 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9540 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9541 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9542
9543 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9544 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9545 rs_ci.pNext = nullptr;
9546
Mark Youngc89c6312016-03-31 16:03:20 -06009547 VkPipelineColorBlendAttachmentState att = {};
9548 att.blendEnable = VK_FALSE;
9549 att.colorWriteMask = 0xf;
9550
Karl Schultz6addd812016-02-02 17:17:23 -07009551 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9552 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9553 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009554 cb_ci.attachmentCount = 1;
9555 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07009556
9557 VkGraphicsPipelineCreateInfo gp_ci = {};
9558 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9559 gp_ci.stageCount = 2;
9560 gp_ci.pStages = shaderStages;
9561 gp_ci.pVertexInputState = &vi_ci;
9562 gp_ci.pInputAssemblyState = &ia_ci;
9563 gp_ci.pViewportState = &vp_state_ci;
9564 gp_ci.pRasterizationState = &rs_ci;
9565 gp_ci.pColorBlendState = &cb_ci;
9566 gp_ci.pDynamicState = &dyn_state_ci;
9567 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9568 gp_ci.layout = pipeline_layout;
9569 gp_ci.renderPass = renderPass();
9570
9571 VkPipelineCacheCreateInfo pc_ci = {};
9572 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9573
9574 VkPipeline pipeline;
9575 VkPipelineCache pipelineCache;
9576
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009577 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07009578 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009579 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009580
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009581 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009582
9583 // Now hit second fail case where we set scissor w/ different count than PSO
9584 // First need to successfully create the PSO from above by setting
9585 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by PSO, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009587
Tobin Ehlisd332f282015-10-02 11:00:56 -06009588 VkRect2D sc = {}; // Just need dummy vp to point to
9589 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009590 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009591 ASSERT_VK_SUCCESS(err);
9592 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009593 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009594 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06009595 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009596 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009597 Draw(1, 0, 0, 0);
9598
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009599 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009600
Chia-I Wuf7458c52015-10-26 21:10:41 +08009601 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9602 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9603 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9604 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009605 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009606}
9607
Mark Young7394fdd2016-03-31 14:56:43 -06009608TEST_F(VkLayerTest, PSOLineWidthInvalid) {
9609 VkResult err;
9610
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009612
9613 ASSERT_NO_FATAL_FAILURE(InitState());
9614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9615
9616 VkDescriptorPoolSize ds_type_count = {};
9617 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9618 ds_type_count.descriptorCount = 1;
9619
9620 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9621 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9622 ds_pool_ci.maxSets = 1;
9623 ds_pool_ci.poolSizeCount = 1;
9624 ds_pool_ci.pPoolSizes = &ds_type_count;
9625
9626 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009627 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06009628 ASSERT_VK_SUCCESS(err);
9629
9630 VkDescriptorSetLayoutBinding dsl_binding = {};
9631 dsl_binding.binding = 0;
9632 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9633 dsl_binding.descriptorCount = 1;
9634 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9635
9636 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9637 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9638 ds_layout_ci.bindingCount = 1;
9639 ds_layout_ci.pBindings = &dsl_binding;
9640
9641 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009642 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009643 ASSERT_VK_SUCCESS(err);
9644
9645 VkDescriptorSet descriptorSet;
9646 VkDescriptorSetAllocateInfo alloc_info = {};
9647 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9648 alloc_info.descriptorSetCount = 1;
9649 alloc_info.descriptorPool = ds_pool;
9650 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009651 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06009652 ASSERT_VK_SUCCESS(err);
9653
9654 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9655 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9656 pipeline_layout_ci.setLayoutCount = 1;
9657 pipeline_layout_ci.pSetLayouts = &ds_layout;
9658
9659 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009660 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009661 ASSERT_VK_SUCCESS(err);
9662
9663 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9664 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9665 vp_state_ci.scissorCount = 1;
9666 vp_state_ci.pScissors = NULL;
9667 vp_state_ci.viewportCount = 1;
9668 vp_state_ci.pViewports = NULL;
9669
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009670 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06009671 // Set scissor as dynamic to avoid that error
9672 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9673 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9674 dyn_state_ci.dynamicStateCount = 2;
9675 dyn_state_ci.pDynamicStates = dynamic_states;
9676
9677 VkPipelineShaderStageCreateInfo shaderStages[2];
9678 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9679
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009680 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9681 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06009682 this); // TODO - We shouldn't need a fragment shader
9683 // but add it to be able to run on more devices
9684 shaderStages[0] = vs.GetStageCreateInfo();
9685 shaderStages[1] = fs.GetStageCreateInfo();
9686
9687 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9688 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9689 vi_ci.pNext = nullptr;
9690 vi_ci.vertexBindingDescriptionCount = 0;
9691 vi_ci.pVertexBindingDescriptions = nullptr;
9692 vi_ci.vertexAttributeDescriptionCount = 0;
9693 vi_ci.pVertexAttributeDescriptions = nullptr;
9694
9695 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9696 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9697 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9698
9699 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9700 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9701 rs_ci.pNext = nullptr;
9702
Mark Young47107952016-05-02 15:59:55 -06009703 // Check too low (line width of -1.0f).
9704 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06009705
9706 VkPipelineColorBlendAttachmentState att = {};
9707 att.blendEnable = VK_FALSE;
9708 att.colorWriteMask = 0xf;
9709
9710 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9711 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9712 cb_ci.pNext = nullptr;
9713 cb_ci.attachmentCount = 1;
9714 cb_ci.pAttachments = &att;
9715
9716 VkGraphicsPipelineCreateInfo gp_ci = {};
9717 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9718 gp_ci.stageCount = 2;
9719 gp_ci.pStages = shaderStages;
9720 gp_ci.pVertexInputState = &vi_ci;
9721 gp_ci.pInputAssemblyState = &ia_ci;
9722 gp_ci.pViewportState = &vp_state_ci;
9723 gp_ci.pRasterizationState = &rs_ci;
9724 gp_ci.pColorBlendState = &cb_ci;
9725 gp_ci.pDynamicState = &dyn_state_ci;
9726 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9727 gp_ci.layout = pipeline_layout;
9728 gp_ci.renderPass = renderPass();
9729
9730 VkPipelineCacheCreateInfo pc_ci = {};
9731 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9732
9733 VkPipeline pipeline;
9734 VkPipelineCache pipelineCache;
9735
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009736 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009737 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009738 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009739
9740 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009741 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009742
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009744
9745 // Check too high (line width of 65536.0f).
9746 rs_ci.lineWidth = 65536.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
9752 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009753 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009754
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009756
9757 dyn_state_ci.dynamicStateCount = 3;
9758
9759 rs_ci.lineWidth = 1.0f;
9760
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009761 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009762 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009763 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009764 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009765 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009766
9767 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06009768 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06009769 m_errorMonitor->VerifyFound();
9770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009772
9773 // Check too high with dynamic setting.
9774 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
9775 m_errorMonitor->VerifyFound();
9776 EndCommandBuffer();
9777
9778 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9779 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9780 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9781 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009782 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009783}
9784
Karl Schultz6addd812016-02-02 17:17:23 -07009785TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009786 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9788 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009789
9790 ASSERT_NO_FATAL_FAILURE(InitState());
9791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009792
Tony Barbourfe3351b2015-07-28 10:17:20 -06009793 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009794 // Don't care about RenderPass handle b/c error should be flagged before
9795 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009796 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009797
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009798 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009799}
9800
Karl Schultz6addd812016-02-02 17:17:23 -07009801TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009802 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9804 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009805
9806 ASSERT_NO_FATAL_FAILURE(InitState());
9807 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009808
Tony Barbourfe3351b2015-07-28 10:17:20 -06009809 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009810 // Just create a dummy Renderpass that's non-NULL so we can get to the
9811 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009812 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009813
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009814 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009815}
9816
Chris Forbes2eeabe32016-06-21 20:52:34 +12009817TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
9818 m_errorMonitor->ExpectSuccess();
9819
9820 ASSERT_NO_FATAL_FAILURE(InitState());
9821 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9822
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009823 BeginCommandBuffer(); // framework implicitly begins the renderpass.
Chris Forbes2eeabe32016-06-21 20:52:34 +12009824 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit.
9825
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009826 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009827 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9828 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009829 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009830 m_errorMonitor->VerifyNotFound();
9831 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9832 m_errorMonitor->VerifyNotFound();
9833
9834 m_commandBuffer->EndCommandBuffer();
9835 m_errorMonitor->VerifyNotFound();
9836}
9837
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009838TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
9839 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
9840 "the number of renderPass attachments that use loadOp"
9841 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
9842
9843 ASSERT_NO_FATAL_FAILURE(InitState());
9844 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9845
9846 // Create a renderPass with a single attachment that uses loadOp CLEAR
9847 VkAttachmentReference attach = {};
9848 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9849 VkSubpassDescription subpass = {};
9850 subpass.inputAttachmentCount = 1;
9851 subpass.pInputAttachments = &attach;
9852 VkRenderPassCreateInfo rpci = {};
9853 rpci.subpassCount = 1;
9854 rpci.pSubpasses = &subpass;
9855 rpci.attachmentCount = 1;
9856 VkAttachmentDescription attach_desc = {};
9857 attach_desc.format = VK_FORMAT_UNDEFINED;
9858 // Set loadOp to CLEAR
9859 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9860 rpci.pAttachments = &attach_desc;
9861 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9862 VkRenderPass rp;
9863 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9864
9865 VkCommandBufferInheritanceInfo hinfo = {};
9866 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9867 hinfo.renderPass = VK_NULL_HANDLE;
9868 hinfo.subpass = 0;
9869 hinfo.framebuffer = VK_NULL_HANDLE;
9870 hinfo.occlusionQueryEnable = VK_FALSE;
9871 hinfo.queryFlags = 0;
9872 hinfo.pipelineStatistics = 0;
9873 VkCommandBufferBeginInfo info = {};
9874 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9875 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9876 info.pInheritanceInfo = &hinfo;
9877
9878 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9879 VkRenderPassBeginInfo rp_begin = {};
9880 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9881 rp_begin.pNext = NULL;
9882 rp_begin.renderPass = renderPass();
9883 rp_begin.framebuffer = framebuffer();
9884 rp_begin.clearValueCount = 0; // Should be 1
9885
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
9887 "there must be at least 1 entries in "
9888 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009889
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009890 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009891
9892 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06009893
9894 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009895}
9896
Cody Northrop3bb4d962016-05-09 16:15:57 -06009897TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
9898
9899 TEST_DESCRIPTION("End a command buffer with an active render pass");
9900
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9902 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06009903
9904 ASSERT_NO_FATAL_FAILURE(InitState());
9905 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9906
9907 // The framework's BeginCommandBuffer calls CreateRenderPass
9908 BeginCommandBuffer();
9909
9910 // Call directly into vkEndCommandBuffer instead of the
9911 // the framework's EndCommandBuffer, which inserts a
9912 // vkEndRenderPass
9913 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
9914
9915 m_errorMonitor->VerifyFound();
9916
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009917 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
9918 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06009919}
9920
Karl Schultz6addd812016-02-02 17:17:23 -07009921TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009922 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9924 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009925
9926 ASSERT_NO_FATAL_FAILURE(InitState());
9927 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009928
9929 // Renderpass is started here
9930 BeginCommandBuffer();
9931
9932 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009933 vk_testing::Buffer dstBuffer;
9934 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009935
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009936 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009937
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009938 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009939}
9940
Karl Schultz6addd812016-02-02 17:17:23 -07009941TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009942 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9944 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009945
9946 ASSERT_NO_FATAL_FAILURE(InitState());
9947 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009948
9949 // Renderpass is started here
9950 BeginCommandBuffer();
9951
9952 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009953 vk_testing::Buffer dstBuffer;
9954 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009955
Karl Schultz6addd812016-02-02 17:17:23 -07009956 VkDeviceSize dstOffset = 0;
9957 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06009958 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009959
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009960 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009961
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009962 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009963}
9964
Karl Schultz6addd812016-02-02 17:17:23 -07009965TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009966 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9968 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009969
9970 ASSERT_NO_FATAL_FAILURE(InitState());
9971 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009972
9973 // Renderpass is started here
9974 BeginCommandBuffer();
9975
Michael Lentine0a369f62016-02-03 16:51:46 -06009976 VkClearColorValue clear_color;
9977 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07009978 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9979 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9980 const int32_t tex_width = 32;
9981 const int32_t tex_height = 32;
9982 VkImageCreateInfo image_create_info = {};
9983 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9984 image_create_info.pNext = NULL;
9985 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9986 image_create_info.format = tex_format;
9987 image_create_info.extent.width = tex_width;
9988 image_create_info.extent.height = tex_height;
9989 image_create_info.extent.depth = 1;
9990 image_create_info.mipLevels = 1;
9991 image_create_info.arrayLayers = 1;
9992 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9993 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9994 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009995
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009996 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009997 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009998
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009999 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010000
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010001 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010002
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010003 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010004}
10005
Karl Schultz6addd812016-02-02 17:17:23 -070010006TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010007 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10009 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010010
10011 ASSERT_NO_FATAL_FAILURE(InitState());
10012 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010013
10014 // Renderpass is started here
10015 BeginCommandBuffer();
10016
10017 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -070010018 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010019 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
10020 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10021 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
10022 image_create_info.extent.width = 64;
10023 image_create_info.extent.height = 64;
10024 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10025 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010026
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010027 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010028 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010029
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010030 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010032 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
10033 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010034
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010035 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010036}
10037
Karl Schultz6addd812016-02-02 17:17:23 -070010038TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010039 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010040 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010041
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
10043 "must be issued inside an active "
10044 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010045
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010046 ASSERT_NO_FATAL_FAILURE(InitState());
10047 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010048
10049 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010050 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010051 ASSERT_VK_SUCCESS(err);
10052
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010053 VkClearAttachment color_attachment;
10054 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10055 color_attachment.clearValue.color.float32[0] = 0;
10056 color_attachment.clearValue.color.float32[1] = 0;
10057 color_attachment.clearValue.color.float32[2] = 0;
10058 color_attachment.clearValue.color.float32[3] = 0;
10059 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010060 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010061 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010062
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010063 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010064}
10065
Chris Forbes3b97e932016-09-07 11:29:24 +120010066TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
10067 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
10068 "called too many times in a renderpass instance");
10069
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010070 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
10071 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +120010072
10073 ASSERT_NO_FATAL_FAILURE(InitState());
10074 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10075
10076 BeginCommandBuffer();
10077
10078 // error here.
10079 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
10080 m_errorMonitor->VerifyFound();
10081
10082 EndCommandBuffer();
10083}
10084
Chris Forbes6d624702016-09-07 13:57:05 +120010085TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
10086 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
10087 "called before the final subpass has been reached");
10088
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
10090 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +120010091
10092 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010093 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
10094 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +120010095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010096 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +120010097
10098 VkRenderPass rp;
10099 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
10100 ASSERT_VK_SUCCESS(err);
10101
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010102 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +120010103
10104 VkFramebuffer fb;
10105 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
10106 ASSERT_VK_SUCCESS(err);
10107
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010108 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +120010109
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010110 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 +120010111
10112 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10113
10114 // Error here.
10115 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10116 m_errorMonitor->VerifyFound();
10117
10118 // Clean up.
10119 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
10120 vkDestroyRenderPass(m_device->device(), rp, nullptr);
10121}
10122
Karl Schultz9e66a292016-04-21 15:57:51 -060010123TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
10124 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10126 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -060010127
10128 ASSERT_NO_FATAL_FAILURE(InitState());
10129 BeginCommandBuffer();
10130
10131 VkBufferMemoryBarrier buf_barrier = {};
10132 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10133 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10134 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10135 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10136 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10137 buf_barrier.buffer = VK_NULL_HANDLE;
10138 buf_barrier.offset = 0;
10139 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010140 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10141 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -060010142
10143 m_errorMonitor->VerifyFound();
10144}
10145
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010146TEST_F(VkLayerTest, InvalidBarriers) {
10147 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
10148
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010150
10151 ASSERT_NO_FATAL_FAILURE(InitState());
10152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10153
10154 VkMemoryBarrier mem_barrier = {};
10155 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
10156 mem_barrier.pNext = NULL;
10157 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10158 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10159 BeginCommandBuffer();
10160 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010161 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010162 &mem_barrier, 0, nullptr, 0, nullptr);
10163 m_errorMonitor->VerifyFound();
10164
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010166 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010167 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 -060010168 ASSERT_TRUE(image.initialized());
10169 VkImageMemoryBarrier img_barrier = {};
10170 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10171 img_barrier.pNext = NULL;
10172 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10173 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10174 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10175 // New layout can't be UNDEFINED
10176 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10177 img_barrier.image = image.handle();
10178 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10179 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10180 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10181 img_barrier.subresourceRange.baseArrayLayer = 0;
10182 img_barrier.subresourceRange.baseMipLevel = 0;
10183 img_barrier.subresourceRange.layerCount = 1;
10184 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010185 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10186 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010187 m_errorMonitor->VerifyFound();
10188 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10189
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
10191 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010192 // baseArrayLayer + layerCount must be <= image's arrayLayers
10193 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010194 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10195 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010196 m_errorMonitor->VerifyFound();
10197 img_barrier.subresourceRange.baseArrayLayer = 0;
10198
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010200 // baseMipLevel + levelCount must be <= image's mipLevels
10201 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010202 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10203 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010204 m_errorMonitor->VerifyFound();
10205 img_barrier.subresourceRange.baseMipLevel = 0;
10206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010207 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 -060010208 vk_testing::Buffer buffer;
10209 buffer.init(*m_device, 256);
10210 VkBufferMemoryBarrier buf_barrier = {};
10211 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10212 buf_barrier.pNext = NULL;
10213 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10214 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10215 buf_barrier.buffer = buffer.handle();
10216 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10217 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10218 buf_barrier.offset = 0;
10219 buf_barrier.size = VK_WHOLE_SIZE;
10220 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010221 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10222 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010223 m_errorMonitor->VerifyFound();
10224 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10225
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010227 buf_barrier.offset = 257;
10228 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010229 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10230 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010231 m_errorMonitor->VerifyFound();
10232 buf_barrier.offset = 0;
10233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010235 buf_barrier.size = 257;
10236 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010237 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10238 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010239 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010240
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010241 // Now exercise barrier aspect bit errors, first DS
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth and stencil format and thus must "
10243 "have either one or both of VK_IMAGE_ASPECT_DEPTH_BIT and "
10244 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010245 VkDepthStencilObj ds_image(m_device);
10246 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
10247 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -060010248 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
10249 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010250 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010251 // Use of COLOR aspect on DS image is error
10252 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010253 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10254 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010255 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010256 // Now test depth-only
10257 VkFormatProperties format_props;
10258
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010259 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
10260 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
10261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth-only format and thus must "
10262 "have VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010263 VkDepthStencilObj d_image(m_device);
10264 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
10265 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010266 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010267 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010268 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010269 // Use of COLOR aspect on depth image is error
10270 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010271 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10272 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010273 m_errorMonitor->VerifyFound();
10274 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010275 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
10276 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010277 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a stencil-only format and thus must "
10279 "have VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010280 VkDepthStencilObj s_image(m_device);
10281 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
10282 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010283 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010284 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010285 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010286 // Use of COLOR aspect on depth image is error
10287 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010288 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10289 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010290 m_errorMonitor->VerifyFound();
10291 }
10292 // Finally test color
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a color format and thus must "
10294 "have VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010295 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010296 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 -060010297 ASSERT_TRUE(c_image.initialized());
10298 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10299 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10300 img_barrier.image = c_image.handle();
10301 // Set aspect to depth (non-color)
10302 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010303 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10304 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010305 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010306}
10307
Karl Schultz6addd812016-02-02 17:17:23 -070010308TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010309 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010310 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010311
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010313
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010314 ASSERT_NO_FATAL_FAILURE(InitState());
10315 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010316 uint32_t qfi = 0;
10317 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010318 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10319 buffCI.size = 1024;
10320 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10321 buffCI.queueFamilyIndexCount = 1;
10322 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010323
10324 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010325 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010326 ASSERT_VK_SUCCESS(err);
10327
10328 BeginCommandBuffer();
10329 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -070010330 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10331 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010332 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010333 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010334
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010335 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010336
Chia-I Wuf7458c52015-10-26 21:10:41 +080010337 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010338}
10339
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010340TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10341 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10343 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
10344 "of the indices specified when the device was created, via the "
10345 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010346
10347 ASSERT_NO_FATAL_FAILURE(InitState());
10348 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10349 VkBufferCreateInfo buffCI = {};
10350 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10351 buffCI.size = 1024;
10352 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10353 buffCI.queueFamilyIndexCount = 1;
10354 // Introduce failure by specifying invalid queue_family_index
10355 uint32_t qfi = 777;
10356 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -060010357 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010358
10359 VkBuffer ib;
10360 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
10361
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010362 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060010363 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010364}
10365
Karl Schultz6addd812016-02-02 17:17:23 -070010366TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010367 TEST_DESCRIPTION("Attempt vkCmdExecuteCommands w/ a primary cmd buffer"
10368 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010369
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010371
10372 ASSERT_NO_FATAL_FAILURE(InitState());
10373 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010374
10375 BeginCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010376
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010377 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
10378 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010379
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010380 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010381}
10382
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010383TEST_F(VkLayerTest, DSUsageBitsErrors) {
10384 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
10385 "that do not have correct usage bits sets.");
10386 VkResult err;
10387
10388 ASSERT_NO_FATAL_FAILURE(InitState());
10389 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10390 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10391 ds_type_count[i].type = VkDescriptorType(i);
10392 ds_type_count[i].descriptorCount = 1;
10393 }
10394 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10395 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10396 ds_pool_ci.pNext = NULL;
10397 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10398 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10399 ds_pool_ci.pPoolSizes = ds_type_count;
10400
10401 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010402 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010403 ASSERT_VK_SUCCESS(err);
10404
10405 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010406 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010407 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10408 dsl_binding[i].binding = 0;
10409 dsl_binding[i].descriptorType = VkDescriptorType(i);
10410 dsl_binding[i].descriptorCount = 1;
10411 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10412 dsl_binding[i].pImmutableSamplers = NULL;
10413 }
10414
10415 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10416 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10417 ds_layout_ci.pNext = NULL;
10418 ds_layout_ci.bindingCount = 1;
10419 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10420 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10421 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010422 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010423 ASSERT_VK_SUCCESS(err);
10424 }
10425 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10426 VkDescriptorSetAllocateInfo alloc_info = {};
10427 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10428 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10429 alloc_info.descriptorPool = ds_pool;
10430 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010431 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010432 ASSERT_VK_SUCCESS(err);
10433
10434 // Create a buffer & bufferView to be used for invalid updates
10435 VkBufferCreateInfo buff_ci = {};
10436 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10437 // This usage is not valid for any descriptor type
10438 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
10439 buff_ci.size = 256;
10440 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10441 VkBuffer buffer;
10442 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10443 ASSERT_VK_SUCCESS(err);
10444
10445 VkBufferViewCreateInfo buff_view_ci = {};
10446 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10447 buff_view_ci.buffer = buffer;
10448 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10449 buff_view_ci.range = VK_WHOLE_SIZE;
10450 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010451 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010452 ASSERT_VK_SUCCESS(err);
10453
10454 // Create an image to be used for invalid updates
10455 VkImageCreateInfo image_ci = {};
10456 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10457 image_ci.imageType = VK_IMAGE_TYPE_2D;
10458 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10459 image_ci.extent.width = 64;
10460 image_ci.extent.height = 64;
10461 image_ci.extent.depth = 1;
10462 image_ci.mipLevels = 1;
10463 image_ci.arrayLayers = 1;
10464 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10465 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10466 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10467 // This usage is not valid for any descriptor type
10468 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10469 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10470 VkImage image;
10471 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10472 ASSERT_VK_SUCCESS(err);
10473 // Bind memory to image
10474 VkMemoryRequirements mem_reqs;
10475 VkDeviceMemory image_mem;
10476 bool pass;
10477 VkMemoryAllocateInfo mem_alloc = {};
10478 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10479 mem_alloc.pNext = NULL;
10480 mem_alloc.allocationSize = 0;
10481 mem_alloc.memoryTypeIndex = 0;
10482 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10483 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010484 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010485 ASSERT_TRUE(pass);
10486 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10487 ASSERT_VK_SUCCESS(err);
10488 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10489 ASSERT_VK_SUCCESS(err);
10490 // Now create view for image
10491 VkImageViewCreateInfo image_view_ci = {};
10492 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10493 image_view_ci.image = image;
10494 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10495 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10496 image_view_ci.subresourceRange.layerCount = 1;
10497 image_view_ci.subresourceRange.baseArrayLayer = 0;
10498 image_view_ci.subresourceRange.levelCount = 1;
10499 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10500 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010501 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010502 ASSERT_VK_SUCCESS(err);
10503
10504 VkDescriptorBufferInfo buff_info = {};
10505 buff_info.buffer = buffer;
10506 VkDescriptorImageInfo img_info = {};
10507 img_info.imageView = image_view;
10508 VkWriteDescriptorSet descriptor_write = {};
10509 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10510 descriptor_write.dstBinding = 0;
10511 descriptor_write.descriptorCount = 1;
10512 descriptor_write.pTexelBufferView = &buff_view;
10513 descriptor_write.pBufferInfo = &buff_info;
10514 descriptor_write.pImageInfo = &img_info;
10515
10516 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010517 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
10518 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10519 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10520 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
10521 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
10522 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
10523 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10524 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10525 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10526 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10527 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010528 // Start loop at 1 as SAMPLER desc type has no usage bit error
10529 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10530 descriptor_write.descriptorType = VkDescriptorType(i);
10531 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010533
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010534 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010535
10536 m_errorMonitor->VerifyFound();
10537 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
10538 }
10539 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10540 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010541 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010542 vkDestroyImageView(m_device->device(), image_view, NULL);
10543 vkDestroyBuffer(m_device->device(), buffer, NULL);
10544 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010545 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010546 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10547}
10548
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010549TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010550 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
10551 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
10552 "1. offset value greater than buffer size\n"
10553 "2. range value of 0\n"
10554 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010555 VkResult err;
10556
10557 ASSERT_NO_FATAL_FAILURE(InitState());
10558 VkDescriptorPoolSize ds_type_count = {};
10559 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10560 ds_type_count.descriptorCount = 1;
10561
10562 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10563 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10564 ds_pool_ci.pNext = NULL;
10565 ds_pool_ci.maxSets = 1;
10566 ds_pool_ci.poolSizeCount = 1;
10567 ds_pool_ci.pPoolSizes = &ds_type_count;
10568
10569 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010570 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010571 ASSERT_VK_SUCCESS(err);
10572
10573 // Create layout with single uniform buffer descriptor
10574 VkDescriptorSetLayoutBinding dsl_binding = {};
10575 dsl_binding.binding = 0;
10576 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10577 dsl_binding.descriptorCount = 1;
10578 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10579 dsl_binding.pImmutableSamplers = NULL;
10580
10581 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10582 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10583 ds_layout_ci.pNext = NULL;
10584 ds_layout_ci.bindingCount = 1;
10585 ds_layout_ci.pBindings = &dsl_binding;
10586 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010587 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010588 ASSERT_VK_SUCCESS(err);
10589
10590 VkDescriptorSet descriptor_set = {};
10591 VkDescriptorSetAllocateInfo alloc_info = {};
10592 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10593 alloc_info.descriptorSetCount = 1;
10594 alloc_info.descriptorPool = ds_pool;
10595 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010596 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010597 ASSERT_VK_SUCCESS(err);
10598
10599 // Create a buffer to be used for invalid updates
10600 VkBufferCreateInfo buff_ci = {};
10601 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10602 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10603 buff_ci.size = 256;
10604 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10605 VkBuffer buffer;
10606 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10607 ASSERT_VK_SUCCESS(err);
10608 // Have to bind memory to buffer before descriptor update
10609 VkMemoryAllocateInfo mem_alloc = {};
10610 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10611 mem_alloc.pNext = NULL;
10612 mem_alloc.allocationSize = 256;
10613 mem_alloc.memoryTypeIndex = 0;
10614
10615 VkMemoryRequirements mem_reqs;
10616 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010617 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010618 if (!pass) {
10619 vkDestroyBuffer(m_device->device(), buffer, NULL);
10620 return;
10621 }
10622
10623 VkDeviceMemory mem;
10624 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10625 ASSERT_VK_SUCCESS(err);
10626 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10627 ASSERT_VK_SUCCESS(err);
10628
10629 VkDescriptorBufferInfo buff_info = {};
10630 buff_info.buffer = buffer;
10631 // First make offset 1 larger than buffer size
10632 buff_info.offset = 257;
10633 buff_info.range = VK_WHOLE_SIZE;
10634 VkWriteDescriptorSet descriptor_write = {};
10635 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10636 descriptor_write.dstBinding = 0;
10637 descriptor_write.descriptorCount = 1;
10638 descriptor_write.pTexelBufferView = nullptr;
10639 descriptor_write.pBufferInfo = &buff_info;
10640 descriptor_write.pImageInfo = nullptr;
10641
10642 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10643 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010645
10646 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10647
10648 m_errorMonitor->VerifyFound();
10649 // Now cause error due to range of 0
10650 buff_info.offset = 0;
10651 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10653 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010654
10655 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10656
10657 m_errorMonitor->VerifyFound();
10658 // Now cause error due to range exceeding buffer size - offset
10659 buff_info.offset = 128;
10660 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010661 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 -060010662
10663 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10664
10665 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010666 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010667 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10668 vkDestroyBuffer(m_device->device(), buffer, NULL);
10669 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10670 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10671}
10672
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010673TEST_F(VkLayerTest, DSAspectBitsErrors) {
10674 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10675 // are set, but could expand this test to hit more cases.
10676 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
10677 "that do not have correct aspect bits sets.");
10678 VkResult err;
10679
10680 ASSERT_NO_FATAL_FAILURE(InitState());
10681 VkDescriptorPoolSize ds_type_count = {};
10682 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10683 ds_type_count.descriptorCount = 1;
10684
10685 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10686 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10687 ds_pool_ci.pNext = NULL;
10688 ds_pool_ci.maxSets = 5;
10689 ds_pool_ci.poolSizeCount = 1;
10690 ds_pool_ci.pPoolSizes = &ds_type_count;
10691
10692 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010693 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010694 ASSERT_VK_SUCCESS(err);
10695
10696 VkDescriptorSetLayoutBinding dsl_binding = {};
10697 dsl_binding.binding = 0;
10698 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10699 dsl_binding.descriptorCount = 1;
10700 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10701 dsl_binding.pImmutableSamplers = NULL;
10702
10703 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10704 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10705 ds_layout_ci.pNext = NULL;
10706 ds_layout_ci.bindingCount = 1;
10707 ds_layout_ci.pBindings = &dsl_binding;
10708 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010709 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010710 ASSERT_VK_SUCCESS(err);
10711
10712 VkDescriptorSet descriptor_set = {};
10713 VkDescriptorSetAllocateInfo alloc_info = {};
10714 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10715 alloc_info.descriptorSetCount = 1;
10716 alloc_info.descriptorPool = ds_pool;
10717 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010718 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010719 ASSERT_VK_SUCCESS(err);
10720
10721 // Create an image to be used for invalid updates
10722 VkImageCreateInfo image_ci = {};
10723 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10724 image_ci.imageType = VK_IMAGE_TYPE_2D;
10725 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10726 image_ci.extent.width = 64;
10727 image_ci.extent.height = 64;
10728 image_ci.extent.depth = 1;
10729 image_ci.mipLevels = 1;
10730 image_ci.arrayLayers = 1;
10731 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10732 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10733 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10734 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10735 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10736 VkImage image;
10737 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10738 ASSERT_VK_SUCCESS(err);
10739 // Bind memory to image
10740 VkMemoryRequirements mem_reqs;
10741 VkDeviceMemory image_mem;
10742 bool pass;
10743 VkMemoryAllocateInfo mem_alloc = {};
10744 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10745 mem_alloc.pNext = NULL;
10746 mem_alloc.allocationSize = 0;
10747 mem_alloc.memoryTypeIndex = 0;
10748 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10749 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010750 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010751 ASSERT_TRUE(pass);
10752 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10753 ASSERT_VK_SUCCESS(err);
10754 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10755 ASSERT_VK_SUCCESS(err);
10756 // Now create view for image
10757 VkImageViewCreateInfo image_view_ci = {};
10758 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10759 image_view_ci.image = image;
10760 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10761 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10762 image_view_ci.subresourceRange.layerCount = 1;
10763 image_view_ci.subresourceRange.baseArrayLayer = 0;
10764 image_view_ci.subresourceRange.levelCount = 1;
10765 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010766 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010767
10768 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010769 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010770 ASSERT_VK_SUCCESS(err);
10771
10772 VkDescriptorImageInfo img_info = {};
10773 img_info.imageView = image_view;
10774 VkWriteDescriptorSet descriptor_write = {};
10775 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10776 descriptor_write.dstBinding = 0;
10777 descriptor_write.descriptorCount = 1;
10778 descriptor_write.pTexelBufferView = NULL;
10779 descriptor_write.pBufferInfo = NULL;
10780 descriptor_write.pImageInfo = &img_info;
10781 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10782 descriptor_write.dstSet = descriptor_set;
10783 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10784 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010786
10787 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10788
10789 m_errorMonitor->VerifyFound();
10790 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10791 vkDestroyImage(m_device->device(), image, NULL);
10792 vkFreeMemory(m_device->device(), image_mem, NULL);
10793 vkDestroyImageView(m_device->device(), image_view, NULL);
10794 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10795 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10796}
10797
Karl Schultz6addd812016-02-02 17:17:23 -070010798TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010799 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010800 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010801
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10803 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10804 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010805
Tobin Ehlis3b780662015-05-28 12:11:26 -060010806 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010807 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010808 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010809 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10810 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010811
10812 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010813 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10814 ds_pool_ci.pNext = NULL;
10815 ds_pool_ci.maxSets = 1;
10816 ds_pool_ci.poolSizeCount = 1;
10817 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010818
Tobin Ehlis3b780662015-05-28 12:11:26 -060010819 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010820 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010821 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010822 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010823 dsl_binding.binding = 0;
10824 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10825 dsl_binding.descriptorCount = 1;
10826 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10827 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010828
Tony Barboureb254902015-07-15 12:50:33 -060010829 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010830 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10831 ds_layout_ci.pNext = NULL;
10832 ds_layout_ci.bindingCount = 1;
10833 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010834
Tobin Ehlis3b780662015-05-28 12:11:26 -060010835 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010836 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010837 ASSERT_VK_SUCCESS(err);
10838
10839 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010840 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010841 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010842 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010843 alloc_info.descriptorPool = ds_pool;
10844 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010845 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010846 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010847
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010848 VkSamplerCreateInfo sampler_ci = {};
10849 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10850 sampler_ci.pNext = NULL;
10851 sampler_ci.magFilter = VK_FILTER_NEAREST;
10852 sampler_ci.minFilter = VK_FILTER_NEAREST;
10853 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10854 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10855 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10856 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10857 sampler_ci.mipLodBias = 1.0;
10858 sampler_ci.anisotropyEnable = VK_FALSE;
10859 sampler_ci.maxAnisotropy = 1;
10860 sampler_ci.compareEnable = VK_FALSE;
10861 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10862 sampler_ci.minLod = 1.0;
10863 sampler_ci.maxLod = 1.0;
10864 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10865 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10866 VkSampler sampler;
10867 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10868 ASSERT_VK_SUCCESS(err);
10869
10870 VkDescriptorImageInfo info = {};
10871 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010872
10873 VkWriteDescriptorSet descriptor_write;
10874 memset(&descriptor_write, 0, sizeof(descriptor_write));
10875 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010876 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010877 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010878 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010879 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010880 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010881
10882 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10883
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010884 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010885
Chia-I Wuf7458c52015-10-26 21:10:41 +080010886 vkDestroySampler(m_device->device(), sampler, NULL);
10887 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10888 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010889}
10890
Karl Schultz6addd812016-02-02 17:17:23 -070010891TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010892 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010893 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010894
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10896 " binding #0 with 1 total descriptors but update of 1 descriptors "
10897 "starting at binding offset of 0 combined with update array element "
10898 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010899
Tobin Ehlis3b780662015-05-28 12:11:26 -060010900 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010901 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010902 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010903 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10904 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010905
10906 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010907 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10908 ds_pool_ci.pNext = NULL;
10909 ds_pool_ci.maxSets = 1;
10910 ds_pool_ci.poolSizeCount = 1;
10911 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010912
Tobin Ehlis3b780662015-05-28 12:11:26 -060010913 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010914 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010915 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010916
Tony Barboureb254902015-07-15 12:50:33 -060010917 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010918 dsl_binding.binding = 0;
10919 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10920 dsl_binding.descriptorCount = 1;
10921 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10922 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010923
10924 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010925 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10926 ds_layout_ci.pNext = NULL;
10927 ds_layout_ci.bindingCount = 1;
10928 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010929
Tobin Ehlis3b780662015-05-28 12:11:26 -060010930 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010931 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010932 ASSERT_VK_SUCCESS(err);
10933
10934 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010935 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010936 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010937 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010938 alloc_info.descriptorPool = ds_pool;
10939 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010940 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010941 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010942
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010943 // Correctly update descriptor to avoid "NOT_UPDATED" error
10944 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010945 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010946 buff_info.offset = 0;
10947 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010948
10949 VkWriteDescriptorSet descriptor_write;
10950 memset(&descriptor_write, 0, sizeof(descriptor_write));
10951 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010952 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010953 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010954 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010955 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10956 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010957
10958 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10959
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010960 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010961
Chia-I Wuf7458c52015-10-26 21:10:41 +080010962 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10963 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010964}
10965
Karl Schultz6addd812016-02-02 17:17:23 -070010966TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
10967 // Create layout w/ count of 1 and attempt update to that layout w/ binding
10968 // index 2
10969 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010970
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010972
Tobin Ehlis3b780662015-05-28 12:11:26 -060010973 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010974 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010975 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010976 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10977 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010978
10979 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010980 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10981 ds_pool_ci.pNext = NULL;
10982 ds_pool_ci.maxSets = 1;
10983 ds_pool_ci.poolSizeCount = 1;
10984 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010985
Tobin Ehlis3b780662015-05-28 12:11:26 -060010986 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010987 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010988 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010989
Tony Barboureb254902015-07-15 12:50:33 -060010990 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010991 dsl_binding.binding = 0;
10992 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10993 dsl_binding.descriptorCount = 1;
10994 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10995 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010996
10997 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010998 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10999 ds_layout_ci.pNext = NULL;
11000 ds_layout_ci.bindingCount = 1;
11001 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011002 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011003 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011004 ASSERT_VK_SUCCESS(err);
11005
11006 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011007 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011008 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011009 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011010 alloc_info.descriptorPool = ds_pool;
11011 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011012 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011013 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011014
Tony Barboureb254902015-07-15 12:50:33 -060011015 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011016 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11017 sampler_ci.pNext = NULL;
11018 sampler_ci.magFilter = VK_FILTER_NEAREST;
11019 sampler_ci.minFilter = VK_FILTER_NEAREST;
11020 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11021 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11022 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11023 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11024 sampler_ci.mipLodBias = 1.0;
11025 sampler_ci.anisotropyEnable = VK_FALSE;
11026 sampler_ci.maxAnisotropy = 1;
11027 sampler_ci.compareEnable = VK_FALSE;
11028 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11029 sampler_ci.minLod = 1.0;
11030 sampler_ci.maxLod = 1.0;
11031 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11032 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011033
Tobin Ehlis3b780662015-05-28 12:11:26 -060011034 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011035 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011036 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011037
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011038 VkDescriptorImageInfo info = {};
11039 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011040
11041 VkWriteDescriptorSet descriptor_write;
11042 memset(&descriptor_write, 0, sizeof(descriptor_write));
11043 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011044 descriptor_write.dstSet = descriptorSet;
11045 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011046 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011047 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011048 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011049 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011050
11051 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11052
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011053 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011054
Chia-I Wuf7458c52015-10-26 21:10:41 +080011055 vkDestroySampler(m_device->device(), sampler, NULL);
11056 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11057 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011058}
11059
Karl Schultz6addd812016-02-02 17:17:23 -070011060TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11061 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11062 // types
11063 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011064
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011065 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 -060011066
Tobin Ehlis3b780662015-05-28 12:11:26 -060011067 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011068
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011069 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011070 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11071 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011072
11073 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011074 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11075 ds_pool_ci.pNext = NULL;
11076 ds_pool_ci.maxSets = 1;
11077 ds_pool_ci.poolSizeCount = 1;
11078 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011079
Tobin Ehlis3b780662015-05-28 12:11:26 -060011080 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011081 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011082 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011083 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011084 dsl_binding.binding = 0;
11085 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11086 dsl_binding.descriptorCount = 1;
11087 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11088 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011089
Tony Barboureb254902015-07-15 12:50:33 -060011090 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011091 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11092 ds_layout_ci.pNext = NULL;
11093 ds_layout_ci.bindingCount = 1;
11094 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011095
Tobin Ehlis3b780662015-05-28 12:11:26 -060011096 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011097 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011098 ASSERT_VK_SUCCESS(err);
11099
11100 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011101 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011102 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011103 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011104 alloc_info.descriptorPool = ds_pool;
11105 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011106 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011107 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011108
Tony Barboureb254902015-07-15 12:50:33 -060011109 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011110 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11111 sampler_ci.pNext = NULL;
11112 sampler_ci.magFilter = VK_FILTER_NEAREST;
11113 sampler_ci.minFilter = VK_FILTER_NEAREST;
11114 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11115 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11116 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11117 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11118 sampler_ci.mipLodBias = 1.0;
11119 sampler_ci.anisotropyEnable = VK_FALSE;
11120 sampler_ci.maxAnisotropy = 1;
11121 sampler_ci.compareEnable = VK_FALSE;
11122 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11123 sampler_ci.minLod = 1.0;
11124 sampler_ci.maxLod = 1.0;
11125 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11126 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011127 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011128 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011129 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011130
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011131 VkDescriptorImageInfo info = {};
11132 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011133
11134 VkWriteDescriptorSet descriptor_write;
11135 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011136 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011137 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011138 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011139 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011140 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011141 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011142
11143 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11144
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011145 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011146
Chia-I Wuf7458c52015-10-26 21:10:41 +080011147 vkDestroySampler(m_device->device(), sampler, NULL);
11148 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11149 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011150}
11151
Karl Schultz6addd812016-02-02 17:17:23 -070011152TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011153 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011154 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011155
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11157 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011158
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011159 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011160 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11161 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011162 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011163 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11164 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011165
11166 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011167 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11168 ds_pool_ci.pNext = NULL;
11169 ds_pool_ci.maxSets = 1;
11170 ds_pool_ci.poolSizeCount = 1;
11171 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011172
11173 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011174 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011175 ASSERT_VK_SUCCESS(err);
11176
11177 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011178 dsl_binding.binding = 0;
11179 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11180 dsl_binding.descriptorCount = 1;
11181 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11182 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011183
11184 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011185 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11186 ds_layout_ci.pNext = NULL;
11187 ds_layout_ci.bindingCount = 1;
11188 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011189 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011190 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011191 ASSERT_VK_SUCCESS(err);
11192
11193 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011194 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011195 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011196 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011197 alloc_info.descriptorPool = ds_pool;
11198 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011199 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011200 ASSERT_VK_SUCCESS(err);
11201
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011202 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011203
11204 VkDescriptorImageInfo descriptor_info;
11205 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11206 descriptor_info.sampler = sampler;
11207
11208 VkWriteDescriptorSet descriptor_write;
11209 memset(&descriptor_write, 0, sizeof(descriptor_write));
11210 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011211 descriptor_write.dstSet = descriptorSet;
11212 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011213 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011214 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11215 descriptor_write.pImageInfo = &descriptor_info;
11216
11217 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11218
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011219 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011220
Chia-I Wuf7458c52015-10-26 21:10:41 +080011221 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11222 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011223}
11224
Karl Schultz6addd812016-02-02 17:17:23 -070011225TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11226 // Create a single combined Image/Sampler descriptor and send it an invalid
11227 // imageView
11228 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011229
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
11231 "image sampler descriptor failed due "
11232 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011233
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011234 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011235 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011236 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11237 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011238
11239 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011240 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11241 ds_pool_ci.pNext = NULL;
11242 ds_pool_ci.maxSets = 1;
11243 ds_pool_ci.poolSizeCount = 1;
11244 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011245
11246 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011247 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011248 ASSERT_VK_SUCCESS(err);
11249
11250 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011251 dsl_binding.binding = 0;
11252 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11253 dsl_binding.descriptorCount = 1;
11254 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11255 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011256
11257 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011258 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11259 ds_layout_ci.pNext = NULL;
11260 ds_layout_ci.bindingCount = 1;
11261 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011262 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011263 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011264 ASSERT_VK_SUCCESS(err);
11265
11266 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011267 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011268 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011269 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011270 alloc_info.descriptorPool = ds_pool;
11271 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011272 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011273 ASSERT_VK_SUCCESS(err);
11274
11275 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011276 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11277 sampler_ci.pNext = NULL;
11278 sampler_ci.magFilter = VK_FILTER_NEAREST;
11279 sampler_ci.minFilter = VK_FILTER_NEAREST;
11280 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11281 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11282 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11283 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11284 sampler_ci.mipLodBias = 1.0;
11285 sampler_ci.anisotropyEnable = VK_FALSE;
11286 sampler_ci.maxAnisotropy = 1;
11287 sampler_ci.compareEnable = VK_FALSE;
11288 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11289 sampler_ci.minLod = 1.0;
11290 sampler_ci.maxLod = 1.0;
11291 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11292 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011293
11294 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011295 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011296 ASSERT_VK_SUCCESS(err);
11297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011298 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011299
11300 VkDescriptorImageInfo descriptor_info;
11301 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11302 descriptor_info.sampler = sampler;
11303 descriptor_info.imageView = view;
11304
11305 VkWriteDescriptorSet descriptor_write;
11306 memset(&descriptor_write, 0, sizeof(descriptor_write));
11307 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011308 descriptor_write.dstSet = descriptorSet;
11309 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011310 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011311 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11312 descriptor_write.pImageInfo = &descriptor_info;
11313
11314 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11315
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011316 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011317
Chia-I Wuf7458c52015-10-26 21:10:41 +080011318 vkDestroySampler(m_device->device(), sampler, NULL);
11319 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11320 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011321}
11322
Karl Schultz6addd812016-02-02 17:17:23 -070011323TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11324 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11325 // into the other
11326 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
11329 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11330 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011331
Tobin Ehlis04356f92015-10-27 16:35:27 -060011332 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011333 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011334 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011335 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11336 ds_type_count[0].descriptorCount = 1;
11337 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11338 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011339
11340 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011341 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11342 ds_pool_ci.pNext = NULL;
11343 ds_pool_ci.maxSets = 1;
11344 ds_pool_ci.poolSizeCount = 2;
11345 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011346
11347 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011348 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011349 ASSERT_VK_SUCCESS(err);
11350 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011351 dsl_binding[0].binding = 0;
11352 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11353 dsl_binding[0].descriptorCount = 1;
11354 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11355 dsl_binding[0].pImmutableSamplers = NULL;
11356 dsl_binding[1].binding = 1;
11357 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11358 dsl_binding[1].descriptorCount = 1;
11359 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11360 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011361
11362 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011363 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11364 ds_layout_ci.pNext = NULL;
11365 ds_layout_ci.bindingCount = 2;
11366 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011367
11368 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011369 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011370 ASSERT_VK_SUCCESS(err);
11371
11372 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011373 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011374 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011375 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011376 alloc_info.descriptorPool = ds_pool;
11377 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011378 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011379 ASSERT_VK_SUCCESS(err);
11380
11381 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011382 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11383 sampler_ci.pNext = NULL;
11384 sampler_ci.magFilter = VK_FILTER_NEAREST;
11385 sampler_ci.minFilter = VK_FILTER_NEAREST;
11386 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11387 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11388 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11389 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11390 sampler_ci.mipLodBias = 1.0;
11391 sampler_ci.anisotropyEnable = VK_FALSE;
11392 sampler_ci.maxAnisotropy = 1;
11393 sampler_ci.compareEnable = VK_FALSE;
11394 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11395 sampler_ci.minLod = 1.0;
11396 sampler_ci.maxLod = 1.0;
11397 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11398 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011399
11400 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011401 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011402 ASSERT_VK_SUCCESS(err);
11403
11404 VkDescriptorImageInfo info = {};
11405 info.sampler = sampler;
11406
11407 VkWriteDescriptorSet descriptor_write;
11408 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11409 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011410 descriptor_write.dstSet = descriptorSet;
11411 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011412 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011413 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11414 descriptor_write.pImageInfo = &info;
11415 // This write update should succeed
11416 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11417 // Now perform a copy update that fails due to type mismatch
11418 VkCopyDescriptorSet copy_ds_update;
11419 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11420 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11421 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -060011422 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011423 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -070011424 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +080011425 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011426 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11427
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011428 m_errorMonitor->VerifyFound();
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, " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -060011431 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11432 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11433 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011434 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011435 copy_ds_update.dstSet = descriptorSet;
11436 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -060011437 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011438 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11439
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011440 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011441
Tobin Ehlis04356f92015-10-27 16:35:27 -060011442 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
11444 "update array offset of 0 and update of "
11445 "5 descriptors oversteps total number "
11446 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011447
Tobin Ehlis04356f92015-10-27 16:35:27 -060011448 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11449 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11450 copy_ds_update.srcSet = descriptorSet;
11451 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011452 copy_ds_update.dstSet = descriptorSet;
11453 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011454 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011455 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11456
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011457 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011458
Chia-I Wuf7458c52015-10-26 21:10:41 +080011459 vkDestroySampler(m_device->device(), sampler, NULL);
11460 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11461 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011462}
11463
Karl Schultz6addd812016-02-02 17:17:23 -070011464TEST_F(VkLayerTest, NumSamplesMismatch) {
11465 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11466 // sampleCount
11467 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011468
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011470
Tobin Ehlis3b780662015-05-28 12:11:26 -060011471 ASSERT_NO_FATAL_FAILURE(InitState());
11472 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011473 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011474 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011475 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011476
11477 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011478 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11479 ds_pool_ci.pNext = NULL;
11480 ds_pool_ci.maxSets = 1;
11481 ds_pool_ci.poolSizeCount = 1;
11482 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011483
Tobin Ehlis3b780662015-05-28 12:11:26 -060011484 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011485 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011486 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011487
Tony Barboureb254902015-07-15 12:50:33 -060011488 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011489 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011490 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011491 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011492 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11493 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011494
Tony Barboureb254902015-07-15 12:50:33 -060011495 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11496 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11497 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011498 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011499 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011500
Tobin Ehlis3b780662015-05-28 12:11:26 -060011501 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011502 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011503 ASSERT_VK_SUCCESS(err);
11504
11505 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011506 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011507 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011508 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011509 alloc_info.descriptorPool = ds_pool;
11510 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011511 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011512 ASSERT_VK_SUCCESS(err);
11513
Tony Barboureb254902015-07-15 12:50:33 -060011514 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011515 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011516 pipe_ms_state_ci.pNext = NULL;
11517 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11518 pipe_ms_state_ci.sampleShadingEnable = 0;
11519 pipe_ms_state_ci.minSampleShading = 1.0;
11520 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011521
Tony Barboureb254902015-07-15 12:50:33 -060011522 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011523 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11524 pipeline_layout_ci.pNext = NULL;
11525 pipeline_layout_ci.setLayoutCount = 1;
11526 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011527
11528 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011529 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011530 ASSERT_VK_SUCCESS(err);
11531
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011532 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11533 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11534 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011535 VkPipelineObj pipe(m_device);
11536 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011537 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011538 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011539 pipe.SetMSAA(&pipe_ms_state_ci);
11540 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011541
Tony Barbourfe3351b2015-07-28 10:17:20 -060011542 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011543 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011544
Mark Young29927482016-05-04 14:38:51 -060011545 // Render triangle (the error should trigger on the attempt to draw).
11546 Draw(3, 1, 0, 0);
11547
11548 // Finalize recording of the command buffer
11549 EndCommandBuffer();
11550
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011551 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011552
Chia-I Wuf7458c52015-10-26 21:10:41 +080011553 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11554 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11555 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011556}
Mark Young29927482016-05-04 14:38:51 -060011557
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011558TEST_F(VkLayerTest, RenderPassIncompatible) {
11559 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
11560 "Initial case is drawing with an active renderpass that's "
11561 "not compatible with the bound PSO's creation renderpass");
11562 VkResult err;
11563
11564 ASSERT_NO_FATAL_FAILURE(InitState());
11565 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11566
11567 VkDescriptorSetLayoutBinding dsl_binding = {};
11568 dsl_binding.binding = 0;
11569 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11570 dsl_binding.descriptorCount = 1;
11571 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11572 dsl_binding.pImmutableSamplers = NULL;
11573
11574 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11575 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11576 ds_layout_ci.pNext = NULL;
11577 ds_layout_ci.bindingCount = 1;
11578 ds_layout_ci.pBindings = &dsl_binding;
11579
11580 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011581 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011582 ASSERT_VK_SUCCESS(err);
11583
11584 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11585 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11586 pipeline_layout_ci.pNext = NULL;
11587 pipeline_layout_ci.setLayoutCount = 1;
11588 pipeline_layout_ci.pSetLayouts = &ds_layout;
11589
11590 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011591 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011592 ASSERT_VK_SUCCESS(err);
11593
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011594 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11595 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11596 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011597 // Create a renderpass that will be incompatible with default renderpass
11598 VkAttachmentReference attach = {};
11599 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11600 VkAttachmentReference color_att = {};
11601 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11602 VkSubpassDescription subpass = {};
11603 subpass.inputAttachmentCount = 1;
11604 subpass.pInputAttachments = &attach;
11605 subpass.colorAttachmentCount = 1;
11606 subpass.pColorAttachments = &color_att;
11607 VkRenderPassCreateInfo rpci = {};
11608 rpci.subpassCount = 1;
11609 rpci.pSubpasses = &subpass;
11610 rpci.attachmentCount = 1;
11611 VkAttachmentDescription attach_desc = {};
11612 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011613 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11614 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011615 rpci.pAttachments = &attach_desc;
11616 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11617 VkRenderPass rp;
11618 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11619 VkPipelineObj pipe(m_device);
11620 pipe.AddShader(&vs);
11621 pipe.AddShader(&fs);
11622 pipe.AddColorAttachment();
11623 VkViewport view_port = {};
11624 m_viewports.push_back(view_port);
11625 pipe.SetViewport(m_viewports);
11626 VkRect2D rect = {};
11627 m_scissors.push_back(rect);
11628 pipe.SetScissor(m_scissors);
11629 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11630
11631 VkCommandBufferInheritanceInfo cbii = {};
11632 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11633 cbii.renderPass = rp;
11634 cbii.subpass = 0;
11635 VkCommandBufferBeginInfo cbbi = {};
11636 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11637 cbbi.pInheritanceInfo = &cbii;
11638 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11639 VkRenderPassBeginInfo rpbi = {};
11640 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11641 rpbi.framebuffer = m_framebuffer;
11642 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011643 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11644 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011645
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011647 // Render triangle (the error should trigger on the attempt to draw).
11648 Draw(3, 1, 0, 0);
11649
11650 // Finalize recording of the command buffer
11651 EndCommandBuffer();
11652
11653 m_errorMonitor->VerifyFound();
11654
11655 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11656 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11657 vkDestroyRenderPass(m_device->device(), rp, NULL);
11658}
11659
Mark Youngc89c6312016-03-31 16:03:20 -060011660TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11661 // Create Pipeline where the number of blend attachments doesn't match the
11662 // number of color attachments. In this case, we don't add any color
11663 // blend attachments even though we have a color attachment.
11664 VkResult err;
11665
11666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011667 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060011668
11669 ASSERT_NO_FATAL_FAILURE(InitState());
11670 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11671 VkDescriptorPoolSize ds_type_count = {};
11672 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11673 ds_type_count.descriptorCount = 1;
11674
11675 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11676 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11677 ds_pool_ci.pNext = NULL;
11678 ds_pool_ci.maxSets = 1;
11679 ds_pool_ci.poolSizeCount = 1;
11680 ds_pool_ci.pPoolSizes = &ds_type_count;
11681
11682 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011683 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011684 ASSERT_VK_SUCCESS(err);
11685
11686 VkDescriptorSetLayoutBinding dsl_binding = {};
11687 dsl_binding.binding = 0;
11688 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11689 dsl_binding.descriptorCount = 1;
11690 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11691 dsl_binding.pImmutableSamplers = NULL;
11692
11693 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11694 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11695 ds_layout_ci.pNext = NULL;
11696 ds_layout_ci.bindingCount = 1;
11697 ds_layout_ci.pBindings = &dsl_binding;
11698
11699 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011700 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011701 ASSERT_VK_SUCCESS(err);
11702
11703 VkDescriptorSet descriptorSet;
11704 VkDescriptorSetAllocateInfo alloc_info = {};
11705 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11706 alloc_info.descriptorSetCount = 1;
11707 alloc_info.descriptorPool = ds_pool;
11708 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011709 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011710 ASSERT_VK_SUCCESS(err);
11711
11712 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011713 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011714 pipe_ms_state_ci.pNext = NULL;
11715 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11716 pipe_ms_state_ci.sampleShadingEnable = 0;
11717 pipe_ms_state_ci.minSampleShading = 1.0;
11718 pipe_ms_state_ci.pSampleMask = NULL;
11719
11720 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11721 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11722 pipeline_layout_ci.pNext = NULL;
11723 pipeline_layout_ci.setLayoutCount = 1;
11724 pipeline_layout_ci.pSetLayouts = &ds_layout;
11725
11726 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011727 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011728 ASSERT_VK_SUCCESS(err);
11729
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011730 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11731 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11732 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011733 VkPipelineObj pipe(m_device);
11734 pipe.AddShader(&vs);
11735 pipe.AddShader(&fs);
11736 pipe.SetMSAA(&pipe_ms_state_ci);
11737 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11738
11739 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011740 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060011741
Mark Young29927482016-05-04 14:38:51 -060011742 // Render triangle (the error should trigger on the attempt to draw).
11743 Draw(3, 1, 0, 0);
11744
11745 // Finalize recording of the command buffer
11746 EndCommandBuffer();
11747
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011748 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011749
11750 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11751 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11752 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11753}
Mark Young29927482016-05-04 14:38:51 -060011754
Mark Muellerd4914412016-06-13 17:52:06 -060011755TEST_F(VkLayerTest, MissingClearAttachment) {
11756 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
11757 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011758 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Muellerd4914412016-06-13 17:52:06 -060011759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11760 "vkCmdClearAttachments() attachment index 1 not found in attachment "
11761 "reference array of active subpass 0");
11762
11763 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11764 m_errorMonitor->VerifyFound();
11765}
11766
Karl Schultz6addd812016-02-02 17:17:23 -070011767TEST_F(VkLayerTest, ClearCmdNoDraw) {
11768 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
11769 // to issuing a Draw
11770 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011771
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11773 "vkCmdClearAttachments() issued on CB object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011774
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011775 ASSERT_NO_FATAL_FAILURE(InitState());
11776 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011777
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011778 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011779 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11780 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011781
11782 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011783 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11784 ds_pool_ci.pNext = NULL;
11785 ds_pool_ci.maxSets = 1;
11786 ds_pool_ci.poolSizeCount = 1;
11787 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011788
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011789 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011790 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011791 ASSERT_VK_SUCCESS(err);
11792
Tony Barboureb254902015-07-15 12:50:33 -060011793 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011794 dsl_binding.binding = 0;
11795 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11796 dsl_binding.descriptorCount = 1;
11797 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11798 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011799
Tony Barboureb254902015-07-15 12:50:33 -060011800 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011801 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11802 ds_layout_ci.pNext = NULL;
11803 ds_layout_ci.bindingCount = 1;
11804 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011805
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011806 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011807 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011808 ASSERT_VK_SUCCESS(err);
11809
11810 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011811 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011812 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011813 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011814 alloc_info.descriptorPool = ds_pool;
11815 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011816 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011817 ASSERT_VK_SUCCESS(err);
11818
Tony Barboureb254902015-07-15 12:50:33 -060011819 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011820 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011821 pipe_ms_state_ci.pNext = NULL;
11822 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11823 pipe_ms_state_ci.sampleShadingEnable = 0;
11824 pipe_ms_state_ci.minSampleShading = 1.0;
11825 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011826
Tony Barboureb254902015-07-15 12:50:33 -060011827 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011828 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11829 pipeline_layout_ci.pNext = NULL;
11830 pipeline_layout_ci.setLayoutCount = 1;
11831 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011832
11833 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011834 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011835 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011836
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011837 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011838 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011839 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011840 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011841
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011842 VkPipelineObj pipe(m_device);
11843 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011844 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011845 pipe.SetMSAA(&pipe_ms_state_ci);
11846 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011847
11848 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011849
Karl Schultz6addd812016-02-02 17:17:23 -070011850 // Main thing we care about for this test is that the VkImage obj we're
11851 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011852 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011853 VkClearAttachment color_attachment;
11854 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11855 color_attachment.clearValue.color.float32[0] = 1.0;
11856 color_attachment.clearValue.color.float32[1] = 1.0;
11857 color_attachment.clearValue.color.float32[2] = 1.0;
11858 color_attachment.clearValue.color.float32[3] = 1.0;
11859 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011860 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011861
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011862 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011863
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011864 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011865
Chia-I Wuf7458c52015-10-26 21:10:41 +080011866 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11867 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11868 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011869}
11870
Karl Schultz6addd812016-02-02 17:17:23 -070011871TEST_F(VkLayerTest, VtxBufferBadIndex) {
11872 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011873
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11875 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011876
Tobin Ehlis502480b2015-06-24 15:53:07 -060011877 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011878 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011880
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011881 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011882 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11883 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011884
11885 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011886 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11887 ds_pool_ci.pNext = NULL;
11888 ds_pool_ci.maxSets = 1;
11889 ds_pool_ci.poolSizeCount = 1;
11890 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011891
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011892 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011893 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011894 ASSERT_VK_SUCCESS(err);
11895
Tony Barboureb254902015-07-15 12:50:33 -060011896 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011897 dsl_binding.binding = 0;
11898 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11899 dsl_binding.descriptorCount = 1;
11900 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11901 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011902
Tony Barboureb254902015-07-15 12:50:33 -060011903 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011904 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11905 ds_layout_ci.pNext = NULL;
11906 ds_layout_ci.bindingCount = 1;
11907 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011908
Tobin Ehlis502480b2015-06-24 15:53:07 -060011909 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011910 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011911 ASSERT_VK_SUCCESS(err);
11912
11913 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011914 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011915 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011916 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011917 alloc_info.descriptorPool = ds_pool;
11918 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011919 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011920 ASSERT_VK_SUCCESS(err);
11921
Tony Barboureb254902015-07-15 12:50:33 -060011922 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011923 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011924 pipe_ms_state_ci.pNext = NULL;
11925 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11926 pipe_ms_state_ci.sampleShadingEnable = 0;
11927 pipe_ms_state_ci.minSampleShading = 1.0;
11928 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011929
Tony Barboureb254902015-07-15 12:50:33 -060011930 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011931 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11932 pipeline_layout_ci.pNext = NULL;
11933 pipeline_layout_ci.setLayoutCount = 1;
11934 pipeline_layout_ci.pSetLayouts = &ds_layout;
11935 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011936
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011937 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011938 ASSERT_VK_SUCCESS(err);
11939
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011940 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11941 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11942 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011943 VkPipelineObj pipe(m_device);
11944 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011945 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011946 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011947 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011948 pipe.SetViewport(m_viewports);
11949 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011950 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011951
11952 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011953 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011954 // Don't care about actual data, just need to get to draw to flag error
11955 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011956 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011957 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011958 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011959
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011960 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011961
Chia-I Wuf7458c52015-10-26 21:10:41 +080011962 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11963 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11964 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011965}
Mark Muellerdfe37552016-07-07 14:47:42 -060011966
Mark Mueller2ee294f2016-08-04 12:59:48 -060011967TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
11968 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
11969 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011970 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011971
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011972 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
11973 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011974
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011975 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
11976 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011977
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011978 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011979
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060011981 // The following test fails with recent NVidia drivers.
11982 // By the time core_validation is reached, the NVidia
11983 // driver has sanitized the invalid condition and core_validation
11984 // is not introduced to the failure condition. This is not the case
11985 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011986 // uint32_t count = static_cast<uint32_t>(~0);
11987 // VkPhysicalDevice physical_device;
11988 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11989 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011992 float queue_priority = 0.0;
11993
11994 VkDeviceQueueCreateInfo queue_create_info = {};
11995 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11996 queue_create_info.queueCount = 1;
11997 queue_create_info.pQueuePriorities = &queue_priority;
11998 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11999
12000 VkPhysicalDeviceFeatures features = m_device->phy().features();
12001 VkDevice testDevice;
12002 VkDeviceCreateInfo device_create_info = {};
12003 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12004 device_create_info.queueCreateInfoCount = 1;
12005 device_create_info.pQueueCreateInfos = &queue_create_info;
12006 device_create_info.pEnabledFeatures = &features;
12007 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12008 m_errorMonitor->VerifyFound();
12009
12010 queue_create_info.queueFamilyIndex = 1;
12011
12012 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12013 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12014 for (unsigned i = 0; i < feature_count; i++) {
12015 if (VK_FALSE == feature_array[i]) {
12016 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012018 device_create_info.pEnabledFeatures = &features;
12019 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12020 m_errorMonitor->VerifyFound();
12021 break;
12022 }
12023 }
12024}
12025
12026TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
12027 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
12028 "End a command buffer with a query still in progress.");
12029
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012030 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12031 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12032 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012033
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012034 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012037
12038 ASSERT_NO_FATAL_FAILURE(InitState());
12039
12040 VkEvent event;
12041 VkEventCreateInfo event_create_info{};
12042 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12043 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12044
Mark Mueller2ee294f2016-08-04 12:59:48 -060012045 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012046 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012047
12048 BeginCommandBuffer();
12049
12050 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012051 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012052 ASSERT_TRUE(image.initialized());
12053 VkImageMemoryBarrier img_barrier = {};
12054 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12055 img_barrier.pNext = NULL;
12056 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12057 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12058 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12059 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12060 img_barrier.image = image.handle();
12061 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012062
12063 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12064 // that layer validation catches the case when it is not.
12065 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012066 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12067 img_barrier.subresourceRange.baseArrayLayer = 0;
12068 img_barrier.subresourceRange.baseMipLevel = 0;
12069 img_barrier.subresourceRange.layerCount = 1;
12070 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012071 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12072 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012073 m_errorMonitor->VerifyFound();
12074
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012076
12077 VkQueryPool query_pool;
12078 VkQueryPoolCreateInfo query_pool_create_info = {};
12079 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12080 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12081 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012082 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012083
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012084 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012085 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12086
12087 vkEndCommandBuffer(m_commandBuffer->handle());
12088 m_errorMonitor->VerifyFound();
12089
12090 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12091 vkDestroyEvent(m_device->device(), event, nullptr);
12092}
12093
Mark Muellerdfe37552016-07-07 14:47:42 -060012094TEST_F(VkLayerTest, VertexBufferInvalid) {
12095 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
12096 "delete a buffer twice, use an invalid offset for each "
12097 "buffer type, and attempt to bind a null buffer");
12098
12099 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
12100 "using deleted buffer ";
12101 const char *double_destroy_message = "Cannot free buffer 0x";
12102 const char *invalid_offset_message = "vkBindBufferMemory(): "
12103 "memoryOffset is 0x";
12104 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
12105 "storage memoryOffset "
12106 "is 0x";
12107 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
12108 "texel memoryOffset "
12109 "is 0x";
12110 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
12111 "uniform memoryOffset "
12112 "is 0x";
12113 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
12114 " to Bind Obj(0x";
12115 const char *free_invalid_buffer_message = "Request to delete memory "
12116 "object 0x";
12117
12118 ASSERT_NO_FATAL_FAILURE(InitState());
12119 ASSERT_NO_FATAL_FAILURE(InitViewport());
12120 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12121
12122 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012123 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012124 pipe_ms_state_ci.pNext = NULL;
12125 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12126 pipe_ms_state_ci.sampleShadingEnable = 0;
12127 pipe_ms_state_ci.minSampleShading = 1.0;
12128 pipe_ms_state_ci.pSampleMask = nullptr;
12129
12130 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12131 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12132 VkPipelineLayout pipeline_layout;
12133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012134 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012135 ASSERT_VK_SUCCESS(err);
12136
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012137 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12138 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012139 VkPipelineObj pipe(m_device);
12140 pipe.AddShader(&vs);
12141 pipe.AddShader(&fs);
12142 pipe.AddColorAttachment();
12143 pipe.SetMSAA(&pipe_ms_state_ci);
12144 pipe.SetViewport(m_viewports);
12145 pipe.SetScissor(m_scissors);
12146 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12147
12148 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012149 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012150
12151 {
12152 // Create and bind a vertex buffer in a reduced scope, which will cause
12153 // it to be deleted upon leaving this scope
12154 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012155 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012156 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12157 draw_verticies.AddVertexInputToPipe(pipe);
12158 }
12159
12160 Draw(1, 0, 0, 0);
12161
12162 EndCommandBuffer();
12163
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012165 QueueCommandBuffer(false);
12166 m_errorMonitor->VerifyFound();
12167
12168 {
12169 // Create and bind a vertex buffer in a reduced scope, and delete it
12170 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012171 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
12172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060012173 buffer_test.TestDoubleDestroy();
12174 }
12175 m_errorMonitor->VerifyFound();
12176
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012177 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012178 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
12180 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12181 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012182 m_errorMonitor->VerifyFound();
12183 }
12184
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012185 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12186 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012187 // Create and bind a memory buffer with an invalid offset again,
12188 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
12190 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12191 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012192 m_errorMonitor->VerifyFound();
12193 }
12194
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012195 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012196 // Create and bind a memory buffer with an invalid offset again, but
12197 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
12199 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12200 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012201 m_errorMonitor->VerifyFound();
12202 }
12203
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012204 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012205 // Create and bind a memory buffer with an invalid offset again, but
12206 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
12208 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12209 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012210 m_errorMonitor->VerifyFound();
12211 }
12212
12213 {
12214 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
12216 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12217 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012218 m_errorMonitor->VerifyFound();
12219 }
12220
12221 {
12222 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
12224 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12225 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012226 }
12227 m_errorMonitor->VerifyFound();
12228
12229 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12230}
12231
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012232// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12233TEST_F(VkLayerTest, InvalidImageLayout) {
12234 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012235 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12236 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012237 // 3 in ValidateCmdBufImageLayouts
12238 // * -1 Attempt to submit cmd buf w/ deleted image
12239 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12240 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12242 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012243
12244 ASSERT_NO_FATAL_FAILURE(InitState());
12245 // Create src & dst images to use for copy operations
12246 VkImage src_image;
12247 VkImage dst_image;
12248
12249 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12250 const int32_t tex_width = 32;
12251 const int32_t tex_height = 32;
12252
12253 VkImageCreateInfo image_create_info = {};
12254 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12255 image_create_info.pNext = NULL;
12256 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12257 image_create_info.format = tex_format;
12258 image_create_info.extent.width = tex_width;
12259 image_create_info.extent.height = tex_height;
12260 image_create_info.extent.depth = 1;
12261 image_create_info.mipLevels = 1;
12262 image_create_info.arrayLayers = 4;
12263 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12264 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12265 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
12266 image_create_info.flags = 0;
12267
12268 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12269 ASSERT_VK_SUCCESS(err);
12270 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12271 ASSERT_VK_SUCCESS(err);
12272
12273 BeginCommandBuffer();
12274 VkImageCopy copyRegion;
12275 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12276 copyRegion.srcSubresource.mipLevel = 0;
12277 copyRegion.srcSubresource.baseArrayLayer = 0;
12278 copyRegion.srcSubresource.layerCount = 1;
12279 copyRegion.srcOffset.x = 0;
12280 copyRegion.srcOffset.y = 0;
12281 copyRegion.srcOffset.z = 0;
12282 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12283 copyRegion.dstSubresource.mipLevel = 0;
12284 copyRegion.dstSubresource.baseArrayLayer = 0;
12285 copyRegion.dstSubresource.layerCount = 1;
12286 copyRegion.dstOffset.x = 0;
12287 copyRegion.dstOffset.y = 0;
12288 copyRegion.dstOffset.z = 0;
12289 copyRegion.extent.width = 1;
12290 copyRegion.extent.height = 1;
12291 copyRegion.extent.depth = 1;
12292 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12293 m_errorMonitor->VerifyFound();
12294 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
12296 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12297 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012298 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12299 m_errorMonitor->VerifyFound();
12300 // Final src error is due to bad layout type
12301 m_errorMonitor->SetDesiredFailureMsg(
12302 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12303 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
12304 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12305 m_errorMonitor->VerifyFound();
12306 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12308 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012309 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12310 m_errorMonitor->VerifyFound();
12311 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
12313 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12314 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012315 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12316 m_errorMonitor->VerifyFound();
12317 m_errorMonitor->SetDesiredFailureMsg(
12318 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12319 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
12320 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12321 m_errorMonitor->VerifyFound();
12322 // Now cause error due to bad image layout transition in PipelineBarrier
12323 VkImageMemoryBarrier image_barrier[1] = {};
12324 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12325 image_barrier[0].image = src_image;
12326 image_barrier[0].subresourceRange.layerCount = 2;
12327 image_barrier[0].subresourceRange.levelCount = 2;
12328 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
12330 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
12331 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
12332 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12333 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012334 m_errorMonitor->VerifyFound();
12335
12336 // Finally some layout errors at RenderPass create time
12337 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12338 VkAttachmentReference attach = {};
12339 // perf warning for GENERAL layout w/ non-DS input attachment
12340 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12341 VkSubpassDescription subpass = {};
12342 subpass.inputAttachmentCount = 1;
12343 subpass.pInputAttachments = &attach;
12344 VkRenderPassCreateInfo rpci = {};
12345 rpci.subpassCount = 1;
12346 rpci.pSubpasses = &subpass;
12347 rpci.attachmentCount = 1;
12348 VkAttachmentDescription attach_desc = {};
12349 attach_desc.format = VK_FORMAT_UNDEFINED;
12350 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012351 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012352 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12354 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012355 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12356 m_errorMonitor->VerifyFound();
12357 // error w/ non-general layout
12358 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12359
12360 m_errorMonitor->SetDesiredFailureMsg(
12361 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12362 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12363 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12364 m_errorMonitor->VerifyFound();
12365 subpass.inputAttachmentCount = 0;
12366 subpass.colorAttachmentCount = 1;
12367 subpass.pColorAttachments = &attach;
12368 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12369 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12371 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012372 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12373 m_errorMonitor->VerifyFound();
12374 // error w/ non-color opt or GENERAL layout for color attachment
12375 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12376 m_errorMonitor->SetDesiredFailureMsg(
12377 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12378 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12379 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12380 m_errorMonitor->VerifyFound();
12381 subpass.colorAttachmentCount = 0;
12382 subpass.pDepthStencilAttachment = &attach;
12383 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12384 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12386 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012387 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12388 m_errorMonitor->VerifyFound();
12389 // error w/ non-ds opt or GENERAL layout for color attachment
12390 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12392 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12393 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012394 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12395 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012396 // For this error we need a valid renderpass so create default one
12397 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12398 attach.attachment = 0;
12399 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12400 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12401 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12402 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12403 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12404 // Can't do a CLEAR load on READ_ONLY initialLayout
12405 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12406 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12407 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
12409 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
12410 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012411 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12412 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012413
12414 vkDestroyImage(m_device->device(), src_image, NULL);
12415 vkDestroyImage(m_device->device(), dst_image, NULL);
12416}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012417
12418TEST_F(VkLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
12419 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
12420 "attachment that uses LOAD_OP_CLEAR, the first subpass "
12421 "has a valid layout, and a second subpass then uses a "
12422 "valid *READ_ONLY* layout.");
12423 m_errorMonitor->ExpectSuccess();
12424 ASSERT_NO_FATAL_FAILURE(InitState());
12425
12426 VkAttachmentReference attach[2] = {};
12427 attach[0].attachment = 0;
12428 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
12429 attach[1].attachment = 0;
12430 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12431 VkSubpassDescription subpasses[2] = {};
12432 // First subpass clears DS attach on load
12433 subpasses[0].pDepthStencilAttachment = &attach[0];
12434 // 2nd subpass reads in DS as input attachment
12435 subpasses[1].inputAttachmentCount = 1;
12436 subpasses[1].pInputAttachments = &attach[1];
12437 VkAttachmentDescription attach_desc = {};
12438 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12439 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12440 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12441 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12442 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12443 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012444 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012445 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12446 VkRenderPassCreateInfo rpci = {};
12447 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
12448 rpci.attachmentCount = 1;
12449 rpci.pAttachments = &attach_desc;
12450 rpci.subpassCount = 2;
12451 rpci.pSubpasses = subpasses;
12452
12453 // Now create RenderPass and verify no errors
12454 VkRenderPass rp;
12455 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12456 m_errorMonitor->VerifyNotFound();
12457
12458 vkDestroyRenderPass(m_device->device(), rp, NULL);
12459}
Tobin Ehlis4af23302016-07-19 10:50:30 -060012460
Mark Mueller93b938f2016-08-18 10:27:40 -060012461TEST_F(VkLayerTest, SimultaneousUse) {
12462 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12463 "in primary and secondary command buffers.");
12464
12465 ASSERT_NO_FATAL_FAILURE(InitState());
12466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12467
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012468 const char *simultaneous_use_message1 = "w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
12469 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12470 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012471
12472 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012473 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012474 command_buffer_allocate_info.commandPool = m_commandPool;
12475 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12476 command_buffer_allocate_info.commandBufferCount = 1;
12477
12478 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012479 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012480 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12481 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012482 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012483 command_buffer_inheritance_info.renderPass = m_renderPass;
12484 command_buffer_inheritance_info.framebuffer = m_framebuffer;
12485 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012486 command_buffer_begin_info.flags =
12487 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012488 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12489
12490 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012491 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12492 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060012493 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012494 vkEndCommandBuffer(secondary_command_buffer);
12495
Mark Mueller93b938f2016-08-18 10:27:40 -060012496 VkSubmitInfo submit_info = {};
12497 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12498 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012499 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060012500 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060012501
Mark Mueller4042b652016-09-05 22:52:21 -060012502 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012503 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12505 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012506 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012507 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12508 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012509
12510 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060012511 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12512
Mark Mueller4042b652016-09-05 22:52:21 -060012513 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012514 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012515 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012516
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12518 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012519 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012520 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12521 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012522}
12523
Mark Mueller917f6bc2016-08-30 10:57:19 -060012524TEST_F(VkLayerTest, InUseDestroyedSignaled) {
12525 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12526 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060012527 "Delete objects that are inuse. Call VkQueueSubmit "
12528 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012529
12530 ASSERT_NO_FATAL_FAILURE(InitState());
12531 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12532
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012533 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
12534 const char *cannot_delete_event_message = "Cannot delete event 0x";
12535 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
12536 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060012537
12538 BeginCommandBuffer();
12539
12540 VkEvent event;
12541 VkEventCreateInfo event_create_info = {};
12542 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12543 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012544 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012545
Mark Muellerc8d441e2016-08-23 17:36:00 -060012546 EndCommandBuffer();
12547 vkDestroyEvent(m_device->device(), event, nullptr);
12548
12549 VkSubmitInfo submit_info = {};
12550 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12551 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012552 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012554 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12555 m_errorMonitor->VerifyFound();
12556
12557 m_errorMonitor->SetDesiredFailureMsg(0, "");
12558 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12559
12560 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12561
Mark Mueller917f6bc2016-08-30 10:57:19 -060012562 VkSemaphoreCreateInfo semaphore_create_info = {};
12563 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12564 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012565 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012566 VkFenceCreateInfo fence_create_info = {};
12567 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12568 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012569 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012570
12571 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012572 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012573 descriptor_pool_type_count.descriptorCount = 1;
12574
12575 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12576 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12577 descriptor_pool_create_info.maxSets = 1;
12578 descriptor_pool_create_info.poolSizeCount = 1;
12579 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012580 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012581
12582 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012583 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012584
12585 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012586 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012587 descriptorset_layout_binding.descriptorCount = 1;
12588 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12589
12590 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012591 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012592 descriptorset_layout_create_info.bindingCount = 1;
12593 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12594
12595 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012596 ASSERT_VK_SUCCESS(
12597 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012598
12599 VkDescriptorSet descriptorset;
12600 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012601 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012602 descriptorset_allocate_info.descriptorSetCount = 1;
12603 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12604 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012605 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012606
Mark Mueller4042b652016-09-05 22:52:21 -060012607 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12608
12609 VkDescriptorBufferInfo buffer_info = {};
12610 buffer_info.buffer = buffer_test.GetBuffer();
12611 buffer_info.offset = 0;
12612 buffer_info.range = 1024;
12613
12614 VkWriteDescriptorSet write_descriptor_set = {};
12615 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12616 write_descriptor_set.dstSet = descriptorset;
12617 write_descriptor_set.descriptorCount = 1;
12618 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12619 write_descriptor_set.pBufferInfo = &buffer_info;
12620
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012621 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012623 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12624 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012625
12626 VkPipelineObj pipe(m_device);
12627 pipe.AddColorAttachment();
12628 pipe.AddShader(&vs);
12629 pipe.AddShader(&fs);
12630
12631 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012632 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012633 pipeline_layout_create_info.setLayoutCount = 1;
12634 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12635
12636 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012637 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012638
12639 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12640
Mark Muellerc8d441e2016-08-23 17:36:00 -060012641 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012642 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012643
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012644 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12645 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12646 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012647
Mark Muellerc8d441e2016-08-23 17:36:00 -060012648 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012649
Mark Mueller917f6bc2016-08-30 10:57:19 -060012650 submit_info.signalSemaphoreCount = 1;
12651 submit_info.pSignalSemaphores = &semaphore;
12652 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012653
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012655 vkDestroyEvent(m_device->device(), event, nullptr);
12656 m_errorMonitor->VerifyFound();
12657
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012659 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12660 m_errorMonitor->VerifyFound();
12661
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012663 vkDestroyFence(m_device->device(), fence, nullptr);
12664 m_errorMonitor->VerifyFound();
12665
Tobin Ehlis122207b2016-09-01 08:50:06 -070012666 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012667 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12668 vkDestroyFence(m_device->device(), fence, nullptr);
12669 vkDestroyEvent(m_device->device(), event, nullptr);
12670 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012671 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012672 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12673}
12674
Tobin Ehlis2adda372016-09-01 08:51:06 -070012675TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12676 TEST_DESCRIPTION("Delete in-use query pool.");
12677
12678 ASSERT_NO_FATAL_FAILURE(InitState());
12679 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12680
12681 VkQueryPool query_pool;
12682 VkQueryPoolCreateInfo query_pool_ci{};
12683 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12684 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12685 query_pool_ci.queryCount = 1;
12686 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
12687 BeginCommandBuffer();
12688 // Reset query pool to create binding with cmd buffer
12689 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12690
12691 EndCommandBuffer();
12692
12693 VkSubmitInfo submit_info = {};
12694 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12695 submit_info.commandBufferCount = 1;
12696 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12697 // Submit cmd buffer and then destroy query pool while in-flight
12698 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12699
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012701 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12702 m_errorMonitor->VerifyFound();
12703
12704 vkQueueWaitIdle(m_device->m_queue);
12705 // Now that cmd buffer done we can safely destroy query_pool
12706 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12707}
12708
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012709TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12710 TEST_DESCRIPTION("Delete in-use pipeline.");
12711
12712 ASSERT_NO_FATAL_FAILURE(InitState());
12713 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12714
12715 // Empty pipeline layout used for binding PSO
12716 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12717 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12718 pipeline_layout_ci.setLayoutCount = 0;
12719 pipeline_layout_ci.pSetLayouts = NULL;
12720
12721 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012722 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012723 ASSERT_VK_SUCCESS(err);
12724
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012726 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012727 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12728 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012729 // Store pipeline handle so we can actually delete it before test finishes
12730 VkPipeline delete_this_pipeline;
12731 { // Scope pipeline so it will be auto-deleted
12732 VkPipelineObj pipe(m_device);
12733 pipe.AddShader(&vs);
12734 pipe.AddShader(&fs);
12735 pipe.AddColorAttachment();
12736 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12737 delete_this_pipeline = pipe.handle();
12738
12739 BeginCommandBuffer();
12740 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012741 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012742
12743 EndCommandBuffer();
12744
12745 VkSubmitInfo submit_info = {};
12746 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12747 submit_info.commandBufferCount = 1;
12748 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12749 // Submit cmd buffer and then pipeline destroyed while in-flight
12750 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12751 } // Pipeline deletion triggered here
12752 m_errorMonitor->VerifyFound();
12753 // Make sure queue finished and then actually delete pipeline
12754 vkQueueWaitIdle(m_device->m_queue);
12755 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12756 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12757}
12758
Tobin Ehlis209532e2016-09-07 13:52:18 -060012759TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12760 TEST_DESCRIPTION("Delete in-use sampler.");
12761
12762 ASSERT_NO_FATAL_FAILURE(InitState());
12763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12764
12765 VkDescriptorPoolSize ds_type_count;
12766 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12767 ds_type_count.descriptorCount = 1;
12768
12769 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12770 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12771 ds_pool_ci.maxSets = 1;
12772 ds_pool_ci.poolSizeCount = 1;
12773 ds_pool_ci.pPoolSizes = &ds_type_count;
12774
12775 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012776 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012777 ASSERT_VK_SUCCESS(err);
12778
12779 VkSamplerCreateInfo sampler_ci = {};
12780 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12781 sampler_ci.pNext = NULL;
12782 sampler_ci.magFilter = VK_FILTER_NEAREST;
12783 sampler_ci.minFilter = VK_FILTER_NEAREST;
12784 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12785 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12786 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12787 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12788 sampler_ci.mipLodBias = 1.0;
12789 sampler_ci.anisotropyEnable = VK_FALSE;
12790 sampler_ci.maxAnisotropy = 1;
12791 sampler_ci.compareEnable = VK_FALSE;
12792 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12793 sampler_ci.minLod = 1.0;
12794 sampler_ci.maxLod = 1.0;
12795 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12796 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12797 VkSampler sampler;
12798
12799 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12800 ASSERT_VK_SUCCESS(err);
12801
12802 VkDescriptorSetLayoutBinding layout_binding;
12803 layout_binding.binding = 0;
12804 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
12805 layout_binding.descriptorCount = 1;
12806 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12807 layout_binding.pImmutableSamplers = NULL;
12808
12809 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12810 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12811 ds_layout_ci.bindingCount = 1;
12812 ds_layout_ci.pBindings = &layout_binding;
12813 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012814 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012815 ASSERT_VK_SUCCESS(err);
12816
12817 VkDescriptorSetAllocateInfo alloc_info = {};
12818 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12819 alloc_info.descriptorSetCount = 1;
12820 alloc_info.descriptorPool = ds_pool;
12821 alloc_info.pSetLayouts = &ds_layout;
12822 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012823 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012824 ASSERT_VK_SUCCESS(err);
12825
12826 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12827 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12828 pipeline_layout_ci.pNext = NULL;
12829 pipeline_layout_ci.setLayoutCount = 1;
12830 pipeline_layout_ci.pSetLayouts = &ds_layout;
12831
12832 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012833 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012834 ASSERT_VK_SUCCESS(err);
12835
12836 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012837 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012838 ASSERT_TRUE(image.initialized());
12839
12840 VkImageView view;
12841 VkImageViewCreateInfo ivci = {};
12842 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12843 ivci.image = image.handle();
12844 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12845 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12846 ivci.subresourceRange.layerCount = 1;
12847 ivci.subresourceRange.baseMipLevel = 0;
12848 ivci.subresourceRange.levelCount = 1;
12849 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12850
12851 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12852 ASSERT_VK_SUCCESS(err);
12853
12854 VkDescriptorImageInfo image_info{};
12855 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12856 image_info.imageView = view;
12857 image_info.sampler = sampler;
12858
12859 VkWriteDescriptorSet descriptor_write = {};
12860 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12861 descriptor_write.dstSet = descriptor_set;
12862 descriptor_write.dstBinding = 0;
12863 descriptor_write.descriptorCount = 1;
12864 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12865 descriptor_write.pImageInfo = &image_info;
12866
12867 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12868
12869 // Create PSO to use the sampler
12870 char const *vsSource = "#version 450\n"
12871 "\n"
12872 "out gl_PerVertex { \n"
12873 " vec4 gl_Position;\n"
12874 "};\n"
12875 "void main(){\n"
12876 " gl_Position = vec4(1);\n"
12877 "}\n";
12878 char const *fsSource = "#version 450\n"
12879 "\n"
12880 "layout(set=0, binding=0) uniform sampler2D s;\n"
12881 "layout(location=0) out vec4 x;\n"
12882 "void main(){\n"
12883 " x = texture(s, vec2(1));\n"
12884 "}\n";
12885 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12886 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12887 VkPipelineObj pipe(m_device);
12888 pipe.AddShader(&vs);
12889 pipe.AddShader(&fs);
12890 pipe.AddColorAttachment();
12891 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12892
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060012894
12895 BeginCommandBuffer();
12896 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012897 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12898 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12899 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012900 Draw(1, 0, 0, 0);
12901 EndCommandBuffer();
12902 // Submit cmd buffer then destroy sampler
12903 VkSubmitInfo submit_info = {};
12904 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12905 submit_info.commandBufferCount = 1;
12906 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12907 // Submit cmd buffer and then destroy sampler while in-flight
12908 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12909
12910 vkDestroySampler(m_device->device(), sampler, nullptr);
12911 m_errorMonitor->VerifyFound();
12912 vkQueueWaitIdle(m_device->m_queue);
12913 // Now we can actually destroy sampler
12914 vkDestroySampler(m_device->device(), sampler, nullptr);
12915 vkDestroyImageView(m_device->device(), view, NULL);
12916 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12917 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12918 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12919}
12920
Mark Mueller1cd9f412016-08-25 13:23:52 -060012921TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060012922 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060012923 "signaled but not waited on by the queue. Wait on a "
12924 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012925
12926 ASSERT_NO_FATAL_FAILURE(InitState());
12927 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12928
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012929 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
12930 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
12931 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012932
12933 BeginCommandBuffer();
12934 EndCommandBuffer();
12935
12936 VkSemaphoreCreateInfo semaphore_create_info = {};
12937 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12938 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012939 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012940 VkSubmitInfo submit_info = {};
12941 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12942 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012943 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012944 submit_info.signalSemaphoreCount = 1;
12945 submit_info.pSignalSemaphores = &semaphore;
12946 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12947 m_errorMonitor->SetDesiredFailureMsg(0, "");
12948 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12949 BeginCommandBuffer();
12950 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012952 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12953 m_errorMonitor->VerifyFound();
12954
Mark Mueller1cd9f412016-08-25 13:23:52 -060012955 VkFenceCreateInfo fence_create_info = {};
12956 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12957 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012958 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012961 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12962 m_errorMonitor->VerifyFound();
12963
Mark Mueller4042b652016-09-05 22:52:21 -060012964 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012965 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012966 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12967}
12968
Tobin Ehlis4af23302016-07-19 10:50:30 -060012969TEST_F(VkLayerTest, FramebufferIncompatible) {
12970 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
12971 "that does not match the framebuffer for the active "
12972 "renderpass.");
12973 ASSERT_NO_FATAL_FAILURE(InitState());
12974 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12975
12976 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012977 VkAttachmentDescription attachment = {0,
12978 VK_FORMAT_B8G8R8A8_UNORM,
12979 VK_SAMPLE_COUNT_1_BIT,
12980 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12981 VK_ATTACHMENT_STORE_OP_STORE,
12982 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12983 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12984 VK_IMAGE_LAYOUT_UNDEFINED,
12985 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012986
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012987 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012988
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012989 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012991 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012992
12993 VkRenderPass rp;
12994 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12995 ASSERT_VK_SUCCESS(err);
12996
12997 // A compatible framebuffer.
12998 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012999 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013000 ASSERT_TRUE(image.initialized());
13001
13002 VkImageViewCreateInfo ivci = {
13003 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13004 nullptr,
13005 0,
13006 image.handle(),
13007 VK_IMAGE_VIEW_TYPE_2D,
13008 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013009 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13010 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013011 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13012 };
13013 VkImageView view;
13014 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13015 ASSERT_VK_SUCCESS(err);
13016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013017 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013018 VkFramebuffer fb;
13019 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13020 ASSERT_VK_SUCCESS(err);
13021
13022 VkCommandBufferAllocateInfo cbai = {};
13023 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13024 cbai.commandPool = m_commandPool;
13025 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13026 cbai.commandBufferCount = 1;
13027
13028 VkCommandBuffer sec_cb;
13029 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13030 ASSERT_VK_SUCCESS(err);
13031 VkCommandBufferBeginInfo cbbi = {};
13032 VkCommandBufferInheritanceInfo cbii = {};
13033 cbii.renderPass = renderPass();
13034 cbii.framebuffer = fb;
13035 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13036 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013037 cbbi.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013038 cbbi.pInheritanceInfo = &cbii;
13039 vkBeginCommandBuffer(sec_cb, &cbbi);
13040 vkEndCommandBuffer(sec_cb);
13041
13042 BeginCommandBuffer();
13043
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13045 " that is not the same as the primaryCB's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013046 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13047 m_errorMonitor->VerifyFound();
13048 // Cleanup
13049 vkDestroyImageView(m_device->device(), view, NULL);
13050 vkDestroyRenderPass(m_device->device(), rp, NULL);
13051 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13052}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013053
13054TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
13055 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
13056 "invalid value. If logicOp is not available, attempt to "
13057 "use it and verify that we see the correct error.");
13058 ASSERT_NO_FATAL_FAILURE(InitState());
13059 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13060
13061 auto features = m_device->phy().features();
13062 // Set the expected error depending on whether or not logicOp available
13063 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
13065 "enabled, logicOpEnable must be "
13066 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013067 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ", logicOp must be a valid VkLogicOp value");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013069 }
13070 // Create a pipeline using logicOp
13071 VkResult err;
13072
13073 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13074 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13075
13076 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013077 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013078 ASSERT_VK_SUCCESS(err);
13079
13080 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13081 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13082 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013083 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013084 vp_state_ci.pViewports = &vp;
13085 vp_state_ci.scissorCount = 1;
13086 VkRect2D scissors = {}; // Dummy scissors to point to
13087 vp_state_ci.pScissors = &scissors;
13088 // No dynamic state
13089 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
13090 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13091
13092 VkPipelineShaderStageCreateInfo shaderStages[2];
13093 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13094
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013095 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13096 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013097 shaderStages[0] = vs.GetStageCreateInfo();
13098 shaderStages[1] = fs.GetStageCreateInfo();
13099
13100 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13101 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13102
13103 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13104 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13105 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13106
13107 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13108 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13109
13110 VkPipelineColorBlendAttachmentState att = {};
13111 att.blendEnable = VK_FALSE;
13112 att.colorWriteMask = 0xf;
13113
13114 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13115 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13116 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13117 cb_ci.logicOpEnable = VK_TRUE;
13118 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
13119 cb_ci.attachmentCount = 1;
13120 cb_ci.pAttachments = &att;
13121
13122 VkGraphicsPipelineCreateInfo gp_ci = {};
13123 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13124 gp_ci.stageCount = 2;
13125 gp_ci.pStages = shaderStages;
13126 gp_ci.pVertexInputState = &vi_ci;
13127 gp_ci.pInputAssemblyState = &ia_ci;
13128 gp_ci.pViewportState = &vp_state_ci;
13129 gp_ci.pRasterizationState = &rs_ci;
13130 gp_ci.pColorBlendState = &cb_ci;
13131 gp_ci.pDynamicState = &dyn_state_ci;
13132 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13133 gp_ci.layout = pipeline_layout;
13134 gp_ci.renderPass = renderPass();
13135
13136 VkPipelineCacheCreateInfo pc_ci = {};
13137 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13138
13139 VkPipeline pipeline;
13140 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013141 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013142 ASSERT_VK_SUCCESS(err);
13143
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013144 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013145 m_errorMonitor->VerifyFound();
13146 if (VK_SUCCESS == err) {
13147 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13148 }
13149 m_errorMonitor->VerifyFound();
13150 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13151 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13152}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013153#endif // DRAW_STATE_TESTS
13154
Tobin Ehlis0788f522015-05-26 16:11:58 -060013155#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060013156#if GTEST_IS_THREADSAFE
13157struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013158 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013159 VkEvent event;
13160 bool bailout;
13161};
13162
Karl Schultz6addd812016-02-02 17:17:23 -070013163extern "C" void *AddToCommandBuffer(void *arg) {
13164 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013165
Mike Stroyana6d14942016-07-13 15:10:05 -060013166 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013167 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013168 if (data->bailout) {
13169 break;
13170 }
13171 }
13172 return NULL;
13173}
13174
Karl Schultz6addd812016-02-02 17:17:23 -070013175TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013176 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013177
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013179
Mike Stroyanaccf7692015-05-12 16:00:45 -060013180 ASSERT_NO_FATAL_FAILURE(InitState());
13181 ASSERT_NO_FATAL_FAILURE(InitViewport());
13182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13183
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013184 // Calls AllocateCommandBuffers
13185 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013186
13187 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013188 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013189
13190 VkEventCreateInfo event_info;
13191 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013192 VkResult err;
13193
13194 memset(&event_info, 0, sizeof(event_info));
13195 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13196
Chia-I Wuf7458c52015-10-26 21:10:41 +080013197 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013198 ASSERT_VK_SUCCESS(err);
13199
Mike Stroyanaccf7692015-05-12 16:00:45 -060013200 err = vkResetEvent(device(), event);
13201 ASSERT_VK_SUCCESS(err);
13202
13203 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013204 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013205 data.event = event;
13206 data.bailout = false;
13207 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013208
13209 // First do some correct operations using multiple threads.
13210 // Add many entries to command buffer from another thread.
13211 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13212 // Make non-conflicting calls from this thread at the same time.
13213 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013214 uint32_t count;
13215 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013216 }
13217 test_platform_thread_join(thread, NULL);
13218
13219 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013220 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013221 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013222 // Add many entries to command buffer from this thread at the same time.
13223 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013224
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013225 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013226 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013227
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013228 m_errorMonitor->SetBailout(NULL);
13229
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013230 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013231
Chia-I Wuf7458c52015-10-26 21:10:41 +080013232 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013233}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013234#endif // GTEST_IS_THREADSAFE
13235#endif // THREADING_TESTS
13236
Chris Forbes9f7ff632015-05-25 11:13:08 +120013237#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070013238TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013239 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13240 "with an impossible code size");
13241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013243
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013244 ASSERT_NO_FATAL_FAILURE(InitState());
13245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13246
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013247 VkShaderModule module;
13248 VkShaderModuleCreateInfo moduleCreateInfo;
13249 struct icd_spv_header spv;
13250
13251 spv.magic = ICD_SPV_MAGIC;
13252 spv.version = ICD_SPV_VERSION;
13253 spv.gen_magic = 0;
13254
13255 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13256 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013257 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013258 moduleCreateInfo.codeSize = 4;
13259 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013260 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013261
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013262 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013263}
13264
Karl Schultz6addd812016-02-02 17:17:23 -070013265TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013266 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13267 "with a bad magic number");
13268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013270
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013271 ASSERT_NO_FATAL_FAILURE(InitState());
13272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13273
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013274 VkShaderModule module;
13275 VkShaderModuleCreateInfo moduleCreateInfo;
13276 struct icd_spv_header spv;
13277
13278 spv.magic = ~ICD_SPV_MAGIC;
13279 spv.version = ICD_SPV_VERSION;
13280 spv.gen_magic = 0;
13281
13282 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13283 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013284 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013285 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13286 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013287 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013288
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013289 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013290}
13291
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013292#if 0
13293// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013294TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013296 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013297
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013298 ASSERT_NO_FATAL_FAILURE(InitState());
13299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13300
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013301 VkShaderModule module;
13302 VkShaderModuleCreateInfo moduleCreateInfo;
13303 struct icd_spv_header spv;
13304
13305 spv.magic = ICD_SPV_MAGIC;
13306 spv.version = ~ICD_SPV_VERSION;
13307 spv.gen_magic = 0;
13308
13309 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13310 moduleCreateInfo.pNext = NULL;
13311
Karl Schultz6addd812016-02-02 17:17:23 -070013312 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013313 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13314 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013315 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013316
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013317 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013318}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013319#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013320
Karl Schultz6addd812016-02-02 17:17:23 -070013321TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013322 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
13323 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013325
Chris Forbes9f7ff632015-05-25 11:13:08 +120013326 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013328
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013329 char const *vsSource = "#version 450\n"
13330 "\n"
13331 "layout(location=0) out float x;\n"
13332 "out gl_PerVertex {\n"
13333 " vec4 gl_Position;\n"
13334 "};\n"
13335 "void main(){\n"
13336 " gl_Position = vec4(1);\n"
13337 " x = 0;\n"
13338 "}\n";
13339 char const *fsSource = "#version 450\n"
13340 "\n"
13341 "layout(location=0) out vec4 color;\n"
13342 "void main(){\n"
13343 " color = vec4(1);\n"
13344 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013345
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013346 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13347 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013348
13349 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013350 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013351 pipe.AddShader(&vs);
13352 pipe.AddShader(&fs);
13353
Chris Forbes9f7ff632015-05-25 11:13:08 +120013354 VkDescriptorSetObj descriptorSet(m_device);
13355 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013356 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013357
Tony Barbour5781e8f2015-08-04 16:23:11 -060013358 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013359
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013360 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013361}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013362
Karl Schultz6addd812016-02-02 17:17:23 -070013363TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013364 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13365 "which is not present in the outputs of the previous stage");
13366
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013368
Chris Forbes59cb88d2015-05-25 11:13:13 +120013369 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013372 char const *vsSource = "#version 450\n"
13373 "\n"
13374 "out gl_PerVertex {\n"
13375 " vec4 gl_Position;\n"
13376 "};\n"
13377 "void main(){\n"
13378 " gl_Position = vec4(1);\n"
13379 "}\n";
13380 char const *fsSource = "#version 450\n"
13381 "\n"
13382 "layout(location=0) in float x;\n"
13383 "layout(location=0) out vec4 color;\n"
13384 "void main(){\n"
13385 " color = vec4(x);\n"
13386 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013387
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013388 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13389 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013390
13391 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013392 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013393 pipe.AddShader(&vs);
13394 pipe.AddShader(&fs);
13395
Chris Forbes59cb88d2015-05-25 11:13:13 +120013396 VkDescriptorSetObj descriptorSet(m_device);
13397 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013398 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013399
Tony Barbour5781e8f2015-08-04 16:23:11 -060013400 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013401
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013402 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013403}
13404
Karl Schultz6addd812016-02-02 17:17:23 -070013405TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013406 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13407 "within an interace block, which is not present in the outputs "
13408 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013410
13411 ASSERT_NO_FATAL_FAILURE(InitState());
13412 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13413
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013414 char const *vsSource = "#version 450\n"
13415 "\n"
13416 "out gl_PerVertex {\n"
13417 " vec4 gl_Position;\n"
13418 "};\n"
13419 "void main(){\n"
13420 " gl_Position = vec4(1);\n"
13421 "}\n";
13422 char const *fsSource = "#version 450\n"
13423 "\n"
13424 "in block { layout(location=0) float x; } ins;\n"
13425 "layout(location=0) out vec4 color;\n"
13426 "void main(){\n"
13427 " color = vec4(ins.x);\n"
13428 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013429
13430 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13431 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13432
13433 VkPipelineObj pipe(m_device);
13434 pipe.AddColorAttachment();
13435 pipe.AddShader(&vs);
13436 pipe.AddShader(&fs);
13437
13438 VkDescriptorSetObj descriptorSet(m_device);
13439 descriptorSet.AppendDummy();
13440 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13441
13442 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13443
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013444 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013445}
13446
Karl Schultz6addd812016-02-02 17:17:23 -070013447TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013448 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
13449 "across the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
13451 "output arr[2] of float32' vs 'ptr to "
13452 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013453
13454 ASSERT_NO_FATAL_FAILURE(InitState());
13455 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13456
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013457 char const *vsSource = "#version 450\n"
13458 "\n"
13459 "layout(location=0) out float x[2];\n"
13460 "out gl_PerVertex {\n"
13461 " vec4 gl_Position;\n"
13462 "};\n"
13463 "void main(){\n"
13464 " x[0] = 0; x[1] = 0;\n"
13465 " gl_Position = vec4(1);\n"
13466 "}\n";
13467 char const *fsSource = "#version 450\n"
13468 "\n"
13469 "layout(location=0) in float x[3];\n"
13470 "layout(location=0) out vec4 color;\n"
13471 "void main(){\n"
13472 " color = vec4(x[0] + x[1] + x[2]);\n"
13473 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013474
13475 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13476 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13477
13478 VkPipelineObj pipe(m_device);
13479 pipe.AddColorAttachment();
13480 pipe.AddShader(&vs);
13481 pipe.AddShader(&fs);
13482
13483 VkDescriptorSetObj descriptorSet(m_device);
13484 descriptorSet.AppendDummy();
13485 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13486
13487 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13488
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013489 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013490}
13491
Karl Schultz6addd812016-02-02 17:17:23 -070013492TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013493 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13494 "the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013496
Chris Forbesb56af562015-05-25 11:13:17 +120013497 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013498 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013499
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013500 char const *vsSource = "#version 450\n"
13501 "\n"
13502 "layout(location=0) out int x;\n"
13503 "out gl_PerVertex {\n"
13504 " vec4 gl_Position;\n"
13505 "};\n"
13506 "void main(){\n"
13507 " x = 0;\n"
13508 " gl_Position = vec4(1);\n"
13509 "}\n";
13510 char const *fsSource = "#version 450\n"
13511 "\n"
13512 "layout(location=0) in float x;\n" /* VS writes int */
13513 "layout(location=0) out vec4 color;\n"
13514 "void main(){\n"
13515 " color = vec4(x);\n"
13516 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013517
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013518 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13519 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013520
13521 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013522 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013523 pipe.AddShader(&vs);
13524 pipe.AddShader(&fs);
13525
Chris Forbesb56af562015-05-25 11:13:17 +120013526 VkDescriptorSetObj descriptorSet(m_device);
13527 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013528 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013529
Tony Barbour5781e8f2015-08-04 16:23:11 -060013530 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013531
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013532 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013533}
13534
Karl Schultz6addd812016-02-02 17:17:23 -070013535TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013536 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13537 "the VS->FS interface, when the variable is contained within "
13538 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013540
13541 ASSERT_NO_FATAL_FAILURE(InitState());
13542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13543
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013544 char const *vsSource = "#version 450\n"
13545 "\n"
13546 "out block { layout(location=0) int x; } outs;\n"
13547 "out gl_PerVertex {\n"
13548 " vec4 gl_Position;\n"
13549 "};\n"
13550 "void main(){\n"
13551 " outs.x = 0;\n"
13552 " gl_Position = vec4(1);\n"
13553 "}\n";
13554 char const *fsSource = "#version 450\n"
13555 "\n"
13556 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13557 "layout(location=0) out vec4 color;\n"
13558 "void main(){\n"
13559 " color = vec4(ins.x);\n"
13560 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013561
13562 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13563 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13564
13565 VkPipelineObj pipe(m_device);
13566 pipe.AddColorAttachment();
13567 pipe.AddShader(&vs);
13568 pipe.AddShader(&fs);
13569
13570 VkDescriptorSetObj descriptorSet(m_device);
13571 descriptorSet.AppendDummy();
13572 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13573
13574 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13575
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013576 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013577}
13578
13579TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013580 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
13581 "the VS->FS interface; This should manifest as a not-written/not-consumed "
13582 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0.0 which is not written by vertex shader");
Chris Forbese9928822016-02-17 14:44:52 +130013584
13585 ASSERT_NO_FATAL_FAILURE(InitState());
13586 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13587
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013588 char const *vsSource = "#version 450\n"
13589 "\n"
13590 "out block { layout(location=1) float x; } outs;\n"
13591 "out gl_PerVertex {\n"
13592 " vec4 gl_Position;\n"
13593 "};\n"
13594 "void main(){\n"
13595 " outs.x = 0;\n"
13596 " gl_Position = vec4(1);\n"
13597 "}\n";
13598 char const *fsSource = "#version 450\n"
13599 "\n"
13600 "in block { layout(location=0) float x; } ins;\n"
13601 "layout(location=0) out vec4 color;\n"
13602 "void main(){\n"
13603 " color = vec4(ins.x);\n"
13604 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013605
13606 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13607 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13608
13609 VkPipelineObj pipe(m_device);
13610 pipe.AddColorAttachment();
13611 pipe.AddShader(&vs);
13612 pipe.AddShader(&fs);
13613
13614 VkDescriptorSetObj descriptorSet(m_device);
13615 descriptorSet.AppendDummy();
13616 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13617
13618 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13619
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013620 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013621}
13622
13623TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013624 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
13625 "VS->FS interface. It's not enough to have the same set of locations in "
13626 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0.1 which is not written by vertex shader");
Chris Forbese9928822016-02-17 14:44:52 +130013628
13629 ASSERT_NO_FATAL_FAILURE(InitState());
13630 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13631
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013632 char const *vsSource = "#version 450\n"
13633 "\n"
13634 "out block { layout(location=0, component=0) float x; } outs;\n"
13635 "out gl_PerVertex {\n"
13636 " vec4 gl_Position;\n"
13637 "};\n"
13638 "void main(){\n"
13639 " outs.x = 0;\n"
13640 " gl_Position = vec4(1);\n"
13641 "}\n";
13642 char const *fsSource = "#version 450\n"
13643 "\n"
13644 "in block { layout(location=0, component=1) float x; } ins;\n"
13645 "layout(location=0) out vec4 color;\n"
13646 "void main(){\n"
13647 " color = vec4(ins.x);\n"
13648 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013649
13650 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13651 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13652
13653 VkPipelineObj pipe(m_device);
13654 pipe.AddColorAttachment();
13655 pipe.AddShader(&vs);
13656 pipe.AddShader(&fs);
13657
13658 VkDescriptorSetObj descriptorSet(m_device);
13659 descriptorSet.AppendDummy();
13660 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13661
13662 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13663
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013664 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013665}
13666
Karl Schultz6addd812016-02-02 17:17:23 -070013667TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013668 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13669 "not consumed by the vertex shader");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013671
Chris Forbesde136e02015-05-25 11:13:28 +120013672 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013673 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013674
13675 VkVertexInputBindingDescription input_binding;
13676 memset(&input_binding, 0, sizeof(input_binding));
13677
13678 VkVertexInputAttributeDescription input_attrib;
13679 memset(&input_attrib, 0, sizeof(input_attrib));
13680 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13681
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013682 char const *vsSource = "#version 450\n"
13683 "\n"
13684 "out gl_PerVertex {\n"
13685 " vec4 gl_Position;\n"
13686 "};\n"
13687 "void main(){\n"
13688 " gl_Position = vec4(1);\n"
13689 "}\n";
13690 char const *fsSource = "#version 450\n"
13691 "\n"
13692 "layout(location=0) out vec4 color;\n"
13693 "void main(){\n"
13694 " color = vec4(1);\n"
13695 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013696
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013697 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13698 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013699
13700 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013701 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013702 pipe.AddShader(&vs);
13703 pipe.AddShader(&fs);
13704
13705 pipe.AddVertexInputBindings(&input_binding, 1);
13706 pipe.AddVertexInputAttribs(&input_attrib, 1);
13707
Chris Forbesde136e02015-05-25 11:13:28 +120013708 VkDescriptorSetObj descriptorSet(m_device);
13709 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013710 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013711
Tony Barbour5781e8f2015-08-04 16:23:11 -060013712 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013713
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013714 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013715}
13716
Karl Schultz6addd812016-02-02 17:17:23 -070013717TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013718 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13719 "vertex attributes. This flushes out bad behavior in the interface walker");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013721
13722 ASSERT_NO_FATAL_FAILURE(InitState());
13723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13724
13725 VkVertexInputBindingDescription input_binding;
13726 memset(&input_binding, 0, sizeof(input_binding));
13727
13728 VkVertexInputAttributeDescription input_attrib;
13729 memset(&input_attrib, 0, sizeof(input_attrib));
13730 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13731
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013732 char const *vsSource = "#version 450\n"
13733 "\n"
13734 "layout(location=1) in float x;\n"
13735 "out gl_PerVertex {\n"
13736 " vec4 gl_Position;\n"
13737 "};\n"
13738 "void main(){\n"
13739 " gl_Position = vec4(x);\n"
13740 "}\n";
13741 char const *fsSource = "#version 450\n"
13742 "\n"
13743 "layout(location=0) out vec4 color;\n"
13744 "void main(){\n"
13745 " color = vec4(1);\n"
13746 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013747
13748 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13749 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13750
13751 VkPipelineObj pipe(m_device);
13752 pipe.AddColorAttachment();
13753 pipe.AddShader(&vs);
13754 pipe.AddShader(&fs);
13755
13756 pipe.AddVertexInputBindings(&input_binding, 1);
13757 pipe.AddVertexInputAttribs(&input_attrib, 1);
13758
13759 VkDescriptorSetObj descriptorSet(m_device);
13760 descriptorSet.AppendDummy();
13761 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13762
13763 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13764
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013765 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013766}
13767
Karl Schultz6addd812016-02-02 17:17:23 -070013768TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013769 TEST_DESCRIPTION("Test that an error is produced for a VS input which is not "
13770 "provided by a vertex attribute");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VS consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013772
Chris Forbes62e8e502015-05-25 11:13:29 +120013773 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013774 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013775
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013776 char const *vsSource = "#version 450\n"
13777 "\n"
13778 "layout(location=0) in vec4 x;\n" /* not provided */
13779 "out gl_PerVertex {\n"
13780 " vec4 gl_Position;\n"
13781 "};\n"
13782 "void main(){\n"
13783 " gl_Position = x;\n"
13784 "}\n";
13785 char const *fsSource = "#version 450\n"
13786 "\n"
13787 "layout(location=0) out vec4 color;\n"
13788 "void main(){\n"
13789 " color = vec4(1);\n"
13790 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013791
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013792 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13793 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013794
13795 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013796 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013797 pipe.AddShader(&vs);
13798 pipe.AddShader(&fs);
13799
Chris Forbes62e8e502015-05-25 11:13:29 +120013800 VkDescriptorSetObj descriptorSet(m_device);
13801 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013802 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013803
Tony Barbour5781e8f2015-08-04 16:23:11 -060013804 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013805
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013806 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013807}
13808
Karl Schultz6addd812016-02-02 17:17:23 -070013809TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013810 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13811 "fundamental type (float/int/uint) of an attribute and the "
13812 "VS input that consumes it");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0 does not match VS input type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013814
Chris Forbesc97d98e2015-05-25 11:13:31 +120013815 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013816 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013817
13818 VkVertexInputBindingDescription input_binding;
13819 memset(&input_binding, 0, sizeof(input_binding));
13820
13821 VkVertexInputAttributeDescription input_attrib;
13822 memset(&input_attrib, 0, sizeof(input_attrib));
13823 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13824
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013825 char const *vsSource = "#version 450\n"
13826 "\n"
13827 "layout(location=0) in int x;\n" /* attrib provided float */
13828 "out gl_PerVertex {\n"
13829 " vec4 gl_Position;\n"
13830 "};\n"
13831 "void main(){\n"
13832 " gl_Position = vec4(x);\n"
13833 "}\n";
13834 char const *fsSource = "#version 450\n"
13835 "\n"
13836 "layout(location=0) out vec4 color;\n"
13837 "void main(){\n"
13838 " color = vec4(1);\n"
13839 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013840
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013841 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13842 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013843
13844 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013845 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013846 pipe.AddShader(&vs);
13847 pipe.AddShader(&fs);
13848
13849 pipe.AddVertexInputBindings(&input_binding, 1);
13850 pipe.AddVertexInputAttribs(&input_attrib, 1);
13851
Chris Forbesc97d98e2015-05-25 11:13:31 +120013852 VkDescriptorSetObj descriptorSet(m_device);
13853 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013854 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013855
Tony Barbour5781e8f2015-08-04 16:23:11 -060013856 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013857
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013858 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013859}
13860
Chris Forbesc68b43c2016-04-06 11:18:47 +120013861TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013862 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13863 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13865 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013866
13867 ASSERT_NO_FATAL_FAILURE(InitState());
13868 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13869
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013870 char const *vsSource = "#version 450\n"
13871 "\n"
13872 "out gl_PerVertex {\n"
13873 " vec4 gl_Position;\n"
13874 "};\n"
13875 "void main(){\n"
13876 " gl_Position = vec4(1);\n"
13877 "}\n";
13878 char const *fsSource = "#version 450\n"
13879 "\n"
13880 "layout(location=0) out vec4 color;\n"
13881 "void main(){\n"
13882 " color = vec4(1);\n"
13883 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013884
13885 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13886 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13887
13888 VkPipelineObj pipe(m_device);
13889 pipe.AddColorAttachment();
13890 pipe.AddShader(&vs);
13891 pipe.AddShader(&vs);
13892 pipe.AddShader(&fs);
13893
13894 VkDescriptorSetObj descriptorSet(m_device);
13895 descriptorSet.AppendDummy();
13896 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13897
13898 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13899
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013900 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013901}
13902
Karl Schultz6addd812016-02-02 17:17:23 -070013903TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013904 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
13905 "as vertex attributes");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013906 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130013907
13908 ASSERT_NO_FATAL_FAILURE(InitState());
13909 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13910
13911 VkVertexInputBindingDescription input_binding;
13912 memset(&input_binding, 0, sizeof(input_binding));
13913
13914 VkVertexInputAttributeDescription input_attribs[2];
13915 memset(input_attribs, 0, sizeof(input_attribs));
13916
13917 for (int i = 0; i < 2; i++) {
13918 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
13919 input_attribs[i].location = i;
13920 }
13921
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013922 char const *vsSource = "#version 450\n"
13923 "\n"
13924 "layout(location=0) in mat2x4 x;\n"
13925 "out gl_PerVertex {\n"
13926 " vec4 gl_Position;\n"
13927 "};\n"
13928 "void main(){\n"
13929 " gl_Position = x[0] + x[1];\n"
13930 "}\n";
13931 char const *fsSource = "#version 450\n"
13932 "\n"
13933 "layout(location=0) out vec4 color;\n"
13934 "void main(){\n"
13935 " color = vec4(1);\n"
13936 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130013937
13938 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13939 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13940
13941 VkPipelineObj pipe(m_device);
13942 pipe.AddColorAttachment();
13943 pipe.AddShader(&vs);
13944 pipe.AddShader(&fs);
13945
13946 pipe.AddVertexInputBindings(&input_binding, 1);
13947 pipe.AddVertexInputAttribs(input_attribs, 2);
13948
13949 VkDescriptorSetObj descriptorSet(m_device);
13950 descriptorSet.AppendDummy();
13951 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13952
13953 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13954
13955 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013956 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130013957}
13958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013959TEST_F(VkLayerTest, CreatePipelineAttribArrayType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013960 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130013961
13962 ASSERT_NO_FATAL_FAILURE(InitState());
13963 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13964
13965 VkVertexInputBindingDescription input_binding;
13966 memset(&input_binding, 0, sizeof(input_binding));
13967
13968 VkVertexInputAttributeDescription input_attribs[2];
13969 memset(input_attribs, 0, sizeof(input_attribs));
13970
13971 for (int i = 0; i < 2; i++) {
13972 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
13973 input_attribs[i].location = i;
13974 }
13975
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013976 char const *vsSource = "#version 450\n"
13977 "\n"
13978 "layout(location=0) in vec4 x[2];\n"
13979 "out gl_PerVertex {\n"
13980 " vec4 gl_Position;\n"
13981 "};\n"
13982 "void main(){\n"
13983 " gl_Position = x[0] + x[1];\n"
13984 "}\n";
13985 char const *fsSource = "#version 450\n"
13986 "\n"
13987 "layout(location=0) out vec4 color;\n"
13988 "void main(){\n"
13989 " color = vec4(1);\n"
13990 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130013991
13992 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13993 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13994
13995 VkPipelineObj pipe(m_device);
13996 pipe.AddColorAttachment();
13997 pipe.AddShader(&vs);
13998 pipe.AddShader(&fs);
13999
14000 pipe.AddVertexInputBindings(&input_binding, 1);
14001 pipe.AddVertexInputAttribs(input_attribs, 2);
14002
14003 VkDescriptorSetObj descriptorSet(m_device);
14004 descriptorSet.AppendDummy();
14005 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14006
14007 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14008
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014009 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130014010}
Chris Forbes2682b242015-11-24 11:13:14 +130014011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014012TEST_F(VkLayerTest, CreatePipelineAttribComponents) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014013 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
14014 "through multiple VS inputs, each consuming a different subset of the "
14015 "components.");
Chris Forbesbc290ce2016-07-06 12:01:49 +120014016 m_errorMonitor->ExpectSuccess();
14017
14018 ASSERT_NO_FATAL_FAILURE(InitState());
14019 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14020
14021 VkVertexInputBindingDescription input_binding;
14022 memset(&input_binding, 0, sizeof(input_binding));
14023
14024 VkVertexInputAttributeDescription input_attribs[3];
14025 memset(input_attribs, 0, sizeof(input_attribs));
14026
14027 for (int i = 0; i < 3; i++) {
14028 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14029 input_attribs[i].location = i;
14030 }
14031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014032 char const *vsSource = "#version 450\n"
14033 "\n"
14034 "layout(location=0) in vec4 x;\n"
14035 "layout(location=1) in vec3 y1;\n"
14036 "layout(location=1, component=3) in float y2;\n"
14037 "layout(location=2) in vec4 z;\n"
14038 "out gl_PerVertex {\n"
14039 " vec4 gl_Position;\n"
14040 "};\n"
14041 "void main(){\n"
14042 " gl_Position = x + vec4(y1, y2) + z;\n"
14043 "}\n";
14044 char const *fsSource = "#version 450\n"
14045 "\n"
14046 "layout(location=0) out vec4 color;\n"
14047 "void main(){\n"
14048 " color = vec4(1);\n"
14049 "}\n";
Chris Forbesbc290ce2016-07-06 12:01:49 +120014050
14051 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14052 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14053
14054 VkPipelineObj pipe(m_device);
14055 pipe.AddColorAttachment();
14056 pipe.AddShader(&vs);
14057 pipe.AddShader(&fs);
14058
14059 pipe.AddVertexInputBindings(&input_binding, 1);
14060 pipe.AddVertexInputAttribs(input_attribs, 3);
14061
14062 VkDescriptorSetObj descriptorSet(m_device);
14063 descriptorSet.AppendDummy();
14064 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14065
14066 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14067
14068 m_errorMonitor->VerifyNotFound();
14069}
14070
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014071TEST_F(VkLayerTest, CreatePipelineSimplePositive) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014072 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014073
14074 ASSERT_NO_FATAL_FAILURE(InitState());
14075 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14076
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014077 char const *vsSource = "#version 450\n"
14078 "out gl_PerVertex {\n"
14079 " vec4 gl_Position;\n"
14080 "};\n"
14081 "void main(){\n"
14082 " gl_Position = vec4(0);\n"
14083 "}\n";
14084 char const *fsSource = "#version 450\n"
14085 "\n"
14086 "layout(location=0) out vec4 color;\n"
14087 "void main(){\n"
14088 " color = vec4(1);\n"
14089 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014090
14091 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14092 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14093
14094 VkPipelineObj pipe(m_device);
14095 pipe.AddColorAttachment();
14096 pipe.AddShader(&vs);
14097 pipe.AddShader(&fs);
14098
14099 VkDescriptorSetObj descriptorSet(m_device);
14100 descriptorSet.AppendDummy();
14101 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14102
14103 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14104
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014105 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014106}
14107
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014108TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014109 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
14110 "set out in 14.1.3: fundamental type must match, and producer side must "
14111 "have at least as many components");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014112 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120014113
14114 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
14115
14116 ASSERT_NO_FATAL_FAILURE(InitState());
14117 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014119 char const *vsSource = "#version 450\n"
14120 "out gl_PerVertex {\n"
14121 " vec4 gl_Position;\n"
14122 "};\n"
14123 "layout(location=0) out vec3 x;\n"
14124 "layout(location=1) out ivec3 y;\n"
14125 "layout(location=2) out vec3 z;\n"
14126 "void main(){\n"
14127 " gl_Position = vec4(0);\n"
14128 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
14129 "}\n";
14130 char const *fsSource = "#version 450\n"
14131 "\n"
14132 "layout(location=0) out vec4 color;\n"
14133 "layout(location=0) in float x;\n"
14134 "layout(location=1) flat in int y;\n"
14135 "layout(location=2) in vec2 z;\n"
14136 "void main(){\n"
14137 " color = vec4(1 + x + y + z.x);\n"
14138 "}\n";
Chris Forbes912c9192016-04-05 17:50:35 +120014139
14140 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14141 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14142
14143 VkPipelineObj pipe(m_device);
14144 pipe.AddColorAttachment();
14145 pipe.AddShader(&vs);
14146 pipe.AddShader(&fs);
14147
14148 VkDescriptorSetObj descriptorSet(m_device);
14149 descriptorSet.AppendDummy();
14150 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14151
Mike Stroyan255e9582016-06-24 09:49:32 -060014152 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014153 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Mike Stroyan255e9582016-06-24 09:49:32 -060014154 ASSERT_VK_SUCCESS(err);
14155
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014156 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120014157}
14158
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014159TEST_F(VkLayerTest, CreatePipelineTessPerVertex) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014160 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
14161 "passed between the TCS and TES stages");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014162 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014163
14164 ASSERT_NO_FATAL_FAILURE(InitState());
14165 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14166
Chris Forbesc1e852d2016-04-04 19:26:42 +120014167 if (!m_device->phy().features().tessellationShader) {
14168 printf("Device does not support tessellation shaders; skipped.\n");
14169 return;
14170 }
14171
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014172 char const *vsSource = "#version 450\n"
14173 "void main(){}\n";
14174 char const *tcsSource = "#version 450\n"
14175 "layout(location=0) out int x[];\n"
14176 "layout(vertices=3) out;\n"
14177 "void main(){\n"
14178 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14179 " gl_TessLevelInner[0] = 1;\n"
14180 " x[gl_InvocationID] = gl_InvocationID;\n"
14181 "}\n";
14182 char const *tesSource = "#version 450\n"
14183 "layout(triangles, equal_spacing, cw) in;\n"
14184 "layout(location=0) in int x[];\n"
14185 "out gl_PerVertex { vec4 gl_Position; };\n"
14186 "void main(){\n"
14187 " gl_Position.xyz = gl_TessCoord;\n"
14188 " gl_Position.w = x[0] + x[1] + x[2];\n"
14189 "}\n";
14190 char const *fsSource = "#version 450\n"
14191 "layout(location=0) out vec4 color;\n"
14192 "void main(){\n"
14193 " color = vec4(1);\n"
14194 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014195
14196 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14197 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14198 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14199 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14200
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014201 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14202 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014203
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014204 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesb4cacb62016-04-04 19:15:00 +120014205
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014206 VkPipelineObj pipe(m_device);
14207 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120014208 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014209 pipe.AddColorAttachment();
14210 pipe.AddShader(&vs);
14211 pipe.AddShader(&tcs);
14212 pipe.AddShader(&tes);
14213 pipe.AddShader(&fs);
14214
14215 VkDescriptorSetObj descriptorSet(m_device);
14216 descriptorSet.AppendDummy();
14217 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14218
14219 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14220
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014221 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014222}
14223
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014224TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014225 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
14226 "interface block passed into the geometry shader. This "
14227 "is interesting because the 'extra' array level is not "
14228 "present on the member type, but on the block instance.");
Chris Forbesa0ab8152016-04-20 13:34:27 +120014229 m_errorMonitor->ExpectSuccess();
14230
14231 ASSERT_NO_FATAL_FAILURE(InitState());
14232 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14233
14234 if (!m_device->phy().features().geometryShader) {
14235 printf("Device does not support geometry shaders; skipped.\n");
14236 return;
14237 }
14238
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014239 char const *vsSource = "#version 450\n"
14240 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
14241 "void main(){\n"
14242 " vs_out.x = vec4(1);\n"
14243 "}\n";
14244 char const *gsSource = "#version 450\n"
14245 "layout(triangles) in;\n"
14246 "layout(triangle_strip, max_vertices=3) out;\n"
14247 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
14248 "out gl_PerVertex { vec4 gl_Position; };\n"
14249 "void main() {\n"
14250 " gl_Position = gs_in[0].x;\n"
14251 " EmitVertex();\n"
14252 "}\n";
14253 char const *fsSource = "#version 450\n"
14254 "layout(location=0) out vec4 color;\n"
14255 "void main(){\n"
14256 " color = vec4(1);\n"
14257 "}\n";
Chris Forbesa0ab8152016-04-20 13:34:27 +120014258
14259 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14260 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
14261 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14262
14263 VkPipelineObj pipe(m_device);
14264 pipe.AddColorAttachment();
14265 pipe.AddShader(&vs);
14266 pipe.AddShader(&gs);
14267 pipe.AddShader(&fs);
14268
14269 VkDescriptorSetObj descriptorSet(m_device);
14270 descriptorSet.AppendDummy();
14271 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14272
14273 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14274
14275 m_errorMonitor->VerifyNotFound();
14276}
14277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014278TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014279 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
14280 "the TCS without the patch decoration, but consumed in the TES "
14281 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
14283 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014284
14285 ASSERT_NO_FATAL_FAILURE(InitState());
14286 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14287
Chris Forbesc1e852d2016-04-04 19:26:42 +120014288 if (!m_device->phy().features().tessellationShader) {
14289 printf("Device does not support tessellation shaders; skipped.\n");
14290 return;
14291 }
14292
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014293 char const *vsSource = "#version 450\n"
14294 "void main(){}\n";
14295 char const *tcsSource = "#version 450\n"
14296 "layout(location=0) out int x[];\n"
14297 "layout(vertices=3) out;\n"
14298 "void main(){\n"
14299 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14300 " gl_TessLevelInner[0] = 1;\n"
14301 " x[gl_InvocationID] = gl_InvocationID;\n"
14302 "}\n";
14303 char const *tesSource = "#version 450\n"
14304 "layout(triangles, equal_spacing, cw) in;\n"
14305 "layout(location=0) patch in int x;\n"
14306 "out gl_PerVertex { vec4 gl_Position; };\n"
14307 "void main(){\n"
14308 " gl_Position.xyz = gl_TessCoord;\n"
14309 " gl_Position.w = x;\n"
14310 "}\n";
14311 char const *fsSource = "#version 450\n"
14312 "layout(location=0) out vec4 color;\n"
14313 "void main(){\n"
14314 " color = vec4(1);\n"
14315 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014316
14317 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14318 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14319 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14320 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14321
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014322 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14323 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014325 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014326
14327 VkPipelineObj pipe(m_device);
14328 pipe.SetInputAssembly(&iasci);
14329 pipe.SetTessellation(&tsci);
14330 pipe.AddColorAttachment();
14331 pipe.AddShader(&vs);
14332 pipe.AddShader(&tcs);
14333 pipe.AddShader(&tes);
14334 pipe.AddShader(&fs);
14335
14336 VkDescriptorSetObj descriptorSet(m_device);
14337 descriptorSet.AppendDummy();
14338 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14339
14340 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14341
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014342 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014343}
14344
Karl Schultz6addd812016-02-02 17:17:23 -070014345TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014346 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
14347 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14349 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014350
Chris Forbes280ba2c2015-06-12 11:16:41 +120014351 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014352 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014353
14354 /* Two binding descriptions for binding 0 */
14355 VkVertexInputBindingDescription input_bindings[2];
14356 memset(input_bindings, 0, sizeof(input_bindings));
14357
14358 VkVertexInputAttributeDescription input_attrib;
14359 memset(&input_attrib, 0, sizeof(input_attrib));
14360 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14361
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014362 char const *vsSource = "#version 450\n"
14363 "\n"
14364 "layout(location=0) in float x;\n" /* attrib provided float */
14365 "out gl_PerVertex {\n"
14366 " vec4 gl_Position;\n"
14367 "};\n"
14368 "void main(){\n"
14369 " gl_Position = vec4(x);\n"
14370 "}\n";
14371 char const *fsSource = "#version 450\n"
14372 "\n"
14373 "layout(location=0) out vec4 color;\n"
14374 "void main(){\n"
14375 " color = vec4(1);\n"
14376 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014377
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014378 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14379 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014380
14381 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014382 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014383 pipe.AddShader(&vs);
14384 pipe.AddShader(&fs);
14385
14386 pipe.AddVertexInputBindings(input_bindings, 2);
14387 pipe.AddVertexInputAttribs(&input_attrib, 1);
14388
Chris Forbes280ba2c2015-06-12 11:16:41 +120014389 VkDescriptorSetObj descriptorSet(m_device);
14390 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014391 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014392
Tony Barbour5781e8f2015-08-04 16:23:11 -060014393 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014394
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014395 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014396}
Chris Forbes8f68b562015-05-25 11:13:32 +120014397
Chris Forbes35efec72016-04-21 14:32:08 +120014398TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014399 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
14400 "attributes. This is interesting because they consume multiple "
14401 "locations.");
Chris Forbes35efec72016-04-21 14:32:08 +120014402 m_errorMonitor->ExpectSuccess();
14403
14404 ASSERT_NO_FATAL_FAILURE(InitState());
14405 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14406
Chris Forbes91cf3a82016-06-28 17:51:35 +120014407 if (!m_device->phy().features().shaderFloat64) {
Chris Forbes35efec72016-04-21 14:32:08 +120014408 printf("Device does not support 64bit vertex attributes; skipped.\n");
14409 return;
14410 }
14411
14412 VkVertexInputBindingDescription input_bindings[1];
14413 memset(input_bindings, 0, sizeof(input_bindings));
14414
14415 VkVertexInputAttributeDescription input_attribs[4];
14416 memset(input_attribs, 0, sizeof(input_attribs));
14417 input_attribs[0].location = 0;
14418 input_attribs[0].offset = 0;
14419 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14420 input_attribs[1].location = 2;
14421 input_attribs[1].offset = 32;
14422 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14423 input_attribs[2].location = 4;
14424 input_attribs[2].offset = 64;
14425 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14426 input_attribs[3].location = 6;
14427 input_attribs[3].offset = 96;
14428 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14429
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014430 char const *vsSource = "#version 450\n"
14431 "\n"
14432 "layout(location=0) in dmat4 x;\n"
14433 "out gl_PerVertex {\n"
14434 " vec4 gl_Position;\n"
14435 "};\n"
14436 "void main(){\n"
14437 " gl_Position = vec4(x[0][0]);\n"
14438 "}\n";
14439 char const *fsSource = "#version 450\n"
14440 "\n"
14441 "layout(location=0) out vec4 color;\n"
14442 "void main(){\n"
14443 " color = vec4(1);\n"
14444 "}\n";
Chris Forbes35efec72016-04-21 14:32:08 +120014445
14446 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14447 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14448
14449 VkPipelineObj pipe(m_device);
14450 pipe.AddColorAttachment();
14451 pipe.AddShader(&vs);
14452 pipe.AddShader(&fs);
14453
14454 pipe.AddVertexInputBindings(input_bindings, 1);
14455 pipe.AddVertexInputAttribs(input_attribs, 4);
14456
14457 VkDescriptorSetObj descriptorSet(m_device);
14458 descriptorSet.AppendDummy();
14459 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14460
14461 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14462
14463 m_errorMonitor->VerifyNotFound();
14464}
14465
Karl Schultz6addd812016-02-02 17:17:23 -070014466TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014467 TEST_DESCRIPTION("Test that an error is produced for a FS which does not "
14468 "provide an output for one of the pipeline's color attachments");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014470
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014471 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014472
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014473 char const *vsSource = "#version 450\n"
14474 "\n"
14475 "out gl_PerVertex {\n"
14476 " vec4 gl_Position;\n"
14477 "};\n"
14478 "void main(){\n"
14479 " gl_Position = vec4(1);\n"
14480 "}\n";
14481 char const *fsSource = "#version 450\n"
14482 "\n"
14483 "void main(){\n"
14484 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014485
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014486 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14487 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014488
14489 VkPipelineObj pipe(m_device);
14490 pipe.AddShader(&vs);
14491 pipe.AddShader(&fs);
14492
Chia-I Wu08accc62015-07-07 11:50:03 +080014493 /* set up CB 0, not written */
14494 pipe.AddColorAttachment();
14495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014496
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014497 VkDescriptorSetObj descriptorSet(m_device);
14498 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014499 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014500
Tony Barbour5781e8f2015-08-04 16:23:11 -060014501 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014502
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014503 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014504}
14505
Karl Schultz6addd812016-02-02 17:17:23 -070014506TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014507 TEST_DESCRIPTION("Test that a warning is produced for a FS which provides a spurious "
14508 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
14510 "FS writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014511
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014512 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014513
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014514 char const *vsSource = "#version 450\n"
14515 "\n"
14516 "out gl_PerVertex {\n"
14517 " vec4 gl_Position;\n"
14518 "};\n"
14519 "void main(){\n"
14520 " gl_Position = vec4(1);\n"
14521 "}\n";
14522 char const *fsSource = "#version 450\n"
14523 "\n"
14524 "layout(location=0) out vec4 x;\n"
14525 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14526 "void main(){\n"
14527 " x = vec4(1);\n"
14528 " y = vec4(1);\n"
14529 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014530
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014531 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14532 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014533
14534 VkPipelineObj pipe(m_device);
14535 pipe.AddShader(&vs);
14536 pipe.AddShader(&fs);
14537
Chia-I Wu08accc62015-07-07 11:50:03 +080014538 /* set up CB 0, not written */
14539 pipe.AddColorAttachment();
14540 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014541 /* FS writes CB 1, but we don't configure it */
14542
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014543 VkDescriptorSetObj descriptorSet(m_device);
14544 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014545 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014546
Tony Barbour5781e8f2015-08-04 16:23:11 -060014547 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014548
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014549 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014550}
14551
Karl Schultz6addd812016-02-02 17:17:23 -070014552TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014553 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
14554 "type of an FS output variable, and the format of the corresponding attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014556
Chris Forbesa36d69e2015-05-25 11:13:44 +120014557 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014558
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014559 char const *vsSource = "#version 450\n"
14560 "\n"
14561 "out gl_PerVertex {\n"
14562 " vec4 gl_Position;\n"
14563 "};\n"
14564 "void main(){\n"
14565 " gl_Position = vec4(1);\n"
14566 "}\n";
14567 char const *fsSource = "#version 450\n"
14568 "\n"
14569 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14570 "void main(){\n"
14571 " x = ivec4(1);\n"
14572 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014573
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014574 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14575 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014576
14577 VkPipelineObj pipe(m_device);
14578 pipe.AddShader(&vs);
14579 pipe.AddShader(&fs);
14580
Chia-I Wu08accc62015-07-07 11:50:03 +080014581 /* set up CB 0; type is UNORM by default */
14582 pipe.AddColorAttachment();
14583 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014584
Chris Forbesa36d69e2015-05-25 11:13:44 +120014585 VkDescriptorSetObj descriptorSet(m_device);
14586 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014587 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014588
Tony Barbour5781e8f2015-08-04 16:23:11 -060014589 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014590
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014591 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014592}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014593
Karl Schultz6addd812016-02-02 17:17:23 -070014594TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014595 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
14596 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014598
Chris Forbes556c76c2015-08-14 12:04:59 +120014599 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014600
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014601 char const *vsSource = "#version 450\n"
14602 "\n"
14603 "out gl_PerVertex {\n"
14604 " vec4 gl_Position;\n"
14605 "};\n"
14606 "void main(){\n"
14607 " gl_Position = vec4(1);\n"
14608 "}\n";
14609 char const *fsSource = "#version 450\n"
14610 "\n"
14611 "layout(location=0) out vec4 x;\n"
14612 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14613 "void main(){\n"
14614 " x = vec4(bar.y);\n"
14615 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014616
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014617 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14618 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014619
Chris Forbes556c76c2015-08-14 12:04:59 +120014620 VkPipelineObj pipe(m_device);
14621 pipe.AddShader(&vs);
14622 pipe.AddShader(&fs);
14623
14624 /* set up CB 0; type is UNORM by default */
14625 pipe.AddColorAttachment();
14626 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14627
14628 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014629 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014630
14631 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14632
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014633 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014634}
14635
Chris Forbes5c59e902016-02-26 16:56:09 +130014636TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014637 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
14638 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014640
14641 ASSERT_NO_FATAL_FAILURE(InitState());
14642
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014643 char const *vsSource = "#version 450\n"
14644 "\n"
14645 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14646 "out gl_PerVertex {\n"
14647 " vec4 gl_Position;\n"
14648 "};\n"
14649 "void main(){\n"
14650 " gl_Position = vec4(consts.x);\n"
14651 "}\n";
14652 char const *fsSource = "#version 450\n"
14653 "\n"
14654 "layout(location=0) out vec4 x;\n"
14655 "void main(){\n"
14656 " x = vec4(1);\n"
14657 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014658
14659 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14660 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14661
14662 VkPipelineObj pipe(m_device);
14663 pipe.AddShader(&vs);
14664 pipe.AddShader(&fs);
14665
14666 /* set up CB 0; type is UNORM by default */
14667 pipe.AddColorAttachment();
14668 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14669
14670 VkDescriptorSetObj descriptorSet(m_device);
14671 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14672
14673 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14674
14675 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014676 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014677}
14678
Chris Forbes3fb17902016-08-22 14:57:55 +120014679TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
14680 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14681 "which is not included in the subpass description");
14682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14683 "consumes input attachment index 0 but not provided in subpass");
14684
14685 ASSERT_NO_FATAL_FAILURE(InitState());
14686
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014687 char const *vsSource = "#version 450\n"
14688 "\n"
14689 "out gl_PerVertex {\n"
14690 " vec4 gl_Position;\n"
14691 "};\n"
14692 "void main(){\n"
14693 " gl_Position = vec4(1);\n"
14694 "}\n";
14695 char const *fsSource = "#version 450\n"
14696 "\n"
14697 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14698 "layout(location=0) out vec4 color;\n"
14699 "void main() {\n"
14700 " color = subpassLoad(x);\n"
14701 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014702
14703 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14704 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14705
14706 VkPipelineObj pipe(m_device);
14707 pipe.AddShader(&vs);
14708 pipe.AddShader(&fs);
14709 pipe.AddColorAttachment();
14710 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14711
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014712 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14713 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014714 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014715 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014716 ASSERT_VK_SUCCESS(err);
14717
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014718 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014719 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014720 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014721 ASSERT_VK_SUCCESS(err);
14722
14723 // error here.
14724 pipe.CreateVKPipeline(pl, renderPass());
14725
14726 m_errorMonitor->VerifyFound();
14727
14728 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14729 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14730}
14731
Chris Forbes663b5a82016-08-22 16:14:06 +120014732TEST_F(VkLayerTest, CreatePipelineInputAttachmentPositive) {
14733 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
14734 m_errorMonitor->ExpectSuccess();
14735
14736 ASSERT_NO_FATAL_FAILURE(InitState());
14737
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014738 char const *vsSource = "#version 450\n"
14739 "\n"
14740 "out gl_PerVertex {\n"
14741 " vec4 gl_Position;\n"
14742 "};\n"
14743 "void main(){\n"
14744 " gl_Position = vec4(1);\n"
14745 "}\n";
14746 char const *fsSource = "#version 450\n"
14747 "\n"
14748 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14749 "layout(location=0) out vec4 color;\n"
14750 "void main() {\n"
14751 " color = subpassLoad(x);\n"
14752 "}\n";
Chris Forbes663b5a82016-08-22 16:14:06 +120014753
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 pipe.AddColorAttachment();
14761 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14762
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014763 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14764 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes663b5a82016-08-22 16:14:06 +120014765 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014766 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes663b5a82016-08-22 16:14:06 +120014767 ASSERT_VK_SUCCESS(err);
14768
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014769 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014770 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014771 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes663b5a82016-08-22 16:14:06 +120014772 ASSERT_VK_SUCCESS(err);
14773
14774 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014775 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14776 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14777 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14778 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14779 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 +120014780 };
14781 VkAttachmentReference color = {
14782 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14783 };
14784 VkAttachmentReference input = {
14785 1, VK_IMAGE_LAYOUT_GENERAL,
14786 };
14787
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014788 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014789
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014790 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014791 VkRenderPass rp;
14792 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14793 ASSERT_VK_SUCCESS(err);
14794
14795 // should be OK. would go wrong here if it's going to...
14796 pipe.CreateVKPipeline(pl, rp);
14797
14798 m_errorMonitor->VerifyNotFound();
14799
14800 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14801 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14802 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14803}
14804
Chris Forbes5a9a0472016-08-22 16:02:09 +120014805TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
14806 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14807 "with a format having a different fundamental type");
14808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14809 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14810
14811 ASSERT_NO_FATAL_FAILURE(InitState());
14812
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014813 char const *vsSource = "#version 450\n"
14814 "\n"
14815 "out gl_PerVertex {\n"
14816 " vec4 gl_Position;\n"
14817 "};\n"
14818 "void main(){\n"
14819 " gl_Position = vec4(1);\n"
14820 "}\n";
14821 char const *fsSource = "#version 450\n"
14822 "\n"
14823 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14824 "layout(location=0) out vec4 color;\n"
14825 "void main() {\n"
14826 " color = subpassLoad(x);\n"
14827 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014828
14829 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14830 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14831
14832 VkPipelineObj pipe(m_device);
14833 pipe.AddShader(&vs);
14834 pipe.AddShader(&fs);
14835 pipe.AddColorAttachment();
14836 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14837
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014838 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14839 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014840 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014841 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014842 ASSERT_VK_SUCCESS(err);
14843
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014844 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014845 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014846 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014847 ASSERT_VK_SUCCESS(err);
14848
14849 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014850 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14851 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14852 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14853 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14854 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 +120014855 };
14856 VkAttachmentReference color = {
14857 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14858 };
14859 VkAttachmentReference input = {
14860 1, VK_IMAGE_LAYOUT_GENERAL,
14861 };
14862
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014863 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014864
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014865 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014866 VkRenderPass rp;
14867 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14868 ASSERT_VK_SUCCESS(err);
14869
14870 // error here.
14871 pipe.CreateVKPipeline(pl, rp);
14872
14873 m_errorMonitor->VerifyFound();
14874
14875 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14876 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14877 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14878}
14879
Chris Forbes541f7b02016-08-22 15:30:27 +120014880TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
14881 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14882 "which is not included in the subpass description -- array case");
14883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14884 "consumes input attachment index 1 but not provided in subpass");
14885
14886 ASSERT_NO_FATAL_FAILURE(InitState());
14887
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014888 char const *vsSource = "#version 450\n"
14889 "\n"
14890 "out gl_PerVertex {\n"
14891 " vec4 gl_Position;\n"
14892 "};\n"
14893 "void main(){\n"
14894 " gl_Position = vec4(1);\n"
14895 "}\n";
14896 char const *fsSource = "#version 450\n"
14897 "\n"
14898 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
14899 "layout(location=0) out vec4 color;\n"
14900 "void main() {\n"
14901 " color = subpassLoad(xs[1]);\n"
14902 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014903
14904 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14905 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14906
14907 VkPipelineObj pipe(m_device);
14908 pipe.AddShader(&vs);
14909 pipe.AddShader(&fs);
14910 pipe.AddColorAttachment();
14911 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14912
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014913 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14914 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120014915 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014916 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014917 ASSERT_VK_SUCCESS(err);
14918
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014919 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120014920 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014921 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014922 ASSERT_VK_SUCCESS(err);
14923
14924 // error here.
14925 pipe.CreateVKPipeline(pl, renderPass());
14926
14927 m_errorMonitor->VerifyFound();
14928
14929 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14930 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14931}
14932
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014933TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014934 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
14935 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014937
14938 ASSERT_NO_FATAL_FAILURE(InitState());
14939
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014940 char const *csSource = "#version 450\n"
14941 "\n"
14942 "layout(local_size_x=1) in;\n"
14943 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14944 "void main(){\n"
14945 " x = vec4(1);\n"
14946 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014947
14948 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14949
14950 VkDescriptorSetObj descriptorSet(m_device);
14951 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14952
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014953 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14954 nullptr,
14955 0,
14956 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14957 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14958 descriptorSet.GetPipelineLayout(),
14959 VK_NULL_HANDLE,
14960 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014961
14962 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014963 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014964
14965 m_errorMonitor->VerifyFound();
14966
14967 if (err == VK_SUCCESS) {
14968 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14969 }
14970}
14971
14972TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014973 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
14974 "descriptor-backed resource which is not provided, but the shader does not "
14975 "statically use it. This is interesting because it requires compute pipelines "
14976 "to have a proper descriptor use walk, which they didn't for some time.");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014977 m_errorMonitor->ExpectSuccess();
14978
14979 ASSERT_NO_FATAL_FAILURE(InitState());
14980
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014981 char const *csSource = "#version 450\n"
14982 "\n"
14983 "layout(local_size_x=1) in;\n"
14984 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14985 "void main(){\n"
14986 " // x is not used.\n"
14987 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014988
14989 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14990
14991 VkDescriptorSetObj descriptorSet(m_device);
14992 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14993
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014994 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14995 nullptr,
14996 0,
14997 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14998 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14999 descriptorSet.GetPipelineLayout(),
15000 VK_NULL_HANDLE,
15001 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015002
15003 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015004 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015005
15006 m_errorMonitor->VerifyNotFound();
15007
15008 if (err == VK_SUCCESS) {
15009 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15010 }
15011}
15012
Chris Forbes22a9b092016-07-19 14:34:05 +120015013TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015014 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
15015 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15017 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015018
15019 ASSERT_NO_FATAL_FAILURE(InitState());
15020
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015021 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15022 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015023 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015024 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015025 ASSERT_VK_SUCCESS(err);
15026
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015027 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015028 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015029 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015030 ASSERT_VK_SUCCESS(err);
15031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015032 char const *csSource = "#version 450\n"
15033 "\n"
15034 "layout(local_size_x=1) in;\n"
15035 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15036 "void main() {\n"
15037 " x.x = 1.0f;\n"
15038 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015039 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015041 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15042 nullptr,
15043 0,
15044 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15045 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15046 pl,
15047 VK_NULL_HANDLE,
15048 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015049
15050 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015051 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015052
15053 m_errorMonitor->VerifyFound();
15054
15055 if (err == VK_SUCCESS) {
15056 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15057 }
15058
15059 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15060 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15061}
15062
Chris Forbese10a51f2016-07-19 14:42:51 +120015063TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015064 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15065 "sampler portion of a combined image + sampler");
Chris Forbese10a51f2016-07-19 14:42:51 +120015066 m_errorMonitor->ExpectSuccess();
15067
15068 ASSERT_NO_FATAL_FAILURE(InitState());
15069
15070 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015071 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15072 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15073 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbese10a51f2016-07-19 14:42:51 +120015074 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015075 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbese10a51f2016-07-19 14:42:51 +120015076 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015077 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015078 ASSERT_VK_SUCCESS(err);
15079
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015080 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbese10a51f2016-07-19 14:42:51 +120015081 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015082 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015083 ASSERT_VK_SUCCESS(err);
15084
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015085 char const *csSource = "#version 450\n"
15086 "\n"
15087 "layout(local_size_x=1) in;\n"
15088 "layout(set=0, binding=0) uniform sampler s;\n"
15089 "layout(set=0, binding=1) uniform texture2D t;\n"
15090 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15091 "void main() {\n"
15092 " x = texture(sampler2D(t, s), vec2(0));\n"
15093 "}\n";
Chris Forbese10a51f2016-07-19 14:42:51 +120015094 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015096 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15097 nullptr,
15098 0,
15099 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15100 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15101 pl,
15102 VK_NULL_HANDLE,
15103 -1};
Chris Forbese10a51f2016-07-19 14:42:51 +120015104
15105 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015106 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbese10a51f2016-07-19 14:42:51 +120015107
15108 m_errorMonitor->VerifyNotFound();
15109
15110 if (err == VK_SUCCESS) {
15111 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15112 }
15113
15114 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15115 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15116}
15117
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015118TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015119 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15120 "image portion of a combined image + sampler");
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015121 m_errorMonitor->ExpectSuccess();
15122
15123 ASSERT_NO_FATAL_FAILURE(InitState());
15124
15125 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015126 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15127 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15128 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015129 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015130 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015131 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015132 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015133 ASSERT_VK_SUCCESS(err);
15134
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015135 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015136 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015137 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015138 ASSERT_VK_SUCCESS(err);
15139
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015140 char const *csSource = "#version 450\n"
15141 "\n"
15142 "layout(local_size_x=1) in;\n"
15143 "layout(set=0, binding=0) uniform texture2D t;\n"
15144 "layout(set=0, binding=1) uniform sampler s;\n"
15145 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15146 "void main() {\n"
15147 " x = texture(sampler2D(t, s), vec2(0));\n"
15148 "}\n";
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015149 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15150
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015151 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15152 nullptr,
15153 0,
15154 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15155 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15156 pl,
15157 VK_NULL_HANDLE,
15158 -1};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015159
15160 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015161 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015162
15163 m_errorMonitor->VerifyNotFound();
15164
15165 if (err == VK_SUCCESS) {
15166 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15167 }
15168
15169 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15170 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15171}
15172
Chris Forbes6a4991a2016-07-19 15:07:32 +120015173TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015174 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
15175 "both the sampler and the image of a combined image+sampler "
15176 "but via separate variables");
Chris Forbes6a4991a2016-07-19 15:07:32 +120015177 m_errorMonitor->ExpectSuccess();
15178
15179 ASSERT_NO_FATAL_FAILURE(InitState());
15180
15181 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015182 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15183 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes6a4991a2016-07-19 15:07:32 +120015184 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015185 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015186 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015187 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015188 ASSERT_VK_SUCCESS(err);
15189
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015190 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015191 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015192 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015193 ASSERT_VK_SUCCESS(err);
15194
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015195 char const *csSource = "#version 450\n"
15196 "\n"
15197 "layout(local_size_x=1) in;\n"
15198 "layout(set=0, binding=0) uniform texture2D t;\n"
15199 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
15200 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
15201 "void main() {\n"
15202 " x = texture(sampler2D(t, s), vec2(0));\n"
15203 "}\n";
Chris Forbes6a4991a2016-07-19 15:07:32 +120015204 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15205
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015206 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15207 nullptr,
15208 0,
15209 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15210 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15211 pl,
15212 VK_NULL_HANDLE,
15213 -1};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015214
15215 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015216 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015217
15218 m_errorMonitor->VerifyNotFound();
15219
15220 if (err == VK_SUCCESS) {
15221 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15222 }
15223
15224 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15225 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15226}
15227
Chris Forbes50020592016-07-27 13:52:41 +120015228TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
15229 TEST_DESCRIPTION("Test that an error is produced when an image view type "
15230 "does not match the dimensionality declared in the shader");
15231
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015232 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 +120015233
15234 ASSERT_NO_FATAL_FAILURE(InitState());
15235 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15236
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015237 char const *vsSource = "#version 450\n"
15238 "\n"
15239 "out gl_PerVertex { vec4 gl_Position; };\n"
15240 "void main() { gl_Position = vec4(0); }\n";
15241 char const *fsSource = "#version 450\n"
15242 "\n"
15243 "layout(set=0, binding=0) uniform sampler3D s;\n"
15244 "layout(location=0) out vec4 color;\n"
15245 "void main() {\n"
15246 " color = texture(s, vec3(0));\n"
15247 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015248 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15249 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15250
15251 VkPipelineObj pipe(m_device);
15252 pipe.AddShader(&vs);
15253 pipe.AddShader(&fs);
15254 pipe.AddColorAttachment();
15255
15256 VkTextureObj texture(m_device, nullptr);
15257 VkSamplerObj sampler(m_device);
15258
15259 VkDescriptorSetObj descriptorSet(m_device);
15260 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15261 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15262
15263 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15264 ASSERT_VK_SUCCESS(err);
15265
15266 BeginCommandBuffer();
15267
15268 m_commandBuffer->BindPipeline(pipe);
15269 m_commandBuffer->BindDescriptorSet(descriptorSet);
15270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015271 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015272 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015273 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015274 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15275
15276 // error produced here.
15277 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15278
15279 m_errorMonitor->VerifyFound();
15280
15281 EndCommandBuffer();
15282}
15283
Chris Forbes5533bfc2016-07-27 14:12:34 +120015284TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
15285 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
15286 "are consumed via singlesample images types in the shader, or vice versa.");
15287
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015289
15290 ASSERT_NO_FATAL_FAILURE(InitState());
15291 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15292
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015293 char const *vsSource = "#version 450\n"
15294 "\n"
15295 "out gl_PerVertex { vec4 gl_Position; };\n"
15296 "void main() { gl_Position = vec4(0); }\n";
15297 char const *fsSource = "#version 450\n"
15298 "\n"
15299 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15300 "layout(location=0) out vec4 color;\n"
15301 "void main() {\n"
15302 " color = texelFetch(s, ivec2(0), 0);\n"
15303 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015304 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15305 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15306
15307 VkPipelineObj pipe(m_device);
15308 pipe.AddShader(&vs);
15309 pipe.AddShader(&fs);
15310 pipe.AddColorAttachment();
15311
15312 VkTextureObj texture(m_device, nullptr);
15313 VkSamplerObj sampler(m_device);
15314
15315 VkDescriptorSetObj descriptorSet(m_device);
15316 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15317 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15318
15319 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15320 ASSERT_VK_SUCCESS(err);
15321
15322 BeginCommandBuffer();
15323
15324 m_commandBuffer->BindPipeline(pipe);
15325 m_commandBuffer->BindDescriptorSet(descriptorSet);
15326
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015327 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015328 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015329 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015330 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15331
15332 // error produced here.
15333 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15334
15335 m_errorMonitor->VerifyFound();
15336
15337 EndCommandBuffer();
15338}
15339
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015340#endif // SHADER_CHECKER_TESTS
15341
15342#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060015343TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015345
15346 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015347
15348 // Create an image
15349 VkImage image;
15350
Karl Schultz6addd812016-02-02 17:17:23 -070015351 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15352 const int32_t tex_width = 32;
15353 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015354
15355 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015356 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15357 image_create_info.pNext = NULL;
15358 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15359 image_create_info.format = tex_format;
15360 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015361 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015362 image_create_info.extent.depth = 1;
15363 image_create_info.mipLevels = 1;
15364 image_create_info.arrayLayers = 1;
15365 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15366 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15367 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15368 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015369
15370 // Introduce error by sending down a bogus width extent
15371 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015372 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015373
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015374 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015375}
15376
Mark Youngc48c4c12016-04-11 14:26:49 -060015377TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15379 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060015380
15381 ASSERT_NO_FATAL_FAILURE(InitState());
15382
15383 // Create an image
15384 VkImage image;
15385
15386 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15387 const int32_t tex_width = 32;
15388 const int32_t tex_height = 32;
15389
15390 VkImageCreateInfo image_create_info = {};
15391 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15392 image_create_info.pNext = NULL;
15393 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15394 image_create_info.format = tex_format;
15395 image_create_info.extent.width = tex_width;
15396 image_create_info.extent.height = tex_height;
15397 image_create_info.extent.depth = 1;
15398 image_create_info.mipLevels = 1;
15399 image_create_info.arrayLayers = 1;
15400 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15401 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15402 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15403 image_create_info.flags = 0;
15404
15405 // Introduce error by sending down a bogus width extent
15406 image_create_info.extent.width = 0;
15407 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15408
15409 m_errorMonitor->VerifyFound();
15410}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015411#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120015412
Tobin Ehliscde08892015-09-22 10:11:37 -060015413#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015414TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
15415 TEST_DESCRIPTION("Create a render pass with an attachment description "
15416 "format set to VK_FORMAT_UNDEFINED");
15417
15418 ASSERT_NO_FATAL_FAILURE(InitState());
15419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15420
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015422
15423 VkAttachmentReference color_attach = {};
15424 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15425 color_attach.attachment = 0;
15426 VkSubpassDescription subpass = {};
15427 subpass.colorAttachmentCount = 1;
15428 subpass.pColorAttachments = &color_attach;
15429
15430 VkRenderPassCreateInfo rpci = {};
15431 rpci.subpassCount = 1;
15432 rpci.pSubpasses = &subpass;
15433 rpci.attachmentCount = 1;
15434 VkAttachmentDescription attach_desc = {};
15435 attach_desc.format = VK_FORMAT_UNDEFINED;
15436 rpci.pAttachments = &attach_desc;
15437 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15438 VkRenderPass rp;
15439 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15440
15441 m_errorMonitor->VerifyFound();
15442
15443 if (result == VK_SUCCESS) {
15444 vkDestroyRenderPass(m_device->device(), rp, NULL);
15445 }
15446}
15447
Karl Schultz6addd812016-02-02 17:17:23 -070015448TEST_F(VkLayerTest, InvalidImageView) {
15449 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015450
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015452
Tobin Ehliscde08892015-09-22 10:11:37 -060015453 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015454
Mike Stroyana3082432015-09-25 13:39:21 -060015455 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015456 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015457
Karl Schultz6addd812016-02-02 17:17:23 -070015458 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15459 const int32_t tex_width = 32;
15460 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015461
15462 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015463 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15464 image_create_info.pNext = NULL;
15465 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15466 image_create_info.format = tex_format;
15467 image_create_info.extent.width = tex_width;
15468 image_create_info.extent.height = tex_height;
15469 image_create_info.extent.depth = 1;
15470 image_create_info.mipLevels = 1;
15471 image_create_info.arrayLayers = 1;
15472 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15473 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15474 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15475 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015476
Chia-I Wuf7458c52015-10-26 21:10:41 +080015477 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015478 ASSERT_VK_SUCCESS(err);
15479
15480 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015481 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15482 image_view_create_info.image = image;
15483 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15484 image_view_create_info.format = tex_format;
15485 image_view_create_info.subresourceRange.layerCount = 1;
15486 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
15487 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015488 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015489
15490 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015491 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015492
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015493 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015494 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015495}
Mike Stroyana3082432015-09-25 13:39:21 -060015496
Mark Youngd339ba32016-05-30 13:28:35 -060015497TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15498 VkResult err;
15499
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindImageMemory");
Mark Youngd339ba32016-05-30 13:28:35 -060015501
15502 ASSERT_NO_FATAL_FAILURE(InitState());
15503
15504 // Create an image and try to create a view with no memory backing the image
15505 VkImage image;
15506
15507 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15508 const int32_t tex_width = 32;
15509 const int32_t tex_height = 32;
15510
15511 VkImageCreateInfo image_create_info = {};
15512 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15513 image_create_info.pNext = NULL;
15514 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15515 image_create_info.format = tex_format;
15516 image_create_info.extent.width = tex_width;
15517 image_create_info.extent.height = tex_height;
15518 image_create_info.extent.depth = 1;
15519 image_create_info.mipLevels = 1;
15520 image_create_info.arrayLayers = 1;
15521 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15522 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15523 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15524 image_create_info.flags = 0;
15525
15526 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15527 ASSERT_VK_SUCCESS(err);
15528
15529 VkImageViewCreateInfo image_view_create_info = {};
15530 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15531 image_view_create_info.image = image;
15532 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15533 image_view_create_info.format = tex_format;
15534 image_view_create_info.subresourceRange.layerCount = 1;
15535 image_view_create_info.subresourceRange.baseMipLevel = 0;
15536 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015537 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015538
15539 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015540 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015541
15542 m_errorMonitor->VerifyFound();
15543 vkDestroyImage(m_device->device(), image, NULL);
15544 // If last error is success, it still created the view, so delete it.
15545 if (err == VK_SUCCESS) {
15546 vkDestroyImageView(m_device->device(), view, NULL);
15547 }
Mark Youngd339ba32016-05-30 13:28:35 -060015548}
15549
Karl Schultz6addd812016-02-02 17:17:23 -070015550TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015551 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
15552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView: Color image "
15553 "formats must have ONLY the "
15554 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015555
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015556 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015557
Karl Schultz6addd812016-02-02 17:17:23 -070015558 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015559 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015560 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015561 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015562
15563 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015564 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015565 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015566 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15567 image_view_create_info.format = tex_format;
15568 image_view_create_info.subresourceRange.baseMipLevel = 0;
15569 image_view_create_info.subresourceRange.levelCount = 1;
15570 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015571 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015572
15573 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015574 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015575
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015576 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015577}
15578
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015579TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015580 VkResult err;
15581 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015582
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15584 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015585
Mike Stroyana3082432015-09-25 13:39:21 -060015586 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015587
15588 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015589 VkImage srcImage;
15590 VkImage dstImage;
15591 VkDeviceMemory srcMem;
15592 VkDeviceMemory destMem;
15593 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015594
15595 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015596 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15597 image_create_info.pNext = NULL;
15598 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15599 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15600 image_create_info.extent.width = 32;
15601 image_create_info.extent.height = 32;
15602 image_create_info.extent.depth = 1;
15603 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015604 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015605 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15606 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15607 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15608 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015609
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015610 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015611 ASSERT_VK_SUCCESS(err);
15612
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015613 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015614 ASSERT_VK_SUCCESS(err);
15615
15616 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015617 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015618 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15619 memAlloc.pNext = NULL;
15620 memAlloc.allocationSize = 0;
15621 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015622
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015623 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015624 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015625 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015626 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015627 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015628 ASSERT_VK_SUCCESS(err);
15629
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015630 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015631 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015632 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015633 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015634 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015635 ASSERT_VK_SUCCESS(err);
15636
15637 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15638 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015639 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015640 ASSERT_VK_SUCCESS(err);
15641
15642 BeginCommandBuffer();
15643 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015644 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015645 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015646 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015647 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015648 copyRegion.srcOffset.x = 0;
15649 copyRegion.srcOffset.y = 0;
15650 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015651 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015652 copyRegion.dstSubresource.mipLevel = 0;
15653 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015654 // Introduce failure by forcing the dst layerCount to differ from src
15655 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015656 copyRegion.dstOffset.x = 0;
15657 copyRegion.dstOffset.y = 0;
15658 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015659 copyRegion.extent.width = 1;
15660 copyRegion.extent.height = 1;
15661 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015662 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015663 EndCommandBuffer();
15664
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015665 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015666
Chia-I Wuf7458c52015-10-26 21:10:41 +080015667 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015668 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015669 vkFreeMemory(m_device->device(), srcMem, NULL);
15670 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015671}
15672
Tony Barbourd6673642016-05-05 14:46:39 -060015673TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
15674
15675 TEST_DESCRIPTION("Creating images with unsuported formats ");
15676
15677 ASSERT_NO_FATAL_FAILURE(InitState());
15678 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15679 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015680 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 -060015681 VK_IMAGE_TILING_OPTIMAL, 0);
15682 ASSERT_TRUE(image.initialized());
15683
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015684 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
15685 VkImageCreateInfo image_create_info;
15686 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15687 image_create_info.pNext = NULL;
15688 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15689 image_create_info.format = VK_FORMAT_UNDEFINED;
15690 image_create_info.extent.width = 32;
15691 image_create_info.extent.height = 32;
15692 image_create_info.extent.depth = 1;
15693 image_create_info.mipLevels = 1;
15694 image_create_info.arrayLayers = 1;
15695 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15696 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15697 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15698 image_create_info.flags = 0;
15699
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15701 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015702
15703 VkImage localImage;
15704 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15705 m_errorMonitor->VerifyFound();
15706
Tony Barbourd6673642016-05-05 14:46:39 -060015707 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015708 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015709 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15710 VkFormat format = static_cast<VkFormat>(f);
15711 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015712 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015713 unsupported = format;
15714 break;
15715 }
15716 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015717
Tony Barbourd6673642016-05-05 14:46:39 -060015718 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015719 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015721
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015722 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015723 m_errorMonitor->VerifyFound();
15724 }
15725}
15726
15727TEST_F(VkLayerTest, ImageLayerViewTests) {
15728 VkResult ret;
15729 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15730
15731 ASSERT_NO_FATAL_FAILURE(InitState());
15732
15733 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015734 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 -060015735 VK_IMAGE_TILING_OPTIMAL, 0);
15736 ASSERT_TRUE(image.initialized());
15737
15738 VkImageView imgView;
15739 VkImageViewCreateInfo imgViewInfo = {};
15740 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15741 imgViewInfo.image = image.handle();
15742 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15743 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15744 imgViewInfo.subresourceRange.layerCount = 1;
15745 imgViewInfo.subresourceRange.baseMipLevel = 0;
15746 imgViewInfo.subresourceRange.levelCount = 1;
15747 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15748
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060015750 // View can't have baseMipLevel >= image's mipLevels - Expect
15751 // VIEW_CREATE_ERROR
15752 imgViewInfo.subresourceRange.baseMipLevel = 1;
15753 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15754 m_errorMonitor->VerifyFound();
15755 imgViewInfo.subresourceRange.baseMipLevel = 0;
15756
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060015758 // View can't have baseArrayLayer >= image's arraySize - Expect
15759 // VIEW_CREATE_ERROR
15760 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15761 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15762 m_errorMonitor->VerifyFound();
15763 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15764
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
15766 "pCreateInfo->subresourceRange."
15767 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060015768 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15769 imgViewInfo.subresourceRange.levelCount = 0;
15770 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15771 m_errorMonitor->VerifyFound();
15772 imgViewInfo.subresourceRange.levelCount = 1;
15773
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
15775 "pCreateInfo->subresourceRange."
15776 "layerCount");
Tony Barbourd6673642016-05-05 14:46:39 -060015777 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15778 imgViewInfo.subresourceRange.layerCount = 0;
15779 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15780 m_errorMonitor->VerifyFound();
15781 imgViewInfo.subresourceRange.layerCount = 1;
15782
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tony Barbourd6673642016-05-05 14:46:39 -060015784 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15785 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15786 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15787 m_errorMonitor->VerifyFound();
15788 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15789
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
15791 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15792 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015793 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15794 // VIEW_CREATE_ERROR
15795 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15796 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15797 m_errorMonitor->VerifyFound();
15798 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15799
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
15801 "differing formats but they must be "
15802 "in the same compatibility class.");
Tony Barbourd6673642016-05-05 14:46:39 -060015803 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15804 // VIEW_CREATE_ERROR
15805 VkImageCreateInfo mutImgInfo = image.create_info();
15806 VkImage mutImage;
15807 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015808 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015809 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15810 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15811 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15812 ASSERT_VK_SUCCESS(ret);
15813 imgViewInfo.image = mutImage;
15814 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15815 m_errorMonitor->VerifyFound();
15816 imgViewInfo.image = image.handle();
15817 vkDestroyImage(m_device->handle(), mutImage, NULL);
15818}
15819
15820TEST_F(VkLayerTest, MiscImageLayerTests) {
15821
15822 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
15823
15824 ASSERT_NO_FATAL_FAILURE(InitState());
15825
15826 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015827 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 -060015828 VK_IMAGE_TILING_OPTIMAL, 0);
15829 ASSERT_TRUE(image.initialized());
15830
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060015832 vk_testing::Buffer buffer;
15833 VkMemoryPropertyFlags reqs = 0;
15834 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
15835 VkBufferImageCopy region = {};
15836 region.bufferRowLength = 128;
15837 region.bufferImageHeight = 128;
15838 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15839 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
15840 region.imageSubresource.layerCount = 0;
15841 region.imageExtent.height = 4;
15842 region.imageExtent.width = 4;
15843 region.imageExtent.depth = 1;
15844 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015845 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15846 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060015847 m_errorMonitor->VerifyFound();
15848 region.imageSubresource.layerCount = 1;
15849
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015850 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
15851 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
15852 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
15854 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15855 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015856 m_errorMonitor->VerifyFound();
15857
15858 // BufferOffset must be a multiple of 4
15859 // Introduce failure by setting bufferOffset to a value not divisible by 4
15860 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
15862 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15863 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015864 m_errorMonitor->VerifyFound();
15865
15866 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
15867 region.bufferOffset = 0;
15868 region.imageExtent.height = 128;
15869 region.imageExtent.width = 128;
15870 // Introduce failure by setting bufferRowLength > 0 but less than width
15871 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15873 "must be zero or greater-than-or-equal-to imageExtent.width");
15874 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15875 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015876 m_errorMonitor->VerifyFound();
15877
15878 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
15879 region.bufferRowLength = 128;
15880 // Introduce failure by setting bufferRowHeight > 0 but less than height
15881 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15883 "must be zero or greater-than-or-equal-to imageExtent.height");
15884 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15885 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015886 m_errorMonitor->VerifyFound();
15887
15888 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
15890 "specify only COLOR or DEPTH or "
15891 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060015892 // Expect MISMATCHED_IMAGE_ASPECT
15893 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015894 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15895 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060015896 m_errorMonitor->VerifyFound();
15897 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15898
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15900 "If the format of srcImage is a depth, stencil, depth stencil or "
15901 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060015902 // Expect INVALID_FILTER
15903 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015904 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 -060015905 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015906 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 -060015907 VkImageBlit blitRegion = {};
15908 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15909 blitRegion.srcSubresource.baseArrayLayer = 0;
15910 blitRegion.srcSubresource.layerCount = 1;
15911 blitRegion.srcSubresource.mipLevel = 0;
15912 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15913 blitRegion.dstSubresource.baseArrayLayer = 0;
15914 blitRegion.dstSubresource.layerCount = 1;
15915 blitRegion.dstSubresource.mipLevel = 0;
15916
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015917 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
15918 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060015919 m_errorMonitor->VerifyFound();
15920
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015921 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
15923 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
15924 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015925 m_errorMonitor->VerifyFound();
15926
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060015928 VkImageMemoryBarrier img_barrier;
15929 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15930 img_barrier.pNext = NULL;
15931 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15932 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15933 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15934 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15935 img_barrier.image = image.handle();
15936 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15937 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15938 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15939 img_barrier.subresourceRange.baseArrayLayer = 0;
15940 img_barrier.subresourceRange.baseMipLevel = 0;
15941 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
15942 img_barrier.subresourceRange.layerCount = 0;
15943 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015944 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
15945 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060015946 m_errorMonitor->VerifyFound();
15947 img_barrier.subresourceRange.layerCount = 1;
15948}
15949
15950TEST_F(VkLayerTest, ImageFormatLimits) {
15951
15952 TEST_DESCRIPTION("Exceed the limits of image format ");
15953
Cody Northropc31a84f2016-08-22 10:41:47 -060015954 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060015956 VkImageCreateInfo image_create_info = {};
15957 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15958 image_create_info.pNext = NULL;
15959 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15960 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15961 image_create_info.extent.width = 32;
15962 image_create_info.extent.height = 32;
15963 image_create_info.extent.depth = 1;
15964 image_create_info.mipLevels = 1;
15965 image_create_info.arrayLayers = 1;
15966 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15967 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15968 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15969 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15970 image_create_info.flags = 0;
15971
15972 VkImage nullImg;
15973 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015974 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
15975 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060015976 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
15977 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15978 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15979 m_errorMonitor->VerifyFound();
15980 image_create_info.extent.depth = 1;
15981
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015983 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
15984 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15985 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15986 m_errorMonitor->VerifyFound();
15987 image_create_info.mipLevels = 1;
15988
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015990 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
15991 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15992 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15993 m_errorMonitor->VerifyFound();
15994 image_create_info.arrayLayers = 1;
15995
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060015997 int samples = imgFmtProps.sampleCounts >> 1;
15998 image_create_info.samples = (VkSampleCountFlagBits)samples;
15999 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16000 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16001 m_errorMonitor->VerifyFound();
16002 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16003
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
16005 "VK_IMAGE_LAYOUT_UNDEFINED or "
16006 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016007 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16008 // Expect INVALID_LAYOUT
16009 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16010 m_errorMonitor->VerifyFound();
16011 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16012}
16013
Karl Schultz6addd812016-02-02 17:17:23 -070016014TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016015 VkResult err;
16016 bool pass;
16017
16018 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16020 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060016021
16022 ASSERT_NO_FATAL_FAILURE(InitState());
16023
16024 // Create two images of different types and try to copy between them
16025 VkImage srcImage;
16026 VkImage dstImage;
16027 VkDeviceMemory srcMem;
16028 VkDeviceMemory destMem;
16029 VkMemoryRequirements memReqs;
16030
16031 VkImageCreateInfo image_create_info = {};
16032 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16033 image_create_info.pNext = NULL;
16034 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16035 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16036 image_create_info.extent.width = 32;
16037 image_create_info.extent.height = 32;
16038 image_create_info.extent.depth = 1;
16039 image_create_info.mipLevels = 1;
16040 image_create_info.arrayLayers = 1;
16041 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16042 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16043 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16044 image_create_info.flags = 0;
16045
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016046 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016047 ASSERT_VK_SUCCESS(err);
16048
16049 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16050 // Introduce failure by creating second image with a different-sized format.
16051 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16052
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016053 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016054 ASSERT_VK_SUCCESS(err);
16055
16056 // Allocate memory
16057 VkMemoryAllocateInfo memAlloc = {};
16058 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16059 memAlloc.pNext = NULL;
16060 memAlloc.allocationSize = 0;
16061 memAlloc.memoryTypeIndex = 0;
16062
16063 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16064 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016065 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016066 ASSERT_TRUE(pass);
16067 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16068 ASSERT_VK_SUCCESS(err);
16069
16070 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16071 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016072 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016073 ASSERT_TRUE(pass);
16074 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16075 ASSERT_VK_SUCCESS(err);
16076
16077 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16078 ASSERT_VK_SUCCESS(err);
16079 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16080 ASSERT_VK_SUCCESS(err);
16081
16082 BeginCommandBuffer();
16083 VkImageCopy copyRegion;
16084 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16085 copyRegion.srcSubresource.mipLevel = 0;
16086 copyRegion.srcSubresource.baseArrayLayer = 0;
16087 copyRegion.srcSubresource.layerCount = 0;
16088 copyRegion.srcOffset.x = 0;
16089 copyRegion.srcOffset.y = 0;
16090 copyRegion.srcOffset.z = 0;
16091 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16092 copyRegion.dstSubresource.mipLevel = 0;
16093 copyRegion.dstSubresource.baseArrayLayer = 0;
16094 copyRegion.dstSubresource.layerCount = 0;
16095 copyRegion.dstOffset.x = 0;
16096 copyRegion.dstOffset.y = 0;
16097 copyRegion.dstOffset.z = 0;
16098 copyRegion.extent.width = 1;
16099 copyRegion.extent.height = 1;
16100 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016101 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060016102 EndCommandBuffer();
16103
16104 m_errorMonitor->VerifyFound();
16105
16106 vkDestroyImage(m_device->device(), srcImage, NULL);
16107 vkDestroyImage(m_device->device(), dstImage, NULL);
16108 vkFreeMemory(m_device->device(), srcMem, NULL);
16109 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016110}
16111
Karl Schultz6addd812016-02-02 17:17:23 -070016112TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16113 VkResult err;
16114 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016115
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016116 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16118 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016119
Mike Stroyana3082432015-09-25 13:39:21 -060016120 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016121
16122 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016123 VkImage srcImage;
16124 VkImage dstImage;
16125 VkDeviceMemory srcMem;
16126 VkDeviceMemory destMem;
16127 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016128
16129 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016130 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16131 image_create_info.pNext = NULL;
16132 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16133 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16134 image_create_info.extent.width = 32;
16135 image_create_info.extent.height = 32;
16136 image_create_info.extent.depth = 1;
16137 image_create_info.mipLevels = 1;
16138 image_create_info.arrayLayers = 1;
16139 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16140 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16141 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16142 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016143
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016144 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016145 ASSERT_VK_SUCCESS(err);
16146
Karl Schultzbdb75952016-04-19 11:36:49 -060016147 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16148
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016149 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016150 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016151 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16152 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016153
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016154 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016155 ASSERT_VK_SUCCESS(err);
16156
16157 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016158 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016159 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16160 memAlloc.pNext = NULL;
16161 memAlloc.allocationSize = 0;
16162 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016163
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016164 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016165 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016166 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016167 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016168 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016169 ASSERT_VK_SUCCESS(err);
16170
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016171 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016172 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016173 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016174 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016175 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016176 ASSERT_VK_SUCCESS(err);
16177
16178 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16179 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016180 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016181 ASSERT_VK_SUCCESS(err);
16182
16183 BeginCommandBuffer();
16184 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016185 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016186 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016187 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016188 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016189 copyRegion.srcOffset.x = 0;
16190 copyRegion.srcOffset.y = 0;
16191 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016192 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016193 copyRegion.dstSubresource.mipLevel = 0;
16194 copyRegion.dstSubresource.baseArrayLayer = 0;
16195 copyRegion.dstSubresource.layerCount = 0;
16196 copyRegion.dstOffset.x = 0;
16197 copyRegion.dstOffset.y = 0;
16198 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016199 copyRegion.extent.width = 1;
16200 copyRegion.extent.height = 1;
16201 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016202 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016203 EndCommandBuffer();
16204
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016205 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016206
Chia-I Wuf7458c52015-10-26 21:10:41 +080016207 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016208 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016209 vkFreeMemory(m_device->device(), srcMem, NULL);
16210 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016211}
16212
Karl Schultz6addd812016-02-02 17:17:23 -070016213TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16214 VkResult err;
16215 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016216
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16218 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016219
Mike Stroyana3082432015-09-25 13:39:21 -060016220 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016221
16222 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016223 VkImage srcImage;
16224 VkImage dstImage;
16225 VkDeviceMemory srcMem;
16226 VkDeviceMemory destMem;
16227 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016228
16229 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016230 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16231 image_create_info.pNext = NULL;
16232 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16233 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16234 image_create_info.extent.width = 32;
16235 image_create_info.extent.height = 1;
16236 image_create_info.extent.depth = 1;
16237 image_create_info.mipLevels = 1;
16238 image_create_info.arrayLayers = 1;
16239 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16240 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16241 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16242 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016243
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016244 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016245 ASSERT_VK_SUCCESS(err);
16246
Karl Schultz6addd812016-02-02 17:17:23 -070016247 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_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 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016280 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16281 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016282 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016283 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016284 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016285 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016286 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016287 resolveRegion.srcOffset.x = 0;
16288 resolveRegion.srcOffset.y = 0;
16289 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016290 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016291 resolveRegion.dstSubresource.mipLevel = 0;
16292 resolveRegion.dstSubresource.baseArrayLayer = 0;
16293 resolveRegion.dstSubresource.layerCount = 0;
16294 resolveRegion.dstOffset.x = 0;
16295 resolveRegion.dstOffset.y = 0;
16296 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016297 resolveRegion.extent.width = 1;
16298 resolveRegion.extent.height = 1;
16299 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016300 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016301 EndCommandBuffer();
16302
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016303 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016304
Chia-I Wuf7458c52015-10-26 21:10:41 +080016305 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016306 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016307 vkFreeMemory(m_device->device(), srcMem, NULL);
16308 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016309}
16310
Karl Schultz6addd812016-02-02 17:17:23 -070016311TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16312 VkResult err;
16313 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016314
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16316 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016317
Mike Stroyana3082432015-09-25 13:39:21 -060016318 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016319
Chris Forbesa7530692016-05-08 12:35:39 +120016320 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016321 VkImage srcImage;
16322 VkImage dstImage;
16323 VkDeviceMemory srcMem;
16324 VkDeviceMemory destMem;
16325 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016326
16327 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016328 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16329 image_create_info.pNext = NULL;
16330 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16331 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16332 image_create_info.extent.width = 32;
16333 image_create_info.extent.height = 1;
16334 image_create_info.extent.depth = 1;
16335 image_create_info.mipLevels = 1;
16336 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016337 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016338 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16339 // Note: Some implementations expect color attachment usage for any
16340 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016341 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016342 image_create_info.flags = 0;
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, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016345 ASSERT_VK_SUCCESS(err);
16346
Karl Schultz6addd812016-02-02 17:17:23 -070016347 // Note: Some implementations expect color attachment usage for any
16348 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016349 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016350
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016351 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016352 ASSERT_VK_SUCCESS(err);
16353
16354 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016355 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016356 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16357 memAlloc.pNext = NULL;
16358 memAlloc.allocationSize = 0;
16359 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016360
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016361 vkGetImageMemoryRequirements(m_device->device(), srcImage, &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, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016366 ASSERT_VK_SUCCESS(err);
16367
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016368 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016369 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016370 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016371 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016372 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016373 ASSERT_VK_SUCCESS(err);
16374
16375 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16376 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016377 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016378 ASSERT_VK_SUCCESS(err);
16379
16380 BeginCommandBuffer();
16381 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016382 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16383 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016384 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016385 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016386 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016387 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016388 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016389 resolveRegion.srcOffset.x = 0;
16390 resolveRegion.srcOffset.y = 0;
16391 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016392 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016393 resolveRegion.dstSubresource.mipLevel = 0;
16394 resolveRegion.dstSubresource.baseArrayLayer = 0;
16395 resolveRegion.dstSubresource.layerCount = 0;
16396 resolveRegion.dstOffset.x = 0;
16397 resolveRegion.dstOffset.y = 0;
16398 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016399 resolveRegion.extent.width = 1;
16400 resolveRegion.extent.height = 1;
16401 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016402 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016403 EndCommandBuffer();
16404
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016405 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016406
Chia-I Wuf7458c52015-10-26 21:10:41 +080016407 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016408 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016409 vkFreeMemory(m_device->device(), srcMem, NULL);
16410 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016411}
16412
Karl Schultz6addd812016-02-02 17:17:23 -070016413TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16414 VkResult err;
16415 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016416
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16418 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016419
Mike Stroyana3082432015-09-25 13:39:21 -060016420 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016421
16422 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016423 VkImage srcImage;
16424 VkImage dstImage;
16425 VkDeviceMemory srcMem;
16426 VkDeviceMemory destMem;
16427 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016428
16429 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016430 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16431 image_create_info.pNext = NULL;
16432 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16433 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16434 image_create_info.extent.width = 32;
16435 image_create_info.extent.height = 1;
16436 image_create_info.extent.depth = 1;
16437 image_create_info.mipLevels = 1;
16438 image_create_info.arrayLayers = 1;
16439 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16440 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16441 // Note: Some implementations expect color attachment usage for any
16442 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016443 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016444 image_create_info.flags = 0;
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, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016447 ASSERT_VK_SUCCESS(err);
16448
Karl Schultz6addd812016-02-02 17:17:23 -070016449 // Set format to something other than source image
16450 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16451 // Note: Some implementations expect color attachment usage for any
16452 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016453 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016454 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016455
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016456 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016457 ASSERT_VK_SUCCESS(err);
16458
16459 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016460 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016461 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16462 memAlloc.pNext = NULL;
16463 memAlloc.allocationSize = 0;
16464 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016465
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016466 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016467 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016468 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016469 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016470 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016471 ASSERT_VK_SUCCESS(err);
16472
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016473 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016474 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016475 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016476 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016477 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016478 ASSERT_VK_SUCCESS(err);
16479
16480 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16481 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016482 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016483 ASSERT_VK_SUCCESS(err);
16484
16485 BeginCommandBuffer();
16486 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016487 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16488 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016489 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016490 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016491 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016492 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016493 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016494 resolveRegion.srcOffset.x = 0;
16495 resolveRegion.srcOffset.y = 0;
16496 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016497 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016498 resolveRegion.dstSubresource.mipLevel = 0;
16499 resolveRegion.dstSubresource.baseArrayLayer = 0;
16500 resolveRegion.dstSubresource.layerCount = 0;
16501 resolveRegion.dstOffset.x = 0;
16502 resolveRegion.dstOffset.y = 0;
16503 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016504 resolveRegion.extent.width = 1;
16505 resolveRegion.extent.height = 1;
16506 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016507 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016508 EndCommandBuffer();
16509
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016510 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016511
Chia-I Wuf7458c52015-10-26 21:10:41 +080016512 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016513 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016514 vkFreeMemory(m_device->device(), srcMem, NULL);
16515 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016516}
16517
Karl Schultz6addd812016-02-02 17:17:23 -070016518TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
16519 VkResult err;
16520 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016521
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16523 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016524
Mike Stroyana3082432015-09-25 13:39:21 -060016525 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016526
16527 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016528 VkImage srcImage;
16529 VkImage dstImage;
16530 VkDeviceMemory srcMem;
16531 VkDeviceMemory destMem;
16532 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016533
16534 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016535 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16536 image_create_info.pNext = NULL;
16537 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16538 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16539 image_create_info.extent.width = 32;
16540 image_create_info.extent.height = 1;
16541 image_create_info.extent.depth = 1;
16542 image_create_info.mipLevels = 1;
16543 image_create_info.arrayLayers = 1;
16544 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16545 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
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_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016549 image_create_info.flags = 0;
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, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016552 ASSERT_VK_SUCCESS(err);
16553
Karl Schultz6addd812016-02-02 17:17:23 -070016554 image_create_info.imageType = VK_IMAGE_TYPE_1D;
16555 // Note: Some implementations expect color attachment usage for any
16556 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016557 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016558 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016559
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016560 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016561 ASSERT_VK_SUCCESS(err);
16562
16563 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016564 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016565 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16566 memAlloc.pNext = NULL;
16567 memAlloc.allocationSize = 0;
16568 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016569
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016570 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016571 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016572 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016573 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016574 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016575 ASSERT_VK_SUCCESS(err);
16576
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016577 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016578 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016579 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016580 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016581 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016582 ASSERT_VK_SUCCESS(err);
16583
16584 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16585 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016586 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016587 ASSERT_VK_SUCCESS(err);
16588
16589 BeginCommandBuffer();
16590 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016591 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16592 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016593 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016594 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016595 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016596 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016597 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016598 resolveRegion.srcOffset.x = 0;
16599 resolveRegion.srcOffset.y = 0;
16600 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016601 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016602 resolveRegion.dstSubresource.mipLevel = 0;
16603 resolveRegion.dstSubresource.baseArrayLayer = 0;
16604 resolveRegion.dstSubresource.layerCount = 0;
16605 resolveRegion.dstOffset.x = 0;
16606 resolveRegion.dstOffset.y = 0;
16607 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016608 resolveRegion.extent.width = 1;
16609 resolveRegion.extent.height = 1;
16610 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016611 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016612 EndCommandBuffer();
16613
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016614 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016615
Chia-I Wuf7458c52015-10-26 21:10:41 +080016616 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016617 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016618 vkFreeMemory(m_device->device(), srcMem, NULL);
16619 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016620}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016621
Karl Schultz6addd812016-02-02 17:17:23 -070016622TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016623 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016624 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16625 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016626 // The image format check comes 2nd in validation so we trigger it first,
16627 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016628 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016629
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16631 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016632
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016633 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016634
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016635 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016636 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16637 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016638
16639 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016640 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16641 ds_pool_ci.pNext = NULL;
16642 ds_pool_ci.maxSets = 1;
16643 ds_pool_ci.poolSizeCount = 1;
16644 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016645
16646 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016647 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016648 ASSERT_VK_SUCCESS(err);
16649
16650 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016651 dsl_binding.binding = 0;
16652 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16653 dsl_binding.descriptorCount = 1;
16654 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16655 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016656
16657 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016658 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16659 ds_layout_ci.pNext = NULL;
16660 ds_layout_ci.bindingCount = 1;
16661 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016662 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016663 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016664 ASSERT_VK_SUCCESS(err);
16665
16666 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016667 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080016668 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070016669 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016670 alloc_info.descriptorPool = ds_pool;
16671 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016672 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016673 ASSERT_VK_SUCCESS(err);
16674
Karl Schultz6addd812016-02-02 17:17:23 -070016675 VkImage image_bad;
16676 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016677 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060016678 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016679 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070016680 const int32_t tex_width = 32;
16681 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016682
16683 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016684 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16685 image_create_info.pNext = NULL;
16686 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16687 image_create_info.format = tex_format_bad;
16688 image_create_info.extent.width = tex_width;
16689 image_create_info.extent.height = tex_height;
16690 image_create_info.extent.depth = 1;
16691 image_create_info.mipLevels = 1;
16692 image_create_info.arrayLayers = 1;
16693 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16694 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016695 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016696 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016697
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016698 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016699 ASSERT_VK_SUCCESS(err);
16700 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016701 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16702 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016703 ASSERT_VK_SUCCESS(err);
16704
16705 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016706 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16707 image_view_create_info.image = image_bad;
16708 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16709 image_view_create_info.format = tex_format_bad;
16710 image_view_create_info.subresourceRange.baseArrayLayer = 0;
16711 image_view_create_info.subresourceRange.baseMipLevel = 0;
16712 image_view_create_info.subresourceRange.layerCount = 1;
16713 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016714 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016715
16716 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016717 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016718
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016719 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016720
Chia-I Wuf7458c52015-10-26 21:10:41 +080016721 vkDestroyImage(m_device->device(), image_bad, NULL);
16722 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016723 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16724 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016725}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016726
16727TEST_F(VkLayerTest, ClearImageErrors) {
16728 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
16729 "ClearDepthStencilImage with a color image.");
16730
16731 ASSERT_NO_FATAL_FAILURE(InitState());
16732 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16733
16734 // Renderpass is started here so end it as Clear cmds can't be in renderpass
16735 BeginCommandBuffer();
16736 m_commandBuffer->EndRenderPass();
16737
16738 // Color image
16739 VkClearColorValue clear_color;
16740 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
16741 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
16742 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
16743 const int32_t img_width = 32;
16744 const int32_t img_height = 32;
16745 VkImageCreateInfo image_create_info = {};
16746 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16747 image_create_info.pNext = NULL;
16748 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16749 image_create_info.format = color_format;
16750 image_create_info.extent.width = img_width;
16751 image_create_info.extent.height = img_height;
16752 image_create_info.extent.depth = 1;
16753 image_create_info.mipLevels = 1;
16754 image_create_info.arrayLayers = 1;
16755 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16756 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16757 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16758
16759 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016760 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016761
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016762 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016763
16764 // Depth/Stencil image
16765 VkClearDepthStencilValue clear_value = {0};
16766 reqs = 0; // don't need HOST_VISIBLE DS image
16767 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
16768 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
16769 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16770 ds_image_create_info.extent.width = 64;
16771 ds_image_create_info.extent.height = 64;
16772 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16773 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
16774
16775 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016776 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016777
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016778 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 -060016779
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016781
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016782 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016783 &color_range);
16784
16785 m_errorMonitor->VerifyFound();
16786
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
16788 "image created without "
16789 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060016790
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016791 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060016792 &color_range);
16793
16794 m_errorMonitor->VerifyFound();
16795
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016796 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16798 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016799
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016800 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
16801 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016802
16803 m_errorMonitor->VerifyFound();
16804}
Tobin Ehliscde08892015-09-22 10:11:37 -060016805#endif // IMAGE_TESTS
16806
Cody Northrop1242dfd2016-07-13 17:24:59 -060016807#if defined(ANDROID) && defined(VALIDATION_APK)
16808static bool initialized = false;
16809static bool active = false;
16810
16811// Convert Intents to argv
16812// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016813std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016814 std::vector<std::string> args;
16815 JavaVM &vm = *app.activity->vm;
16816 JNIEnv *p_env;
16817 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
16818 return args;
16819
16820 JNIEnv &env = *p_env;
16821 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016822 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060016823 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016824 jmethodID get_string_extra_method =
16825 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060016826 jvalue get_string_extra_args;
16827 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016828 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060016829
16830 std::string args_str;
16831 if (extra_str) {
16832 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
16833 args_str = extra_utf;
16834 env.ReleaseStringUTFChars(extra_str, extra_utf);
16835 env.DeleteLocalRef(extra_str);
16836 }
16837
16838 env.DeleteLocalRef(get_string_extra_args.l);
16839 env.DeleteLocalRef(intent);
16840 vm.DetachCurrentThread();
16841
16842 // split args_str
16843 std::stringstream ss(args_str);
16844 std::string arg;
16845 while (std::getline(ss, arg, ' ')) {
16846 if (!arg.empty())
16847 args.push_back(arg);
16848 }
16849
16850 return args;
16851}
16852
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016853static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060016854
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016855static void processCommand(struct android_app *app, int32_t cmd) {
16856 switch (cmd) {
16857 case APP_CMD_INIT_WINDOW: {
16858 if (app->window) {
16859 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060016860 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016861 break;
16862 }
16863 case APP_CMD_GAINED_FOCUS: {
16864 active = true;
16865 break;
16866 }
16867 case APP_CMD_LOST_FOCUS: {
16868 active = false;
16869 break;
16870 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060016871 }
16872}
16873
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016874void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016875 app_dummy();
16876
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016877 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060016878
16879 int vulkanSupport = InitVulkan();
16880 if (vulkanSupport == 0) {
16881 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
16882 return;
16883 }
16884
16885 app->onAppCmd = processCommand;
16886 app->onInputEvent = processInput;
16887
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016888 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016889 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016890 struct android_poll_source *source;
16891 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016892 if (source) {
16893 source->process(app, source);
16894 }
16895
16896 if (app->destroyRequested != 0) {
16897 VkTestFramework::Finish();
16898 return;
16899 }
16900 }
16901
16902 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016903 // Use the following key to send arguments to gtest, i.e.
16904 // --es args "--gtest_filter=-VkLayerTest.foo"
16905 const char key[] = "args";
16906 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060016907
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016908 std::string filter = "";
16909 if (args.size() > 0) {
16910 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
16911 filter += args[0];
16912 } else {
16913 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
16914 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060016915
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016916 int argc = 2;
16917 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
16918 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060016919
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016920 // Route output to files until we can override the gtest output
16921 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
16922 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060016923
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016924 ::testing::InitGoogleTest(&argc, argv);
16925 VkTestFramework::InitArgs(&argc, argv);
16926 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060016927
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016928 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060016929
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016930 if (result != 0) {
16931 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
16932 } else {
16933 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
16934 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060016935
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016936 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060016937
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016938 fclose(stdout);
16939 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060016940
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016941 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060016942
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016943 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060016944 }
16945 }
16946}
16947#endif
16948
Tony Barbour300a6082015-04-07 13:44:53 -060016949int main(int argc, char **argv) {
16950 int result;
16951
Cody Northrop8e54a402016-03-08 22:25:52 -070016952#ifdef ANDROID
16953 int vulkanSupport = InitVulkan();
16954 if (vulkanSupport == 0)
16955 return 1;
16956#endif
16957
Tony Barbour300a6082015-04-07 13:44:53 -060016958 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060016959 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060016960
16961 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
16962
16963 result = RUN_ALL_TESTS();
16964
Tony Barbour6918cd52015-04-09 12:58:51 -060016965 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060016966 return result;
16967}