blob: 0ea2e6962b6c39534ad870d4ab70b3e04ca59462 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
37#include "vkrenderframework.h"
Tony Barbour300a6082015-04-07 13:44:53 -060038
Mark Lobodzinski3780e142015-05-14 15:08:13 -050039#define GLM_FORCE_RADIANS
40#include "glm/glm.hpp"
41#include <glm/gtc/matrix_transform.hpp>
42
Dustin Gravesffa90fa2016-05-06 11:20:38 -060043#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060044#define MEM_TRACKER_TESTS 1
45#define OBJ_TRACKER_TESTS 1
46#define DRAW_STATE_TESTS 1
47#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120048#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060049#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060050#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060051
Mark Lobodzinski3780e142015-05-14 15:08:13 -050052//--------------------------------------------------------------------------------------
53// Mesh and VertexFormat Data
54//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070055struct Vertex {
56 float posX, posY, posZ, posW; // Position data
57 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050058};
59
Karl Schultz6addd812016-02-02 17:17:23 -070060#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061
62typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070063 BsoFailNone = 0x00000000,
64 BsoFailLineWidth = 0x00000001,
65 BsoFailDepthBias = 0x00000002,
66 BsoFailViewport = 0x00000004,
67 BsoFailScissor = 0x00000008,
68 BsoFailBlend = 0x00000010,
69 BsoFailDepthBounds = 0x00000020,
70 BsoFailStencilReadMask = 0x00000040,
71 BsoFailStencilWriteMask = 0x00000080,
72 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060073 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060074 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050075} BsoFailSelect;
76
77struct vktriangle_vs_uniform {
78 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070079 float mvp[4][4];
80 float position[3][4];
81 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050082};
83
Mark Lobodzinskice751c62016-09-08 10:45:35 -060084static const char bindStateVertShaderText[] = "#version 450\n"
85 "vec2 vertices[3];\n"
86 "out gl_PerVertex {\n"
87 " vec4 gl_Position;\n"
88 "};\n"
89 "void main() {\n"
90 " vertices[0] = vec2(-1.0, -1.0);\n"
91 " vertices[1] = vec2( 1.0, -1.0);\n"
92 " vertices[2] = vec2( 0.0, 1.0);\n"
93 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
94 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060096static const char bindStateFragShaderText[] = "#version 450\n"
97 "\n"
98 "layout(location = 0) out vec4 uFragColor;\n"
99 "void main(){\n"
100 " uFragColor = vec4(0,1,0,1);\n"
101 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500102
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600103static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
104 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
105 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600106
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600107// ********************************************************
108// ErrorMonitor Usage:
109//
110// Call SetDesiredFailureMsg with a string to be compared against all
111// encountered log messages. Passing NULL will match all log messages.
112// logMsg will return true for skipCall only if msg is matched or NULL.
113//
114// Call DesiredMsgFound to determine if the desired failure message
115// was encountered.
116
Tony Barbour300a6082015-04-07 13:44:53 -0600117class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700118 public:
119 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600120 test_platform_thread_create_mutex(&m_mutex);
121 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200122 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700123 m_bailout = NULL;
Chris Forbes17756132016-09-16 14:36:39 +1200124 m_desiredMsgSet = false;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600125 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600126 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600127
Dustin Graves48458142016-04-29 16:11:55 -0600128 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
129
Karl Schultz6addd812016-02-02 17:17:23 -0700130 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200131 // also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600132 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600133 m_failureMsg.clear();
134 m_otherMsgs.clear();
135 m_desiredMsg = msgString;
Karl Schultz6addd812016-02-02 17:17:23 -0700136 m_msgFound = VK_FALSE;
137 m_msgFlags = msgFlags;
Chris Forbes17756132016-09-16 14:36:39 +1200138 m_desiredMsgSet = true;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600139 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600140 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600141
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600142 VkBool32 CheckForDesiredMsg(const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600143 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600144 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600145 if (m_bailout != NULL) {
146 *m_bailout = true;
147 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600148 string errorString(msgString);
Chris Forbes17756132016-09-16 14:36:39 +1200149 if (m_desiredMsgSet && errorString.find(m_desiredMsg) != string::npos) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600150 if (m_msgFound) { // If multiple matches, don't lose all but the last!
151 m_otherMsgs.push_back(m_failureMsg);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600152 }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600153 m_failureMsg = errorString;
154 m_msgFound = VK_TRUE;
155 result = VK_TRUE;
156 } else {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200157 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600158 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600159 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600160 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600162 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600163
Karl Schultz6addd812016-02-02 17:17:23 -0700164 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600165
Karl Schultz6addd812016-02-02 17:17:23 -0700166 string GetFailureMsg(void) { return m_failureMsg; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600167
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600168 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
169
Karl Schultz6addd812016-02-02 17:17:23 -0700170 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600171
Karl Schultz6addd812016-02-02 17:17:23 -0700172 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600173
Karl Schultz6addd812016-02-02 17:17:23 -0700174 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600175 vector<string> otherMsgs = GetOtherFailureMsgs();
176 cout << "Other error messages logged for this test were:" << endl;
177 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
178 cout << " " << *iter << endl;
179 }
180 }
181
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600182 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200183
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600184 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
185 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
186 m_msgFlags = message_flag_mask;
187 // Match ANY message matching specified type
188 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200189 }
190
191 void VerifyFound() {
192 // Not seeing the desired message is a failure. /Before/ throwing, dump
193 // any other messages.
194 if (!DesiredMsgFound()) {
195 DumpFailureMsgs();
196 FAIL() << "Did not receive expected error '" << m_desiredMsg << "'";
197 }
198 }
199
200 void VerifyNotFound() {
201 // ExpectSuccess() configured us to match anything. Any error is a
202 // failure.
203 if (DesiredMsgFound()) {
204 DumpFailureMsgs();
205 FAIL() << "Expected to succeed but got error: " << GetFailureMsg();
206 }
207 }
208
Karl Schultz6addd812016-02-02 17:17:23 -0700209 private:
210 VkFlags m_msgFlags;
211 string m_desiredMsg;
212 string m_failureMsg;
213 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600214 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700215 bool *m_bailout;
216 VkBool32 m_msgFound;
Chris Forbes17756132016-09-16 14:36:39 +1200217 bool m_desiredMsgSet;
Tony Barbour300a6082015-04-07 13:44:53 -0600218};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500219
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600220static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
221 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
222 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600223 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
224 if (msgFlags & errMonitor->GetMessageFlags()) {
225 return errMonitor->CheckForDesiredMsg(pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600226 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600227 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600228}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500229
Karl Schultz6addd812016-02-02 17:17:23 -0700230class VkLayerTest : public VkRenderFramework {
231 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800232 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
233 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600234 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
235 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700236 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600237 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
238 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700239 }
Tony Barbour300a6082015-04-07 13:44:53 -0600240
Tony Barbourfe3351b2015-07-28 10:17:20 -0600241 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600242 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800243 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600244 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
245 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700246 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600247 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700248 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600249 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700250 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600251 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
252 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
253 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700254 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
255 }
256 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
257 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
258 }
259
260 protected:
261 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600262 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600263
264 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600265 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600266 std::vector<const char *> instance_extension_names;
267 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600268
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700269 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600270 /*
271 * Since CreateDbgMsgCallback is an instance level extension call
272 * any extension / layer that utilizes that feature also needs
273 * to be enabled at create instance time.
274 */
Karl Schultz6addd812016-02-02 17:17:23 -0700275 // Use Threading layer first to protect others from
276 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700277 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600278 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800279 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700280 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800281 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600282 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700283 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600284
Ian Elliott2c1daf52016-05-12 09:41:46 -0600285 if (m_enableWSI) {
286 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
287 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
288#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
289#if defined(VK_USE_PLATFORM_ANDROID_KHR)
290 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
291#endif // VK_USE_PLATFORM_ANDROID_KHR
292#if defined(VK_USE_PLATFORM_MIR_KHR)
293 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
294#endif // VK_USE_PLATFORM_MIR_KHR
295#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
296 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
297#endif // VK_USE_PLATFORM_WAYLAND_KHR
298#if defined(VK_USE_PLATFORM_WIN32_KHR)
299 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
300#endif // VK_USE_PLATFORM_WIN32_KHR
301#endif // NEED_TO_TEST_THIS_ON_PLATFORM
302#if defined(VK_USE_PLATFORM_XCB_KHR)
303 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
304#elif defined(VK_USE_PLATFORM_XLIB_KHR)
305 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
306#endif // VK_USE_PLATFORM_XLIB_KHR
307 }
308
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600309 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600310 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800311 this->app_info.pApplicationName = "layer_tests";
312 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600313 this->app_info.pEngineName = "unittest";
314 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600315 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600316
Tony Barbour15524c32015-04-29 17:34:29 -0600317 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600318 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600319 }
320
321 virtual void TearDown() {
322 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600323 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600324 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600325 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600326
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600327 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600328};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500329
Karl Schultz6addd812016-02-02 17:17:23 -0700330VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600331 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600332
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800333 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600334
335 /*
336 * For render test all drawing happens in a single render pass
337 * on a single command buffer.
338 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200339 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800340 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600341 }
342
343 return result;
344}
345
Karl Schultz6addd812016-02-02 17:17:23 -0700346VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600347 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600348
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200349 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800350 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200351 }
Tony Barbour300a6082015-04-07 13:44:53 -0600352
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800353 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600354
355 return result;
356}
357
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600358void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500359 // Create identity matrix
360 int i;
361 struct vktriangle_vs_uniform data;
362
363 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700364 glm::mat4 View = glm::mat4(1.0f);
365 glm::mat4 Model = glm::mat4(1.0f);
366 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500367 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700368 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500369
370 memcpy(&data.mvp, &MVP[0][0], matrixSize);
371
Karl Schultz6addd812016-02-02 17:17:23 -0700372 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600373 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500374 };
375
Karl Schultz6addd812016-02-02 17:17:23 -0700376 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500377 data.position[i][0] = tri_data[i].posX;
378 data.position[i][1] = tri_data[i].posY;
379 data.position[i][2] = tri_data[i].posZ;
380 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700381 data.color[i][0] = tri_data[i].r;
382 data.color[i][1] = tri_data[i].g;
383 data.color[i][2] = tri_data[i].b;
384 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500385 }
386
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500387 ASSERT_NO_FATAL_FAILURE(InitViewport());
388
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200389 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
390 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500391
Karl Schultz6addd812016-02-02 17:17:23 -0700392 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600393 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500394
395 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800396 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500397 pipelineobj.AddShader(&vs);
398 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600399 if (failMask & BsoFailLineWidth) {
400 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600401 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600402 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600403 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
404 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600405 }
406 if (failMask & BsoFailDepthBias) {
407 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600408 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600409 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600410 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600411 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600412 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600413 }
Karl Schultz6addd812016-02-02 17:17:23 -0700414 // Viewport and scissors must stay in synch or other errors will occur than
415 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600416 if (failMask & BsoFailViewport) {
417 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
418 }
419 if (failMask & BsoFailScissor) {
420 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
421 }
422 if (failMask & BsoFailBlend) {
423 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600424 VkPipelineColorBlendAttachmentState att_state = {};
425 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
426 att_state.blendEnable = VK_TRUE;
427 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600428 }
429 if (failMask & BsoFailDepthBounds) {
430 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
431 }
432 if (failMask & BsoFailStencilReadMask) {
433 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
434 }
435 if (failMask & BsoFailStencilWriteMask) {
436 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
437 }
438 if (failMask & BsoFailStencilReference) {
439 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
440 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500441
442 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600443 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500444
445 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600446 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Tony Barbourfe3351b2015-07-28 10:17:20 -0600448 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500449
450 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600451 if (failMask & BsoFailIndexBuffer) {
452 // Use DrawIndexed w/o an index buffer bound
453 DrawIndexed(3, 1, 0, 0, 0);
454 } else {
455 Draw(3, 1, 0, 0);
456 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457
Mark Muellerd4914412016-06-13 17:52:06 -0600458 if (failMask & BsoFailCmdClearAttachments) {
459 VkClearAttachment color_attachment = {};
460 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
461 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
462 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
463
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600464 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600465 }
466
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500467 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600468 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500469
Tony Barbourfe3351b2015-07-28 10:17:20 -0600470 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500471}
472
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600473void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
474 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500475 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600476 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500477 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600478 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500479 }
480
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800481 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700482 // Make sure depthWriteEnable is set so that Depth fail test will work
483 // correctly
484 // Make sure stencilTestEnable is set so that Stencil fail test will work
485 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600486 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800487 stencil.failOp = VK_STENCIL_OP_KEEP;
488 stencil.passOp = VK_STENCIL_OP_KEEP;
489 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
490 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600491
492 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
493 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600494 ds_ci.pNext = NULL;
495 ds_ci.depthTestEnable = VK_FALSE;
496 ds_ci.depthWriteEnable = VK_TRUE;
497 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
498 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600499 if (failMask & BsoFailDepthBounds) {
500 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600501 ds_ci.maxDepthBounds = 0.0f;
502 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600503 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600504 ds_ci.stencilTestEnable = VK_TRUE;
505 ds_ci.front = stencil;
506 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600507
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600508 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600509 pipelineobj.SetViewport(m_viewports);
510 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800511 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600512 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600513 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800514 commandBuffer->BindPipeline(pipelineobj);
515 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516}
517
Ian Elliott2c1daf52016-05-12 09:41:46 -0600518class VkWsiEnabledLayerTest : public VkLayerTest {
519 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600520 protected:
521 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600522};
523
Mark Muellerdfe37552016-07-07 14:47:42 -0600524class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600525 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600526 enum eTestEnFlags {
527 eDoubleDelete,
528 eInvalidDeviceOffset,
529 eInvalidMemoryOffset,
530 eBindNullBuffer,
531 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600532 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600533 };
534
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600535 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600536
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600537 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
538 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600539 return true;
540 }
541 VkDeviceSize offset_limit = 0;
542 if (eInvalidMemoryOffset == aTestFlag) {
543 VkBuffer vulkanBuffer;
544 VkBufferCreateInfo buffer_create_info = {};
545 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
546 buffer_create_info.size = 32;
547 buffer_create_info.usage = aBufferUsage;
548
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600549 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600550 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600551
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600552 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600553 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
554 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600555 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
556 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600557 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600558 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600559 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600560 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600561 }
562 if (eOffsetAlignment < offset_limit) {
563 return true;
564 }
565 return false;
566 }
567
568 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600569 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
570 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600571
572 if (eBindNullBuffer == aTestFlag) {
573 VulkanMemory = 0;
574 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
575 } else {
576 VkBufferCreateInfo buffer_create_info = {};
577 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
578 buffer_create_info.size = 32;
579 buffer_create_info.usage = aBufferUsage;
580
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600581 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600582
583 CreateCurrent = true;
584
585 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600586 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600587
588 VkMemoryAllocateInfo memory_allocate_info = {};
589 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
590 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600591 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
592 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600593 if (!pass) {
594 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
595 return;
596 }
597
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600598 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600599 AllocateCurrent = true;
600 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600601 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
602 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600603 BoundCurrent = true;
604
605 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
606 }
607 }
608
609 ~VkBufferTest() {
610 if (CreateCurrent) {
611 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
612 }
613 if (AllocateCurrent) {
614 if (InvalidDeleteEn) {
615 union {
616 VkDeviceMemory device_memory;
617 unsigned long long index_access;
618 } bad_index;
619
620 bad_index.device_memory = VulkanMemory;
621 bad_index.index_access++;
622
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600623 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600624 }
625 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
626 }
627 }
628
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600629 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600630
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600631 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
633 void TestDoubleDestroy() {
634 // Destroy the buffer but leave the flag set, which will cause
635 // the buffer to be destroyed again in the destructor.
636 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
637 }
638
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600639 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600640 bool AllocateCurrent;
641 bool BoundCurrent;
642 bool CreateCurrent;
643 bool InvalidDeleteEn;
644
645 VkBuffer VulkanBuffer;
646 VkDevice VulkanDevice;
647 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600648};
649
650class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600651 public:
652 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600653 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600654 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600655 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600656 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
657 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600658 BindIdGenerator++; // NB: This can wrap w/misuse
659
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600660 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
661 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600662
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600663 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
664 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
665 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
666 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
667 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600668
669 unsigned i = 0;
670 do {
671 VertexInputAttributeDescription[i].binding = BindId;
672 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600673 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
674 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600675 i++;
676 } while (AttributeCount < i);
677
678 i = 0;
679 do {
680 VertexInputBindingDescription[i].binding = BindId;
681 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600682 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600683 i++;
684 } while (BindingCount < i);
685 }
686
687 ~VkVerticesObj() {
688 if (VertexInputAttributeDescription) {
689 delete[] VertexInputAttributeDescription;
690 }
691 if (VertexInputBindingDescription) {
692 delete[] VertexInputBindingDescription;
693 }
694 }
695
696 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600697 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
698 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600699 return true;
700 }
701
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600702 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600703 VkDeviceSize *offsetList;
704 unsigned offsetCount;
705
706 if (aOffsetCount) {
707 offsetList = aOffsetList;
708 offsetCount = aOffsetCount;
709 } else {
710 offsetList = new VkDeviceSize[1]();
711 offsetCount = 1;
712 }
713
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600714 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600715 BoundCurrent = true;
716
717 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 }
720 }
721
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600722 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600723 static uint32_t BindIdGenerator;
724
725 bool BoundCurrent;
726 unsigned AttributeCount;
727 unsigned BindingCount;
728 uint32_t BindId;
729
730 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
731 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
732 VkVertexInputBindingDescription *VertexInputBindingDescription;
733 VkConstantBufferObj VulkanMemoryBuffer;
734};
735
736uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500737// ********************************************************************************************************************
738// ********************************************************************************************************************
739// ********************************************************************************************************************
740// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600741#if PARAMETER_VALIDATION_TESTS
742TEST_F(VkLayerTest, RequiredParameter) {
743 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
744 "pointer, array, and array count parameters");
745
746 ASSERT_NO_FATAL_FAILURE(InitState());
747
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600749 // Specify NULL for a pointer to a handle
750 // Expected to trigger an error with
751 // parameter_validation::validate_required_pointer
752 vkGetPhysicalDeviceFeatures(gpu(), NULL);
753 m_errorMonitor->VerifyFound();
754
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
756 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600757 // Specify NULL for pointer to array count
758 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600759 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600760 m_errorMonitor->VerifyFound();
761
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600763 // Specify 0 for a required array count
764 // Expected to trigger an error with parameter_validation::validate_array
765 VkViewport view_port = {};
766 m_commandBuffer->SetViewport(0, 0, &view_port);
767 m_errorMonitor->VerifyFound();
768
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600770 // Specify NULL for a required array
771 // Expected to trigger an error with parameter_validation::validate_array
772 m_commandBuffer->SetViewport(0, 1, NULL);
773 m_errorMonitor->VerifyFound();
774
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600776 // Specify VK_NULL_HANDLE for a required handle
777 // Expected to trigger an error with
778 // parameter_validation::validate_required_handle
779 vkUnmapMemory(device(), VK_NULL_HANDLE);
780 m_errorMonitor->VerifyFound();
781
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
783 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600784 // Specify VK_NULL_HANDLE for a required handle array entry
785 // Expected to trigger an error with
786 // parameter_validation::validate_required_handle_array
787 VkFence fence = VK_NULL_HANDLE;
788 vkResetFences(device(), 1, &fence);
789 m_errorMonitor->VerifyFound();
790
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600792 // Specify NULL for a required struct pointer
793 // Expected to trigger an error with
794 // parameter_validation::validate_struct_type
795 VkDeviceMemory memory = VK_NULL_HANDLE;
796 vkAllocateMemory(device(), NULL, NULL, &memory);
797 m_errorMonitor->VerifyFound();
798
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600800 // Specify 0 for a required VkFlags parameter
801 // Expected to trigger an error with parameter_validation::validate_flags
802 m_commandBuffer->SetStencilReference(0, 0);
803 m_errorMonitor->VerifyFound();
804
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600806 // Specify 0 for a required VkFlags array entry
807 // Expected to trigger an error with
808 // parameter_validation::validate_flags_array
809 VkSemaphore semaphore = VK_NULL_HANDLE;
810 VkPipelineStageFlags stageFlags = 0;
811 VkSubmitInfo submitInfo = {};
812 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
813 submitInfo.waitSemaphoreCount = 1;
814 submitInfo.pWaitSemaphores = &semaphore;
815 submitInfo.pWaitDstStageMask = &stageFlags;
816 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
817 m_errorMonitor->VerifyFound();
818}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600819
Dustin Gravesfce74c02016-05-10 11:42:58 -0600820TEST_F(VkLayerTest, ReservedParameter) {
821 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
822
823 ASSERT_NO_FATAL_FAILURE(InitState());
824
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600826 // Specify 0 for a reserved VkFlags parameter
827 // Expected to trigger an error with
828 // parameter_validation::validate_reserved_flags
829 VkEvent event_handle = VK_NULL_HANDLE;
830 VkEventCreateInfo event_info = {};
831 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
832 event_info.flags = 1;
833 vkCreateEvent(device(), &event_info, NULL, &event_handle);
834 m_errorMonitor->VerifyFound();
835}
836
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600837TEST_F(VkLayerTest, InvalidStructSType) {
838 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
839 "structure's sType field");
840
841 ASSERT_NO_FATAL_FAILURE(InitState());
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600844 // Zero struct memory, effectively setting sType to
845 // VK_STRUCTURE_TYPE_APPLICATION_INFO
846 // Expected to trigger an error with
847 // parameter_validation::validate_struct_type
848 VkMemoryAllocateInfo alloc_info = {};
849 VkDeviceMemory memory = VK_NULL_HANDLE;
850 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
851 m_errorMonitor->VerifyFound();
852
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600854 // Zero struct memory, effectively setting sType to
855 // VK_STRUCTURE_TYPE_APPLICATION_INFO
856 // Expected to trigger an error with
857 // parameter_validation::validate_struct_type_array
858 VkSubmitInfo submit_info = {};
859 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
860 m_errorMonitor->VerifyFound();
861}
862
863TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600864 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600865
866 ASSERT_NO_FATAL_FAILURE(InitState());
867
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600869 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
Karl Schultz38b50992016-07-11 16:09:09 -0600870 // NULL.
871 // Need to pick a function that has no allowed pNext structure types.
872 // Expected to trigger an error with
873 // parameter_validation::validate_struct_pnext
874 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600875 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600876 // Zero-initialization will provide the correct sType
877 VkApplicationInfo app_info = {};
878 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
879 event_alloc_info.pNext = &app_info;
880 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
881 m_errorMonitor->VerifyFound();
882
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
884 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600885 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
886 // a function that has allowed pNext structure types and specify
887 // a structure type that is not allowed.
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600888 // Expected to trigger an error with
889 // parameter_validation::validate_struct_pnext
890 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600891 VkMemoryAllocateInfo memory_alloc_info = {};
892 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
893 memory_alloc_info.pNext = &app_info;
894 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600895 m_errorMonitor->VerifyFound();
896
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600897 // Positive test to check parameter_validation and unique_objects support
898 // for NV_dedicated_allocation
899 uint32_t extension_count = 0;
900 bool supports_nv_dedicated_allocation = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600901 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600902 ASSERT_VK_SUCCESS(err);
903
904 if (extension_count > 0) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600905 std::vector<VkExtensionProperties> available_extensions(extension_count);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600906
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600907 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600908 ASSERT_VK_SUCCESS(err);
909
910 for (const auto &extension_props : available_extensions) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600911 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600912 supports_nv_dedicated_allocation = true;
913 }
914 }
915 }
916
917 if (supports_nv_dedicated_allocation) {
918 m_errorMonitor->ExpectSuccess();
919
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600920 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
921 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600922 dedicated_buffer_create_info.pNext = nullptr;
923 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
924
925 uint32_t queue_family_index = 0;
926 VkBufferCreateInfo buffer_create_info = {};
927 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
928 buffer_create_info.pNext = &dedicated_buffer_create_info;
929 buffer_create_info.size = 1024;
930 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
931 buffer_create_info.queueFamilyIndexCount = 1;
932 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
933
934 VkBuffer buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600935 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600936 ASSERT_VK_SUCCESS(err);
937
938 VkMemoryRequirements memory_reqs;
939 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
940
941 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600943 dedicated_memory_info.pNext = nullptr;
944 dedicated_memory_info.buffer = buffer;
945 dedicated_memory_info.image = VK_NULL_HANDLE;
946
947 VkMemoryAllocateInfo memory_info = {};
948 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
949 memory_info.pNext = &dedicated_memory_info;
950 memory_info.allocationSize = memory_reqs.size;
951
952 bool pass;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600953 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600954 ASSERT_TRUE(pass);
955
956 VkDeviceMemory buffer_memory;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600957 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600958 ASSERT_VK_SUCCESS(err);
959
960 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
961 ASSERT_VK_SUCCESS(err);
962
963 vkDestroyBuffer(m_device->device(), buffer, NULL);
964 vkFreeMemory(m_device->device(), buffer_memory, NULL);
965
966 m_errorMonitor->VerifyNotFound();
967 }
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600968}
Dustin Graves5d33d532016-05-09 16:21:12 -0600969
970TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972
973 ASSERT_NO_FATAL_FAILURE(InitState());
974
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
976 "range of the core VkFormat "
977 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600978 // Specify an invalid VkFormat value
979 // Expected to trigger an error with
980 // parameter_validation::validate_ranged_enum
981 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600982 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600983 m_errorMonitor->VerifyFound();
984
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600986 // Specify an invalid VkFlags bitmask value
987 // Expected to trigger an error with parameter_validation::validate_flags
988 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600989 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
990 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600991 m_errorMonitor->VerifyFound();
992
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600994 // Specify an invalid VkFlags array entry
995 // Expected to trigger an error with
996 // parameter_validation::validate_flags_array
997 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600998 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600999 VkSubmitInfo submit_info = {};
1000 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1001 submit_info.waitSemaphoreCount = 1;
1002 submit_info.pWaitSemaphores = &semaphore;
1003 submit_info.pWaitDstStageMask = &stage_flags;
1004 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1005 m_errorMonitor->VerifyFound();
1006
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001008 // Specify an invalid VkBool32 value
1009 // Expected to trigger a warning with
1010 // parameter_validation::validate_bool32
1011 VkSampler sampler = VK_NULL_HANDLE;
1012 VkSamplerCreateInfo sampler_info = {};
1013 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1014 sampler_info.pNext = NULL;
1015 sampler_info.magFilter = VK_FILTER_NEAREST;
1016 sampler_info.minFilter = VK_FILTER_NEAREST;
1017 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1018 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1019 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1020 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1021 sampler_info.mipLodBias = 1.0;
1022 sampler_info.maxAnisotropy = 1;
1023 sampler_info.compareEnable = VK_FALSE;
1024 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1025 sampler_info.minLod = 1.0;
1026 sampler_info.maxLod = 1.0;
1027 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1028 sampler_info.unnormalizedCoordinates = VK_FALSE;
1029 // Not VK_TRUE or VK_FALSE
1030 sampler_info.anisotropyEnable = 3;
1031 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1032 m_errorMonitor->VerifyFound();
1033}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001034
1035TEST_F(VkLayerTest, FailedReturnValue) {
1036 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1037
1038 ASSERT_NO_FATAL_FAILURE(InitState());
1039
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001040 // Find an unsupported image format
1041 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1042 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1043 VkFormat format = static_cast<VkFormat>(f);
1044 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001045 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001046 unsupported = format;
1047 break;
1048 }
1049 }
1050
1051 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1053 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001054 // Specify an unsupported VkFormat value to generate a
1055 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1056 // Expected to trigger a warning from
1057 // parameter_validation::validate_result
1058 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001059 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1060 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001061 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1062 m_errorMonitor->VerifyFound();
1063 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001064}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001065
1066TEST_F(VkLayerTest, UpdateBufferAlignment) {
1067 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001068 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001069
1070 ASSERT_NO_FATAL_FAILURE(InitState());
1071
1072 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1073 vk_testing::Buffer buffer;
1074 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1075
1076 BeginCommandBuffer();
1077 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001079 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1080 m_errorMonitor->VerifyFound();
1081
1082 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001084 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1085 m_errorMonitor->VerifyFound();
1086
1087 // Introduce failure by using dataSize that is < 0
1088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001089 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001090 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1091 m_errorMonitor->VerifyFound();
1092
1093 // Introduce failure by using dataSize that is > 65536
1094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001095 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001096 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1097 m_errorMonitor->VerifyFound();
1098
1099 EndCommandBuffer();
1100}
1101
1102TEST_F(VkLayerTest, FillBufferAlignment) {
1103 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1104
1105 ASSERT_NO_FATAL_FAILURE(InitState());
1106
1107 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1108 vk_testing::Buffer buffer;
1109 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1110
1111 BeginCommandBuffer();
1112
1113 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001115 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1116 m_errorMonitor->VerifyFound();
1117
1118 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001120 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1121 m_errorMonitor->VerifyFound();
1122
1123 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001125 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1126 m_errorMonitor->VerifyFound();
1127
1128 EndCommandBuffer();
1129}
Dustin Graves40f35822016-06-23 11:12:53 -06001130
1131// This is a positive test. No failures are expected.
1132TEST_F(VkLayerTest, IgnoreUnrelatedDescriptor) {
1133 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSet validation code "
1134 "is ignoring VkWriteDescriptorSet members that are not "
1135 "related to the descriptor type specified by "
1136 "VkWriteDescriptorSet::descriptorType. Correct "
1137 "validation behavior will result in the test running to "
1138 "completion without validation errors.");
1139
Dustin Graves5e2d8fc2016-07-07 16:18:49 -06001140 const uintptr_t invalid_ptr = 0xcdcdcdcd;
1141
Dustin Graves40f35822016-06-23 11:12:53 -06001142 ASSERT_NO_FATAL_FAILURE(InitState());
1143
1144 // Image Case
1145 {
1146 m_errorMonitor->ExpectSuccess();
1147
1148 VkImage image;
1149 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1150 const int32_t tex_width = 32;
1151 const int32_t tex_height = 32;
1152 VkImageCreateInfo image_create_info = {};
1153 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1154 image_create_info.pNext = NULL;
1155 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1156 image_create_info.format = tex_format;
1157 image_create_info.extent.width = tex_width;
1158 image_create_info.extent.height = tex_height;
1159 image_create_info.extent.depth = 1;
1160 image_create_info.mipLevels = 1;
1161 image_create_info.arrayLayers = 1;
1162 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis51cde412016-07-11 16:08:30 -06001163 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Dustin Graves40f35822016-06-23 11:12:53 -06001164 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1165 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001166 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Dustin Graves40f35822016-06-23 11:12:53 -06001167 ASSERT_VK_SUCCESS(err);
1168
1169 VkMemoryRequirements memory_reqs;
1170 VkDeviceMemory image_memory;
1171 bool pass;
1172 VkMemoryAllocateInfo memory_info = {};
1173 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1174 memory_info.pNext = NULL;
1175 memory_info.allocationSize = 0;
1176 memory_info.memoryTypeIndex = 0;
1177 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
1178 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001179 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001180 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001181 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001182 ASSERT_VK_SUCCESS(err);
1183 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
1184 ASSERT_VK_SUCCESS(err);
1185
1186 VkImageViewCreateInfo image_view_create_info = {};
1187 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1188 image_view_create_info.image = image;
1189 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
1190 image_view_create_info.format = tex_format;
1191 image_view_create_info.subresourceRange.layerCount = 1;
1192 image_view_create_info.subresourceRange.baseMipLevel = 0;
1193 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001194 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dustin Graves40f35822016-06-23 11:12:53 -06001195
1196 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001197 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Dustin Graves40f35822016-06-23 11:12:53 -06001198 ASSERT_VK_SUCCESS(err);
1199
1200 VkDescriptorPoolSize ds_type_count = {};
1201 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1202 ds_type_count.descriptorCount = 1;
1203
1204 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1205 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1206 ds_pool_ci.pNext = NULL;
1207 ds_pool_ci.maxSets = 1;
1208 ds_pool_ci.poolSizeCount = 1;
1209 ds_pool_ci.pPoolSizes = &ds_type_count;
1210
1211 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001212 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001213 ASSERT_VK_SUCCESS(err);
1214
1215 VkDescriptorSetLayoutBinding dsl_binding = {};
1216 dsl_binding.binding = 0;
1217 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1218 dsl_binding.descriptorCount = 1;
1219 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1220 dsl_binding.pImmutableSamplers = NULL;
1221
1222 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001223 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001224 ds_layout_ci.pNext = NULL;
1225 ds_layout_ci.bindingCount = 1;
1226 ds_layout_ci.pBindings = &dsl_binding;
1227 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001228 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001229 ASSERT_VK_SUCCESS(err);
1230
1231 VkDescriptorSet descriptor_set;
1232 VkDescriptorSetAllocateInfo alloc_info = {};
1233 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1234 alloc_info.descriptorSetCount = 1;
1235 alloc_info.descriptorPool = ds_pool;
1236 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001237 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001238 ASSERT_VK_SUCCESS(err);
1239
1240 VkDescriptorImageInfo image_info = {};
1241 image_info.imageView = view;
1242 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
1243
1244 VkWriteDescriptorSet descriptor_write;
1245 memset(&descriptor_write, 0, sizeof(descriptor_write));
1246 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1247 descriptor_write.dstSet = descriptor_set;
1248 descriptor_write.dstBinding = 0;
1249 descriptor_write.descriptorCount = 1;
1250 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1251 descriptor_write.pImageInfo = &image_info;
1252
1253 // Set pBufferInfo and pTexelBufferView to invalid values, which should
1254 // be
1255 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
1256 // This will most likely produce a crash if the parameter_validation
1257 // layer
1258 // does not correctly ignore pBufferInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001259 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
1260 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001261
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001262 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001263
1264 m_errorMonitor->VerifyNotFound();
1265
Dustin Graves40f35822016-06-23 11:12:53 -06001266 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1267 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1268 vkDestroyImageView(m_device->device(), view, NULL);
1269 vkDestroyImage(m_device->device(), image, NULL);
1270 vkFreeMemory(m_device->device(), image_memory, NULL);
1271 }
1272
1273 // Buffer Case
1274 {
1275 m_errorMonitor->ExpectSuccess();
1276
1277 VkBuffer buffer;
1278 uint32_t queue_family_index = 0;
1279 VkBufferCreateInfo buffer_create_info = {};
1280 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1281 buffer_create_info.size = 1024;
1282 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1283 buffer_create_info.queueFamilyIndexCount = 1;
1284 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
1285
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001286 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Graves40f35822016-06-23 11:12:53 -06001287 ASSERT_VK_SUCCESS(err);
1288
1289 VkMemoryRequirements memory_reqs;
1290 VkDeviceMemory buffer_memory;
1291 bool pass;
1292 VkMemoryAllocateInfo memory_info = {};
1293 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1294 memory_info.pNext = NULL;
1295 memory_info.allocationSize = 0;
1296 memory_info.memoryTypeIndex = 0;
1297
1298 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
1299 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001300 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001301 ASSERT_TRUE(pass);
1302
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001303 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001304 ASSERT_VK_SUCCESS(err);
1305 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
1306 ASSERT_VK_SUCCESS(err);
1307
1308 VkDescriptorPoolSize ds_type_count = {};
1309 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1310 ds_type_count.descriptorCount = 1;
1311
1312 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1313 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1314 ds_pool_ci.pNext = NULL;
1315 ds_pool_ci.maxSets = 1;
1316 ds_pool_ci.poolSizeCount = 1;
1317 ds_pool_ci.pPoolSizes = &ds_type_count;
1318
1319 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001320 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001321 ASSERT_VK_SUCCESS(err);
1322
1323 VkDescriptorSetLayoutBinding dsl_binding = {};
1324 dsl_binding.binding = 0;
1325 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1326 dsl_binding.descriptorCount = 1;
1327 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1328 dsl_binding.pImmutableSamplers = NULL;
1329
1330 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001331 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001332 ds_layout_ci.pNext = NULL;
1333 ds_layout_ci.bindingCount = 1;
1334 ds_layout_ci.pBindings = &dsl_binding;
1335 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001336 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001337 ASSERT_VK_SUCCESS(err);
1338
1339 VkDescriptorSet descriptor_set;
1340 VkDescriptorSetAllocateInfo alloc_info = {};
1341 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1342 alloc_info.descriptorSetCount = 1;
1343 alloc_info.descriptorPool = ds_pool;
1344 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001345 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001346 ASSERT_VK_SUCCESS(err);
1347
1348 VkDescriptorBufferInfo buffer_info = {};
1349 buffer_info.buffer = buffer;
1350 buffer_info.offset = 0;
1351 buffer_info.range = 1024;
1352
1353 VkWriteDescriptorSet descriptor_write;
1354 memset(&descriptor_write, 0, sizeof(descriptor_write));
1355 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1356 descriptor_write.dstSet = descriptor_set;
1357 descriptor_write.dstBinding = 0;
1358 descriptor_write.descriptorCount = 1;
1359 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1360 descriptor_write.pBufferInfo = &buffer_info;
1361
1362 // Set pImageInfo and pTexelBufferView to invalid values, which should
1363 // be
1364 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
1365 // This will most likely produce a crash if the parameter_validation
1366 // layer
1367 // does not correctly ignore pImageInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001368 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
1369 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001370
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001371 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001372
1373 m_errorMonitor->VerifyNotFound();
1374
1375 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
1376 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1377 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1378 vkDestroyBuffer(m_device->device(), buffer, NULL);
1379 vkFreeMemory(m_device->device(), buffer_memory, NULL);
1380 }
1381
1382 // Texel Buffer Case
1383 {
1384 m_errorMonitor->ExpectSuccess();
1385
1386 VkBuffer buffer;
1387 uint32_t queue_family_index = 0;
1388 VkBufferCreateInfo buffer_create_info = {};
1389 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1390 buffer_create_info.size = 1024;
1391 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
1392 buffer_create_info.queueFamilyIndexCount = 1;
1393 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
1394
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001395 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Graves40f35822016-06-23 11:12:53 -06001396 ASSERT_VK_SUCCESS(err);
1397
1398 VkMemoryRequirements memory_reqs;
1399 VkDeviceMemory buffer_memory;
1400 bool pass;
1401 VkMemoryAllocateInfo memory_info = {};
1402 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1403 memory_info.pNext = NULL;
1404 memory_info.allocationSize = 0;
1405 memory_info.memoryTypeIndex = 0;
1406
1407 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
1408 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001409 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001410 ASSERT_TRUE(pass);
1411
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001412 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001413 ASSERT_VK_SUCCESS(err);
1414 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
1415 ASSERT_VK_SUCCESS(err);
1416
1417 VkBufferViewCreateInfo buff_view_ci = {};
1418 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
1419 buff_view_ci.buffer = buffer;
1420 buff_view_ci.format = VK_FORMAT_R8_UNORM;
1421 buff_view_ci.range = VK_WHOLE_SIZE;
1422 VkBufferView buffer_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001423 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
Dustin Graves40f35822016-06-23 11:12:53 -06001424
1425 VkDescriptorPoolSize ds_type_count = {};
1426 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1427 ds_type_count.descriptorCount = 1;
1428
1429 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1430 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1431 ds_pool_ci.pNext = NULL;
1432 ds_pool_ci.maxSets = 1;
1433 ds_pool_ci.poolSizeCount = 1;
1434 ds_pool_ci.pPoolSizes = &ds_type_count;
1435
1436 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001437 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001438 ASSERT_VK_SUCCESS(err);
1439
1440 VkDescriptorSetLayoutBinding dsl_binding = {};
1441 dsl_binding.binding = 0;
1442 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1443 dsl_binding.descriptorCount = 1;
1444 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1445 dsl_binding.pImmutableSamplers = NULL;
1446
1447 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001448 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001449 ds_layout_ci.pNext = NULL;
1450 ds_layout_ci.bindingCount = 1;
1451 ds_layout_ci.pBindings = &dsl_binding;
1452 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001453 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001454 ASSERT_VK_SUCCESS(err);
1455
1456 VkDescriptorSet descriptor_set;
1457 VkDescriptorSetAllocateInfo alloc_info = {};
1458 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1459 alloc_info.descriptorSetCount = 1;
1460 alloc_info.descriptorPool = ds_pool;
1461 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001462 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001463 ASSERT_VK_SUCCESS(err);
1464
1465 VkWriteDescriptorSet descriptor_write;
1466 memset(&descriptor_write, 0, sizeof(descriptor_write));
1467 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1468 descriptor_write.dstSet = descriptor_set;
1469 descriptor_write.dstBinding = 0;
1470 descriptor_write.descriptorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001471 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Dustin Graves40f35822016-06-23 11:12:53 -06001472 descriptor_write.pTexelBufferView = &buffer_view;
1473
1474 // Set pImageInfo and pBufferInfo to invalid values, which should be
1475 // ignored for descriptorType ==
1476 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
1477 // This will most likely produce a crash if the parameter_validation
1478 // layer
1479 // does not correctly ignore pImageInfo and pBufferInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001480 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
1481 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001482
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001483 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001484
1485 m_errorMonitor->VerifyNotFound();
1486
1487 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
1488 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1489 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1490 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
1491 vkDestroyBuffer(m_device->device(), buffer, NULL);
1492 vkFreeMemory(m_device->device(), buffer_memory, NULL);
1493 }
1494}
Cortd889ff92016-07-27 09:51:27 -07001495
1496TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1497 VkResult err;
1498
1499 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001500 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001501
1502 ASSERT_NO_FATAL_FAILURE(InitState());
1503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1504
1505 std::vector<const char *> device_extension_names;
1506 auto features = m_device->phy().features();
1507 // Artificially disable support for non-solid fill modes
1508 features.fillModeNonSolid = false;
1509 // The sacrificial device object
1510 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1511
1512 VkRenderpassObj render_pass(&test_device);
1513
1514 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1515 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1516 pipeline_layout_ci.setLayoutCount = 0;
1517 pipeline_layout_ci.pSetLayouts = NULL;
1518
1519 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001520 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001521 ASSERT_VK_SUCCESS(err);
1522
1523 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1524 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1525 rs_ci.pNext = nullptr;
1526 rs_ci.lineWidth = 1.0f;
1527 rs_ci.rasterizerDiscardEnable = true;
1528
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001529 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1530 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001531
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001532 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1534 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001535 {
1536 VkPipelineObj pipe(&test_device);
1537 pipe.AddShader(&vs);
1538 pipe.AddShader(&fs);
1539 pipe.AddColorAttachment();
1540 // Introduce failure by setting unsupported polygon mode
1541 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1542 pipe.SetRasterization(&rs_ci);
1543 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1544 }
1545 m_errorMonitor->VerifyFound();
1546
1547 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1549 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001550 {
1551 VkPipelineObj pipe(&test_device);
1552 pipe.AddShader(&vs);
1553 pipe.AddShader(&fs);
1554 pipe.AddColorAttachment();
1555 // Introduce failure by setting unsupported polygon mode
1556 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1557 pipe.SetRasterization(&rs_ci);
1558 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1559 }
1560 m_errorMonitor->VerifyFound();
1561
1562 // Try again with polygonMode=FILL. No error is expected
1563 m_errorMonitor->ExpectSuccess();
1564 {
1565 VkPipelineObj pipe(&test_device);
1566 pipe.AddShader(&vs);
1567 pipe.AddShader(&fs);
1568 pipe.AddColorAttachment();
1569 // Set polygonMode to a good value
1570 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
1571 pipe.SetRasterization(&rs_ci);
1572 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1573 }
1574 m_errorMonitor->VerifyNotFound();
1575
1576 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1577}
1578
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001579#endif // PARAMETER_VALIDATION_TESTS
1580
Tobin Ehlis0788f522015-05-26 16:11:58 -06001581#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001582#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001583TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001584{
1585 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001586 VkFenceCreateInfo fenceInfo = {};
1587 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1588 fenceInfo.pNext = NULL;
1589 fenceInfo.flags = 0;
1590
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001592
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001593 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001594
1595 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1596 vk_testing::Buffer buffer;
1597 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001598
Tony Barbourfe3351b2015-07-28 10:17:20 -06001599 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001600 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001601 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001602
1603 testFence.init(*m_device, fenceInfo);
1604
1605 // Bypass framework since it does the waits automatically
1606 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001607 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001608 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1609 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001610 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001611 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001612 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001613 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001614 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001615 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001616 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001617
1618 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001619 ASSERT_VK_SUCCESS( err );
1620
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001621 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001622 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001623
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001624 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001625}
1626
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001627TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001628{
1629 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001630 VkFenceCreateInfo fenceInfo = {};
1631 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1632 fenceInfo.pNext = NULL;
1633 fenceInfo.flags = 0;
1634
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001636
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001637 ASSERT_NO_FATAL_FAILURE(InitState());
1638 ASSERT_NO_FATAL_FAILURE(InitViewport());
1639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1640
Tony Barbourfe3351b2015-07-28 10:17:20 -06001641 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001642 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001643 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001644
1645 testFence.init(*m_device, fenceInfo);
1646
1647 // Bypass framework since it does the waits automatically
1648 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001649 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001650 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1651 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001652 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001653 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001654 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001655 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001656 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001657 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001658 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001659
1660 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001661 ASSERT_VK_SUCCESS( err );
1662
Jon Ashburnf19916e2016-01-11 13:12:43 -07001663 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001664 VkCommandBufferBeginInfo info = {};
1665 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1666 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001667 info.renderPass = VK_NULL_HANDLE;
1668 info.subpass = 0;
1669 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001670 info.occlusionQueryEnable = VK_FALSE;
1671 info.queryFlags = 0;
1672 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001673
1674 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001675 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001676
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001677 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001678}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001679#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001680
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001681// This is a positive test. No failures are expected.
1682TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1683 VkResult err;
1684 bool pass;
1685
1686 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1687 "the buffer, create an image, and bind the same memory to "
1688 "it");
1689
1690 m_errorMonitor->ExpectSuccess();
1691
1692 ASSERT_NO_FATAL_FAILURE(InitState());
1693
1694 VkBuffer buffer;
1695 VkImage image;
1696 VkDeviceMemory mem;
1697 VkMemoryRequirements mem_reqs;
1698
1699 VkBufferCreateInfo buf_info = {};
1700 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1701 buf_info.pNext = NULL;
1702 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1703 buf_info.size = 256;
1704 buf_info.queueFamilyIndexCount = 0;
1705 buf_info.pQueueFamilyIndices = NULL;
1706 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1707 buf_info.flags = 0;
1708 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1709 ASSERT_VK_SUCCESS(err);
1710
1711 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1712
1713 VkMemoryAllocateInfo alloc_info = {};
1714 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1715 alloc_info.pNext = NULL;
1716 alloc_info.memoryTypeIndex = 0;
1717
1718 // Ensure memory is big enough for both bindings
1719 alloc_info.allocationSize = 0x10000;
1720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001721 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001722 if (!pass) {
1723 vkDestroyBuffer(m_device->device(), buffer, NULL);
1724 return;
1725 }
1726
1727 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1728 ASSERT_VK_SUCCESS(err);
1729
1730 uint8_t *pData;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001731 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001732 ASSERT_VK_SUCCESS(err);
1733
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001734 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001735
1736 vkUnmapMemory(m_device->device(), mem);
1737
1738 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1739 ASSERT_VK_SUCCESS(err);
1740
1741 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1742 // memory. In fact, it was never used by the GPU.
1743 // Just be be sure, wait for idle.
1744 vkDestroyBuffer(m_device->device(), buffer, NULL);
1745 vkDeviceWaitIdle(m_device->device());
1746
1747 VkImageCreateInfo image_create_info = {};
1748 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1749 image_create_info.pNext = NULL;
1750 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1751 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1752 image_create_info.extent.width = 64;
1753 image_create_info.extent.height = 64;
1754 image_create_info.extent.depth = 1;
1755 image_create_info.mipLevels = 1;
1756 image_create_info.arrayLayers = 1;
1757 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1758 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1759 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1760 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1761 image_create_info.queueFamilyIndexCount = 0;
1762 image_create_info.pQueueFamilyIndices = NULL;
1763 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1764 image_create_info.flags = 0;
1765
1766 VkMemoryAllocateInfo mem_alloc = {};
1767 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1768 mem_alloc.pNext = NULL;
1769 mem_alloc.allocationSize = 0;
1770 mem_alloc.memoryTypeIndex = 0;
1771
1772 /* Create a mappable image. It will be the texture if linear images are ok
1773 * to be textures or it will be the staging image if they are not.
1774 */
1775 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1776 ASSERT_VK_SUCCESS(err);
1777
1778 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1779
1780 mem_alloc.allocationSize = mem_reqs.size;
1781
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001782 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001783 if (!pass) {
1784 vkDestroyImage(m_device->device(), image, NULL);
1785 return;
1786 }
1787
Tobin Ehlis077ded32016-05-12 17:39:13 -06001788 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001789 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1790 ASSERT_VK_SUCCESS(err);
1791
1792 m_errorMonitor->VerifyNotFound();
1793
Tony Barbourdf4c0042016-06-01 15:55:43 -06001794 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001795 vkDestroyBuffer(m_device->device(), buffer, NULL);
1796 vkDestroyImage(m_device->device(), image, NULL);
1797}
1798
Tobin Ehlisf11be982016-05-11 13:52:53 -06001799TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1800 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1801 "buffer and image to memory such that they will alias.");
1802 VkResult err;
1803 bool pass;
1804 ASSERT_NO_FATAL_FAILURE(InitState());
1805
Tobin Ehlis077ded32016-05-12 17:39:13 -06001806 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001807 VkImage image;
1808 VkDeviceMemory mem; // buffer will be bound first
1809 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001810 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001811
1812 VkBufferCreateInfo buf_info = {};
1813 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1814 buf_info.pNext = NULL;
1815 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1816 buf_info.size = 256;
1817 buf_info.queueFamilyIndexCount = 0;
1818 buf_info.pQueueFamilyIndices = NULL;
1819 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1820 buf_info.flags = 0;
1821 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1822 ASSERT_VK_SUCCESS(err);
1823
Tobin Ehlis077ded32016-05-12 17:39:13 -06001824 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001825
1826 VkImageCreateInfo image_create_info = {};
1827 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1828 image_create_info.pNext = NULL;
1829 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1830 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1831 image_create_info.extent.width = 64;
1832 image_create_info.extent.height = 64;
1833 image_create_info.extent.depth = 1;
1834 image_create_info.mipLevels = 1;
1835 image_create_info.arrayLayers = 1;
1836 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001837 // Image tiling must be optimal to trigger error when aliasing linear buffer
1838 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001839 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1840 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1841 image_create_info.queueFamilyIndexCount = 0;
1842 image_create_info.pQueueFamilyIndices = NULL;
1843 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1844 image_create_info.flags = 0;
1845
Tobin Ehlisf11be982016-05-11 13:52:53 -06001846 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1847 ASSERT_VK_SUCCESS(err);
1848
Tobin Ehlis077ded32016-05-12 17:39:13 -06001849 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1850
1851 VkMemoryAllocateInfo alloc_info = {};
1852 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1853 alloc_info.pNext = NULL;
1854 alloc_info.memoryTypeIndex = 0;
1855 // Ensure memory is big enough for both bindings
1856 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001857 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1858 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001859 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001860 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001861 vkDestroyImage(m_device->device(), image, NULL);
1862 return;
1863 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001864 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1865 ASSERT_VK_SUCCESS(err);
1866 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1867 ASSERT_VK_SUCCESS(err);
1868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001870 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001871 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1872 m_errorMonitor->VerifyFound();
1873
1874 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001875 // aliasing buffer2
1876 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1877 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001878 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1879 ASSERT_VK_SUCCESS(err);
1880 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1881 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001883 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001884 m_errorMonitor->VerifyFound();
1885
1886 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001887 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001888 vkDestroyImage(m_device->device(), image, NULL);
1889 vkFreeMemory(m_device->device(), mem, NULL);
1890 vkFreeMemory(m_device->device(), mem_img, NULL);
1891}
1892
Tobin Ehlis35372522016-05-12 08:32:31 -06001893TEST_F(VkLayerTest, InvalidMemoryMapping) {
1894 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1895 VkResult err;
1896 bool pass;
1897 ASSERT_NO_FATAL_FAILURE(InitState());
1898
1899 VkBuffer buffer;
1900 VkDeviceMemory mem;
1901 VkMemoryRequirements mem_reqs;
1902
1903 VkBufferCreateInfo buf_info = {};
1904 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1905 buf_info.pNext = NULL;
1906 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1907 buf_info.size = 256;
1908 buf_info.queueFamilyIndexCount = 0;
1909 buf_info.pQueueFamilyIndices = NULL;
1910 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1911 buf_info.flags = 0;
1912 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1913 ASSERT_VK_SUCCESS(err);
1914
1915 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1916 VkMemoryAllocateInfo alloc_info = {};
1917 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1918 alloc_info.pNext = NULL;
1919 alloc_info.memoryTypeIndex = 0;
1920
1921 // Ensure memory is big enough for both bindings
1922 static const VkDeviceSize allocation_size = 0x10000;
1923 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001924 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001925 if (!pass) {
1926 vkDestroyBuffer(m_device->device(), buffer, NULL);
1927 return;
1928 }
1929 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1930 ASSERT_VK_SUCCESS(err);
1931
1932 uint8_t *pData;
1933 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001935 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1936 m_errorMonitor->VerifyFound();
1937 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001938 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001939 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1941 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1942 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001943 m_errorMonitor->VerifyFound();
1944
1945 // Unmap the memory to avoid re-map error
1946 vkUnmapMemory(m_device->device(), mem);
1947 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1949 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1950 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001951 m_errorMonitor->VerifyFound();
1952 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1954 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001955 m_errorMonitor->VerifyFound();
1956 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001958 vkUnmapMemory(m_device->device(), mem);
1959 m_errorMonitor->VerifyFound();
1960 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001961 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001962 ASSERT_VK_SUCCESS(err);
1963 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001964 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001965 mmr.memory = mem;
1966 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") is less than Memory Object's offset (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001968 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1969 m_errorMonitor->VerifyFound();
1970 // Now flush range that oversteps mapped range
1971 vkUnmapMemory(m_device->device(), mem);
1972 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1973 ASSERT_VK_SUCCESS(err);
1974 mmr.offset = 16;
1975 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") exceeds the Memory Object's upper-bound (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001977 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1978 m_errorMonitor->VerifyFound();
1979
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001980 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1981 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001982 if (!pass) {
1983 vkFreeMemory(m_device->device(), mem, NULL);
1984 vkDestroyBuffer(m_device->device(), buffer, NULL);
1985 return;
1986 }
1987 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1988 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1989
1990 vkDestroyBuffer(m_device->device(), buffer, NULL);
1991 vkFreeMemory(m_device->device(), mem, NULL);
1992}
1993
Mark Lobodzinski1f515922016-08-16 10:03:30 -06001994TEST_F(VkLayerTest, NonCoherentMemoryMapping) {
1995
1996 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
1997 "mapping while using VK_WHOLE_SIZE does not cause access "
1998 "violations");
1999 VkResult err;
2000 uint8_t *pData;
2001 ASSERT_NO_FATAL_FAILURE(InitState());
2002
2003 VkDeviceMemory mem;
2004 VkMemoryRequirements mem_reqs;
2005 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
2006 VkMemoryAllocateInfo alloc_info = {};
2007 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2008 alloc_info.pNext = NULL;
2009 alloc_info.memoryTypeIndex = 0;
2010
2011 static const VkDeviceSize allocation_size = 0x1000;
2012 alloc_info.allocationSize = allocation_size;
2013
2014 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002015 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
2016 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002017 if (!pass) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002018 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
2019 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
2020 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002021 if (!pass) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002022 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
2023 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
2024 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
2025 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002026 if (!pass) {
2027 return;
2028 }
2029 }
2030 }
2031
2032 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
2033 ASSERT_VK_SUCCESS(err);
2034
2035 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
2036 // mapped range
2037 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002038 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002039 ASSERT_VK_SUCCESS(err);
2040 VkMappedMemoryRange mmr = {};
2041 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2042 mmr.memory = mem;
2043 mmr.offset = 0;
2044 mmr.size = VK_WHOLE_SIZE;
2045 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2046 ASSERT_VK_SUCCESS(err);
2047 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2048 ASSERT_VK_SUCCESS(err);
2049 m_errorMonitor->VerifyNotFound();
2050 vkUnmapMemory(m_device->device(), mem);
2051
2052 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
2053 // mapped range
2054 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002055 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002056 ASSERT_VK_SUCCESS(err);
2057 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2058 mmr.memory = mem;
2059 mmr.offset = 13;
2060 mmr.size = VK_WHOLE_SIZE;
2061 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2062 ASSERT_VK_SUCCESS(err);
2063 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2064 ASSERT_VK_SUCCESS(err);
2065 m_errorMonitor->VerifyNotFound();
2066 vkUnmapMemory(m_device->device(), mem);
2067
2068 // Map with prime offset and size
2069 // Flush/Invalidate subrange of mapped area with prime offset and size
2070 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002071 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002072 ASSERT_VK_SUCCESS(err);
2073 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2074 mmr.memory = mem;
2075 mmr.offset = allocation_size - 107;
2076 mmr.size = 61;
2077 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2078 ASSERT_VK_SUCCESS(err);
2079 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2080 ASSERT_VK_SUCCESS(err);
2081 m_errorMonitor->VerifyNotFound();
2082 vkUnmapMemory(m_device->device(), mem);
2083
2084 vkFreeMemory(m_device->device(), mem, NULL);
2085}
2086
Ian Elliott1c32c772016-04-28 14:47:13 -06002087TEST_F(VkLayerTest, EnableWsiBeforeUse) {
2088 VkResult err;
2089 bool pass;
2090
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002091 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
2092 // following declaration (which is temporarily being moved below):
2093 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002094 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2095 VkSwapchainCreateInfoKHR swapchain_create_info = {};
2096 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002097 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06002098 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002099 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06002100
2101 ASSERT_NO_FATAL_FAILURE(InitState());
2102
Ian Elliott3f06ce52016-04-29 14:46:21 -06002103#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
2104#if defined(VK_USE_PLATFORM_ANDROID_KHR)
2105 // Use the functions from the VK_KHR_android_surface extension without
2106 // enabling that extension:
2107
2108 // Create a surface:
2109 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2111 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002112 pass = (err != VK_SUCCESS);
2113 ASSERT_TRUE(pass);
2114 m_errorMonitor->VerifyFound();
2115#endif // VK_USE_PLATFORM_ANDROID_KHR
2116
Ian Elliott3f06ce52016-04-29 14:46:21 -06002117#if defined(VK_USE_PLATFORM_MIR_KHR)
2118 // Use the functions from the VK_KHR_mir_surface extension without enabling
2119 // that extension:
2120
2121 // Create a surface:
2122 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06002124 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
2125 pass = (err != VK_SUCCESS);
2126 ASSERT_TRUE(pass);
2127 m_errorMonitor->VerifyFound();
2128
2129 // Tell whether an mir_connection supports presentation:
2130 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2132 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002133 m_errorMonitor->VerifyFound();
2134#endif // VK_USE_PLATFORM_MIR_KHR
2135
Ian Elliott3f06ce52016-04-29 14:46:21 -06002136#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
2137 // Use the functions from the VK_KHR_wayland_surface extension without
2138 // enabling that extension:
2139
2140 // Create a surface:
2141 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2143 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002144 pass = (err != VK_SUCCESS);
2145 ASSERT_TRUE(pass);
2146 m_errorMonitor->VerifyFound();
2147
2148 // Tell whether an wayland_display supports presentation:
2149 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2151 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002152 m_errorMonitor->VerifyFound();
2153#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06002154#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06002155
Ian Elliott3f06ce52016-04-29 14:46:21 -06002156#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002157 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2158 // TO NON-LINUX PLATFORMS:
2159 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06002160 // Use the functions from the VK_KHR_win32_surface extension without
2161 // enabling that extension:
2162
2163 // Create a surface:
2164 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2166 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002167 pass = (err != VK_SUCCESS);
2168 ASSERT_TRUE(pass);
2169 m_errorMonitor->VerifyFound();
2170
2171 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06002173 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002174 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002175// Set this (for now, until all platforms are supported and tested):
2176#define NEED_TO_TEST_THIS_ON_PLATFORM
2177#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06002178
Ian Elliott1c32c772016-04-28 14:47:13 -06002179#if defined(VK_USE_PLATFORM_XCB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002180 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2181 // TO NON-LINUX PLATFORMS:
2182 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002183 // Use the functions from the VK_KHR_xcb_surface extension without enabling
2184 // that extension:
2185
2186 // Create a surface:
2187 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002189 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2190 pass = (err != VK_SUCCESS);
2191 ASSERT_TRUE(pass);
2192 m_errorMonitor->VerifyFound();
2193
2194 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06002195 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06002196 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2198 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06002199 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002200// Set this (for now, until all platforms are supported and tested):
2201#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002202#endif // VK_USE_PLATFORM_XCB_KHR
2203
Ian Elliott12630812016-04-29 14:35:43 -06002204#if defined(VK_USE_PLATFORM_XLIB_KHR)
2205 // Use the functions from the VK_KHR_xlib_surface extension without enabling
2206 // that extension:
2207
2208 // Create a surface:
2209 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002211 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
2212 pass = (err != VK_SUCCESS);
2213 ASSERT_TRUE(pass);
2214 m_errorMonitor->VerifyFound();
2215
2216 // Tell whether an Xlib VisualID supports presentation:
2217 Display *dpy = NULL;
2218 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002220 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
2221 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002222// Set this (for now, until all platforms are supported and tested):
2223#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06002224#endif // VK_USE_PLATFORM_XLIB_KHR
2225
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002226// Use the functions from the VK_KHR_surface extension without enabling
2227// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002228
Ian Elliott489eec02016-05-05 14:12:44 -06002229#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002230 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002232 vkDestroySurfaceKHR(instance(), surface, NULL);
2233 m_errorMonitor->VerifyFound();
2234
2235 // Check if surface supports presentation:
2236 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002238 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2239 pass = (err != VK_SUCCESS);
2240 ASSERT_TRUE(pass);
2241 m_errorMonitor->VerifyFound();
2242
2243 // Check surface capabilities:
2244 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2246 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06002247 pass = (err != VK_SUCCESS);
2248 ASSERT_TRUE(pass);
2249 m_errorMonitor->VerifyFound();
2250
2251 // Check surface formats:
2252 uint32_t format_count = 0;
2253 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2255 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06002256 pass = (err != VK_SUCCESS);
2257 ASSERT_TRUE(pass);
2258 m_errorMonitor->VerifyFound();
2259
2260 // Check surface present modes:
2261 uint32_t present_mode_count = 0;
2262 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2264 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06002265 pass = (err != VK_SUCCESS);
2266 ASSERT_TRUE(pass);
2267 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002268#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002269
Ian Elliott1c32c772016-04-28 14:47:13 -06002270 // Use the functions from the VK_KHR_swapchain extension without enabling
2271 // that extension:
2272
2273 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002275 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2276 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002277 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06002278 pass = (err != VK_SUCCESS);
2279 ASSERT_TRUE(pass);
2280 m_errorMonitor->VerifyFound();
2281
2282 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2284 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06002285 pass = (err != VK_SUCCESS);
2286 ASSERT_TRUE(pass);
2287 m_errorMonitor->VerifyFound();
2288
Chris Forbeseb7d5502016-09-13 18:19:21 +12002289 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
2290 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2291 VkFence fence;
2292 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2293
Ian Elliott1c32c772016-04-28 14:47:13 -06002294 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12002296 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06002297 pass = (err != VK_SUCCESS);
2298 ASSERT_TRUE(pass);
2299 m_errorMonitor->VerifyFound();
2300
Chris Forbeseb7d5502016-09-13 18:19:21 +12002301 vkDestroyFence(m_device->device(), fence, nullptr);
2302
Ian Elliott1c32c772016-04-28 14:47:13 -06002303 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002304 //
2305 // NOTE: Currently can't test this because a real swapchain is needed (as
2306 // opposed to the fake one we created) in order for the layer to lookup the
2307 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002308
2309 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002311 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
2312 m_errorMonitor->VerifyFound();
2313}
2314
Ian Elliott2c1daf52016-05-12 09:41:46 -06002315TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06002316
Dustin Graves6c6d8982016-05-17 10:09:21 -06002317#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06002318 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002319
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002320 VkResult err;
2321 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002322 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2323 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002324 // uint32_t swapchain_image_count = 0;
2325 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
2326 // uint32_t image_index = 0;
2327 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06002328
2329 ASSERT_NO_FATAL_FAILURE(InitState());
2330
2331 // Use the create function from one of the VK_KHR_*_surface extension in
2332 // order to create a surface, testing all known errors in the process,
2333 // before successfully creating a surface:
2334 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002336 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
2337 pass = (err != VK_SUCCESS);
2338 ASSERT_TRUE(pass);
2339 m_errorMonitor->VerifyFound();
2340
2341 // Next, try to create a surface with the wrong
2342 // VkXcbSurfaceCreateInfoKHR::sType:
2343 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
2344 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002346 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2347 pass = (err != VK_SUCCESS);
2348 ASSERT_TRUE(pass);
2349 m_errorMonitor->VerifyFound();
2350
Ian Elliott2c1daf52016-05-12 09:41:46 -06002351 // Create a native window, and then correctly create a surface:
2352 xcb_connection_t *connection;
2353 xcb_screen_t *screen;
2354 xcb_window_t xcb_window;
2355 xcb_intern_atom_reply_t *atom_wm_delete_window;
2356
2357 const xcb_setup_t *setup;
2358 xcb_screen_iterator_t iter;
2359 int scr;
2360 uint32_t value_mask, value_list[32];
2361 int width = 1;
2362 int height = 1;
2363
2364 connection = xcb_connect(NULL, &scr);
2365 ASSERT_TRUE(connection != NULL);
2366 setup = xcb_get_setup(connection);
2367 iter = xcb_setup_roots_iterator(setup);
2368 while (scr-- > 0)
2369 xcb_screen_next(&iter);
2370 screen = iter.data;
2371
2372 xcb_window = xcb_generate_id(connection);
2373
2374 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
2375 value_list[0] = screen->black_pixel;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002376 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002377
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002378 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
2379 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002380
2381 /* Magic code that will send notification when window is destroyed */
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002382 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
2383 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002384
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002385 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002386 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002387 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002388 free(reply);
2389
2390 xcb_map_window(connection, xcb_window);
2391
2392 // Force the x/y coordinates to 100,100 results are identical in consecutive
2393 // runs
2394 const uint32_t coords[] = {100, 100};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002395 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002396
Ian Elliott2c1daf52016-05-12 09:41:46 -06002397 // Finally, try to correctly create a surface:
2398 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
2399 xcb_create_info.pNext = NULL;
2400 xcb_create_info.flags = 0;
2401 xcb_create_info.connection = connection;
2402 xcb_create_info.window = xcb_window;
2403 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2404 pass = (err == VK_SUCCESS);
2405 ASSERT_TRUE(pass);
2406
Ian Elliott2c1daf52016-05-12 09:41:46 -06002407 // Check if surface supports presentation:
2408
2409 // 1st, do so without having queried the queue families:
2410 VkBool32 supported = false;
2411 // TODO: Get the following error to come out:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2413 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
2414 "function");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002415 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2416 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002417 // ASSERT_TRUE(pass);
2418 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06002419
2420 // Next, query a queue family index that's too large:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2422 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002423 pass = (err != VK_SUCCESS);
2424 ASSERT_TRUE(pass);
2425 m_errorMonitor->VerifyFound();
2426
2427 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002428 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2429 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002430 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2431 pass = (err == VK_SUCCESS);
2432 ASSERT_TRUE(pass);
2433
Ian Elliott2c1daf52016-05-12 09:41:46 -06002434 // Before proceeding, try to create a swapchain without having called
2435 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
2436 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2437 swapchain_create_info.pNext = NULL;
2438 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2440 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
2441 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002442 pass = (err != VK_SUCCESS);
2443 ASSERT_TRUE(pass);
2444 m_errorMonitor->VerifyFound();
2445
Ian Elliott2c1daf52016-05-12 09:41:46 -06002446 // Get the surface capabilities:
2447 VkSurfaceCapabilitiesKHR surface_capabilities;
2448
2449 // Do so correctly (only error logged by this entrypoint is if the
2450 // extension isn't enabled):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002451 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002452 pass = (err == VK_SUCCESS);
2453 ASSERT_TRUE(pass);
2454
Ian Elliott2c1daf52016-05-12 09:41:46 -06002455 // Get the surface formats:
2456 uint32_t surface_format_count;
2457
2458 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
2460 "specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002461 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
2462 pass = (err == VK_SUCCESS);
2463 ASSERT_TRUE(pass);
2464 m_errorMonitor->VerifyFound();
2465
2466 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
2467 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002469 surface_format_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002470 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002471 pass = (err == VK_SUCCESS);
2472 ASSERT_TRUE(pass);
2473 m_errorMonitor->VerifyFound();
2474
2475 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002476 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002477 pass = (err == VK_SUCCESS);
2478 ASSERT_TRUE(pass);
2479
2480 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002481 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002482
2483 // Next, do a 2nd try with surface_format_count being set too high:
2484 surface_format_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2486 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002487 pass = (err == VK_SUCCESS);
2488 ASSERT_TRUE(pass);
2489 m_errorMonitor->VerifyFound();
2490
2491 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002492 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002493 pass = (err == VK_SUCCESS);
2494 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002495 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002496 pass = (err == VK_SUCCESS);
2497 ASSERT_TRUE(pass);
2498
Ian Elliott2c1daf52016-05-12 09:41:46 -06002499 // Get the surface present modes:
2500 uint32_t surface_present_mode_count;
2501
2502 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
2504 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002505
Ian Elliott2c1daf52016-05-12 09:41:46 -06002506 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
2507 pass = (err == VK_SUCCESS);
2508 ASSERT_TRUE(pass);
2509 m_errorMonitor->VerifyFound();
2510
2511 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
2512 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002514 surface_present_mode_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002515 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
2516 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002517 pass = (err == VK_SUCCESS);
2518 ASSERT_TRUE(pass);
2519 m_errorMonitor->VerifyFound();
2520
2521 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002522 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002523 pass = (err == VK_SUCCESS);
2524 ASSERT_TRUE(pass);
2525
2526 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002527 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002528
2529 // Next, do a 2nd try with surface_format_count being set too high:
2530 surface_present_mode_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2532 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002533 pass = (err == VK_SUCCESS);
2534 ASSERT_TRUE(pass);
2535 m_errorMonitor->VerifyFound();
2536
2537 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002538 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002539 pass = (err == VK_SUCCESS);
2540 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002541 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002542 pass = (err == VK_SUCCESS);
2543 ASSERT_TRUE(pass);
2544
Ian Elliott2c1daf52016-05-12 09:41:46 -06002545 // Create a swapchain:
2546
2547 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
2549 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002550
Ian Elliott2c1daf52016-05-12 09:41:46 -06002551 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
2552 pass = (err != VK_SUCCESS);
2553 ASSERT_TRUE(pass);
2554 m_errorMonitor->VerifyFound();
2555
2556 // Next, call with a non-NULL swapchain_create_info, that has the wrong
2557 // sType:
2558 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002560
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002561 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002562 pass = (err != VK_SUCCESS);
2563 ASSERT_TRUE(pass);
2564 m_errorMonitor->VerifyFound();
2565
2566 // Next, call with a NULL swapchain pointer:
2567 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2568 swapchain_create_info.pNext = NULL;
2569 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
2571 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002572
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002573 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002574 pass = (err != VK_SUCCESS);
2575 ASSERT_TRUE(pass);
2576 m_errorMonitor->VerifyFound();
2577
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002578 // TODO: Enhance swapchain layer so that
2579 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06002580
2581 // Next, call with a queue family index that's too large:
2582 uint32_t queueFamilyIndex[2] = {100000, 0};
2583 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2584 swapchain_create_info.queueFamilyIndexCount = 2;
2585 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2587 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002588 pass = (err != VK_SUCCESS);
2589 ASSERT_TRUE(pass);
2590 m_errorMonitor->VerifyFound();
2591
2592 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
2593 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2594 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2596 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
2597 "pCreateInfo->pQueueFamilyIndices).");
2598 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002599 pass = (err != VK_SUCCESS);
2600 ASSERT_TRUE(pass);
2601 m_errorMonitor->VerifyFound();
2602
2603 // Next, call with an invalid imageSharingMode:
2604 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
2605 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2607 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
2608 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002609 pass = (err != VK_SUCCESS);
2610 ASSERT_TRUE(pass);
2611 m_errorMonitor->VerifyFound();
2612 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002613 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2614 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002615 swapchain_create_info.queueFamilyIndexCount = 0;
2616 queueFamilyIndex[0] = 0;
2617 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2618
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002619 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002620 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002621 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002622 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002623 // Destroy the swapchain:
2624
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002625 // TODOs:
2626 //
2627 // - Try destroying the device without first destroying the swapchain
2628 //
2629 // - Try destroying the device without first destroying the surface
2630 //
2631 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002632
2633 // Destroy the surface:
2634 vkDestroySurfaceKHR(instance(), surface, NULL);
2635
Ian Elliott2c1daf52016-05-12 09:41:46 -06002636 // Tear down the window:
2637 xcb_destroy_window(connection, xcb_window);
2638 xcb_disconnect(connection);
2639
2640#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002641 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002642#endif // VK_USE_PLATFORM_XCB_KHR
2643}
2644
Karl Schultz6addd812016-02-02 17:17:23 -07002645TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2646 VkResult err;
2647 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002648
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2650 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002651
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002652 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002653
2654 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002655 VkImage image;
2656 VkDeviceMemory mem;
2657 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002658
Karl Schultz6addd812016-02-02 17:17:23 -07002659 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2660 const int32_t tex_width = 32;
2661 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002662
Tony Barboureb254902015-07-15 12:50:33 -06002663 VkImageCreateInfo image_create_info = {};
2664 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002665 image_create_info.pNext = NULL;
2666 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2667 image_create_info.format = tex_format;
2668 image_create_info.extent.width = tex_width;
2669 image_create_info.extent.height = tex_height;
2670 image_create_info.extent.depth = 1;
2671 image_create_info.mipLevels = 1;
2672 image_create_info.arrayLayers = 1;
2673 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2674 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2675 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2676 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002677 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002678
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002679 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002680 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002681 mem_alloc.pNext = NULL;
2682 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002683
Chia-I Wuf7458c52015-10-26 21:10:41 +08002684 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002685 ASSERT_VK_SUCCESS(err);
2686
Karl Schultz6addd812016-02-02 17:17:23 -07002687 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002688
Mark Lobodzinski23065352015-05-29 09:32:35 -05002689 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002690
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002691 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Karl Schultz6addd812016-02-02 17:17:23 -07002692 if (!pass) { // If we can't find any unmappable memory this test doesn't
2693 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002694 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002695 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002696 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002697
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002698 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002699 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002700 ASSERT_VK_SUCCESS(err);
2701
2702 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002703 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002704 ASSERT_VK_SUCCESS(err);
2705
2706 // Map memory as if to initialize the image
2707 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002708 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002709
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002710 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002711
Chia-I Wuf7458c52015-10-26 21:10:41 +08002712 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002713 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002714}
2715
Karl Schultz6addd812016-02-02 17:17:23 -07002716TEST_F(VkLayerTest, RebindMemory) {
2717 VkResult err;
2718 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002719
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002721
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002722 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002723
2724 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002725 VkImage image;
2726 VkDeviceMemory mem1;
2727 VkDeviceMemory mem2;
2728 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002729
Karl Schultz6addd812016-02-02 17:17:23 -07002730 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2731 const int32_t tex_width = 32;
2732 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002733
Tony Barboureb254902015-07-15 12:50:33 -06002734 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002735 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2736 image_create_info.pNext = NULL;
2737 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2738 image_create_info.format = tex_format;
2739 image_create_info.extent.width = tex_width;
2740 image_create_info.extent.height = tex_height;
2741 image_create_info.extent.depth = 1;
2742 image_create_info.mipLevels = 1;
2743 image_create_info.arrayLayers = 1;
2744 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2745 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2746 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2747 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002748
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002749 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002750 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2751 mem_alloc.pNext = NULL;
2752 mem_alloc.allocationSize = 0;
2753 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002754
Karl Schultz6addd812016-02-02 17:17:23 -07002755 // Introduce failure, do NOT set memProps to
2756 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002757 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002758 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002759 ASSERT_VK_SUCCESS(err);
2760
Karl Schultz6addd812016-02-02 17:17:23 -07002761 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002762
2763 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002764 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002765 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002766
2767 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002768 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002769 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002770 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002771 ASSERT_VK_SUCCESS(err);
2772
2773 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002774 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002775 ASSERT_VK_SUCCESS(err);
2776
Karl Schultz6addd812016-02-02 17:17:23 -07002777 // Introduce validation failure, try to bind a different memory object to
2778 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002779 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002780
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002781 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002782
Chia-I Wuf7458c52015-10-26 21:10:41 +08002783 vkDestroyImage(m_device->device(), image, NULL);
2784 vkFreeMemory(m_device->device(), mem1, NULL);
2785 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002786}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002787
Karl Schultz6addd812016-02-02 17:17:23 -07002788TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002789 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002790
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2792 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002793
2794 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002795 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2796 fenceInfo.pNext = NULL;
2797 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002798
Tony Barbour300a6082015-04-07 13:44:53 -06002799 ASSERT_NO_FATAL_FAILURE(InitState());
2800 ASSERT_NO_FATAL_FAILURE(InitViewport());
2801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2802
Tony Barbourfe3351b2015-07-28 10:17:20 -06002803 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002804 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002805 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002806
2807 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002808
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002809 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002810 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2811 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002812 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002813 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002814 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002815 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002816 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002817 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002818 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002819
2820 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002821 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002822
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002823 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002824}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002825// This is a positive test. We used to expect error in this case but spec now
2826// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002827TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002828 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002829 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002830 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002831 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2832 fenceInfo.pNext = NULL;
2833
Tony Barbour0b4d9562015-04-09 10:48:04 -06002834 ASSERT_NO_FATAL_FAILURE(InitState());
2835 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002836 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002837 VkResult result = vkResetFences(m_device->device(), 1, fences);
2838 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002839
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002840 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002841}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002842#if 0 // A few devices have issues with this test so disabling for now
Chris Forbese70b7d32016-06-15 15:49:12 +12002843TEST_F(VkLayerTest, LongFenceChain)
2844{
2845 m_errorMonitor->ExpectSuccess();
2846
2847 ASSERT_NO_FATAL_FAILURE(InitState());
2848 VkResult err;
2849
2850 std::vector<VkFence> fences;
2851
2852 const int chainLength = 32768;
2853
2854 for (int i = 0; i < chainLength; i++) {
2855 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2856 VkFence fence;
2857 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2858 ASSERT_VK_SUCCESS(err);
2859
2860 fences.push_back(fence);
2861
2862 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2863 0, nullptr, 0, nullptr };
2864 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2865 ASSERT_VK_SUCCESS(err);
2866
2867 }
2868
2869 // BOOM, stack overflow.
2870 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
2871
2872 for (auto fence : fences)
2873 vkDestroyFence(m_device->device(), fence, nullptr);
2874
2875 m_errorMonitor->VerifyNotFound();
2876}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002877#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002878TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) {
Chris Forbes18127d12016-06-08 16:52:28 +12002879 m_errorMonitor->ExpectSuccess();
2880
2881 ASSERT_NO_FATAL_FAILURE(InitState());
2882 VkResult err;
2883
2884 // Record (empty!) command buffer that can be submitted multiple times
2885 // simultaneously.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002886 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
2887 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Chris Forbes18127d12016-06-08 16:52:28 +12002888 m_commandBuffer->BeginCommandBuffer(&cbbi);
2889 m_commandBuffer->EndCommandBuffer();
2890
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002891 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002892 VkFence fence;
2893 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2894 ASSERT_VK_SUCCESS(err);
2895
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002896 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002897 VkSemaphore s1, s2;
2898 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
2899 ASSERT_VK_SUCCESS(err);
2900 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
2901 ASSERT_VK_SUCCESS(err);
2902
2903 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002904 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Chris Forbes18127d12016-06-08 16:52:28 +12002905 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2906 ASSERT_VK_SUCCESS(err);
2907
2908 // Submit CB again, signaling s2.
2909 si.pSignalSemaphores = &s2;
2910 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
2911 ASSERT_VK_SUCCESS(err);
2912
2913 // Wait for fence.
2914 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2915 ASSERT_VK_SUCCESS(err);
2916
2917 // CB is still in flight from second submission, but semaphore s1 is no
2918 // longer in flight. delete it.
2919 vkDestroySemaphore(m_device->device(), s1, nullptr);
2920
2921 m_errorMonitor->VerifyNotFound();
2922
2923 // Force device idle and clean up remaining objects
2924 vkDeviceWaitIdle(m_device->device());
2925 vkDestroySemaphore(m_device->device(), s2, nullptr);
2926 vkDestroyFence(m_device->device(), fence, nullptr);
2927}
2928
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002929TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling) {
Chris Forbes4e44c912016-06-16 10:20:00 +12002930 m_errorMonitor->ExpectSuccess();
2931
2932 ASSERT_NO_FATAL_FAILURE(InitState());
2933 VkResult err;
2934
2935 // A fence created signaled
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002936 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Chris Forbes4e44c912016-06-16 10:20:00 +12002937 VkFence f1;
2938 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
2939 ASSERT_VK_SUCCESS(err);
2940
2941 // A fence created not
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002942 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes4e44c912016-06-16 10:20:00 +12002943 VkFence f2;
2944 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
2945 ASSERT_VK_SUCCESS(err);
2946
2947 // Submit the unsignaled fence
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002948 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Chris Forbes4e44c912016-06-16 10:20:00 +12002949 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
2950
2951 // Wait on both fences, with signaled first.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002952 VkFence fences[] = {f1, f2};
Chris Forbes4e44c912016-06-16 10:20:00 +12002953 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
2954
2955 // Should have both retired!
2956 vkDestroyFence(m_device->device(), f1, nullptr);
2957 vkDestroyFence(m_device->device(), f2, nullptr);
2958
2959 m_errorMonitor->VerifyNotFound();
2960}
2961
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002962TEST_F(VkLayerTest, InvalidUsageBits) {
2963 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
2964 "Initialize buffer with wrong usage then perform copy expecting errors "
2965 "from both the image and the buffer (2 calls)");
2966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002967
2968 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002969 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002970 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002971 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002972 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002973
Tony Barbourf92621a2016-05-02 14:28:12 -06002974 VkImageView dsv;
2975 VkImageViewCreateInfo dsvci = {};
2976 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2977 dsvci.image = image.handle();
2978 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2979 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2980 dsvci.subresourceRange.layerCount = 1;
2981 dsvci.subresourceRange.baseMipLevel = 0;
2982 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002983 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002984
Tony Barbourf92621a2016-05-02 14:28:12 -06002985 // Create a view with depth / stencil aspect for image with different usage
2986 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002987
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002988 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002989
2990 // Initialize buffer with TRANSFER_DST usage
2991 vk_testing::Buffer buffer;
2992 VkMemoryPropertyFlags reqs = 0;
2993 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2994 VkBufferImageCopy region = {};
2995 region.bufferRowLength = 128;
2996 region.bufferImageHeight = 128;
2997 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2998 region.imageSubresource.layerCount = 1;
2999 region.imageExtent.height = 16;
3000 region.imageExtent.width = 16;
3001 region.imageExtent.depth = 1;
3002
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for buffer ");
Tony Barbourf92621a2016-05-02 14:28:12 -06003004 // Buffer usage not set to TRANSFER_SRC and image usage not set to
3005 // TRANSFER_DST
3006 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003007 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3008 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003009 m_errorMonitor->VerifyFound();
3010
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
3012 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3013 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003014 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06003015}
Tony Barbour75d79f02016-08-30 09:39:07 -06003016
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003017TEST_F(VkLayerTest, ValidUsage) {
3018 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
3019 "doesn't generate validation errors");
Tony Barbour75d79f02016-08-30 09:39:07 -06003020
3021 ASSERT_NO_FATAL_FAILURE(InitState());
3022
3023 m_errorMonitor->ExpectSuccess();
3024 // Verify that we can create a view with usage INPUT_ATTACHMENT
3025 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003026 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour75d79f02016-08-30 09:39:07 -06003027 ASSERT_TRUE(image.initialized());
3028 VkImageView imageView;
3029 VkImageViewCreateInfo ivci = {};
3030 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3031 ivci.image = image.handle();
3032 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3033 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
3034 ivci.subresourceRange.layerCount = 1;
3035 ivci.subresourceRange.baseMipLevel = 0;
3036 ivci.subresourceRange.levelCount = 1;
3037 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3038
3039 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
3040 m_errorMonitor->VerifyNotFound();
3041 vkDestroyImageView(m_device->device(), imageView, NULL);
3042}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003043#endif // MEM_TRACKER_TESTS
3044
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06003045#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003046
3047TEST_F(VkLayerTest, LeakAnObject) {
3048 VkResult err;
3049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003050 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003051
3052 // Note that we have to create a new device since destroying the
3053 // framework's device causes Teardown() to fail and just calling Teardown
3054 // will destroy the errorMonitor.
3055
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003057
3058 ASSERT_NO_FATAL_FAILURE(InitState());
3059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003060 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003061 std::vector<VkDeviceQueueCreateInfo> queue_info;
3062 queue_info.reserve(queue_props.size());
3063 std::vector<std::vector<float>> queue_priorities;
3064 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
3065 VkDeviceQueueCreateInfo qi = {};
3066 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
3067 qi.pNext = NULL;
3068 qi.queueFamilyIndex = i;
3069 qi.queueCount = queue_props[i].queueCount;
3070 queue_priorities.emplace_back(qi.queueCount, 0.0f);
3071 qi.pQueuePriorities = queue_priorities[i].data();
3072 queue_info.push_back(qi);
3073 }
3074
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003075 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003076
3077 // The sacrificial device object
3078 VkDevice testDevice;
3079 VkDeviceCreateInfo device_create_info = {};
3080 auto features = m_device->phy().features();
3081 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
3082 device_create_info.pNext = NULL;
3083 device_create_info.queueCreateInfoCount = queue_info.size();
3084 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06003085 device_create_info.enabledLayerCount = 0;
3086 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003087 device_create_info.pEnabledFeatures = &features;
3088 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
3089 ASSERT_VK_SUCCESS(err);
3090
3091 VkFence fence;
3092 VkFenceCreateInfo fence_create_info = {};
3093 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3094 fence_create_info.pNext = NULL;
3095 fence_create_info.flags = 0;
3096 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
3097 ASSERT_VK_SUCCESS(err);
3098
3099 // Induce failure by not calling vkDestroyFence
3100 vkDestroyDevice(testDevice, NULL);
3101 m_errorMonitor->VerifyFound();
3102}
3103
3104TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
3105
3106 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
3107 "attempt to delete them from another.");
3108
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003110
Cody Northropc31a84f2016-08-22 10:41:47 -06003111 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003112 VkCommandPool command_pool_one;
3113 VkCommandPool command_pool_two;
3114
3115 VkCommandPoolCreateInfo pool_create_info{};
3116 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3117 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3118 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3119
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003120 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003121
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003122 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003123
3124 VkCommandBuffer command_buffer[9];
3125 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003126 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003127 command_buffer_allocate_info.commandPool = command_pool_one;
3128 command_buffer_allocate_info.commandBufferCount = 9;
3129 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003130 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003131
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003132 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003133
3134 m_errorMonitor->VerifyFound();
3135
3136 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
3137 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
3138}
3139
3140TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
3141 VkResult err;
3142
3143 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003144 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003145
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003147
3148 ASSERT_NO_FATAL_FAILURE(InitState());
3149 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3150
3151 VkDescriptorPoolSize ds_type_count = {};
3152 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3153 ds_type_count.descriptorCount = 1;
3154
3155 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3156 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3157 ds_pool_ci.pNext = NULL;
3158 ds_pool_ci.flags = 0;
3159 ds_pool_ci.maxSets = 1;
3160 ds_pool_ci.poolSizeCount = 1;
3161 ds_pool_ci.pPoolSizes = &ds_type_count;
3162
3163 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003164 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003165 ASSERT_VK_SUCCESS(err);
3166
3167 // Create a second descriptor pool
3168 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003169 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003170 ASSERT_VK_SUCCESS(err);
3171
3172 VkDescriptorSetLayoutBinding dsl_binding = {};
3173 dsl_binding.binding = 0;
3174 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3175 dsl_binding.descriptorCount = 1;
3176 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3177 dsl_binding.pImmutableSamplers = NULL;
3178
3179 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3180 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3181 ds_layout_ci.pNext = NULL;
3182 ds_layout_ci.bindingCount = 1;
3183 ds_layout_ci.pBindings = &dsl_binding;
3184
3185 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003186 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003187 ASSERT_VK_SUCCESS(err);
3188
3189 VkDescriptorSet descriptorSet;
3190 VkDescriptorSetAllocateInfo alloc_info = {};
3191 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3192 alloc_info.descriptorSetCount = 1;
3193 alloc_info.descriptorPool = ds_pool_one;
3194 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003195 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003196 ASSERT_VK_SUCCESS(err);
3197
3198 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
3199
3200 m_errorMonitor->VerifyFound();
3201
3202 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3203 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
3204 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
3205}
3206
3207TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003209
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003210 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003211
3212 ASSERT_NO_FATAL_FAILURE(InitState());
3213
3214 // Pass bogus handle into GetImageMemoryRequirements
3215 VkMemoryRequirements mem_reqs;
3216 uint64_t fakeImageHandle = 0xCADECADE;
3217 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
3218
3219 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
3220
3221 m_errorMonitor->VerifyFound();
3222}
3223
Karl Schultz6addd812016-02-02 17:17:23 -07003224TEST_F(VkLayerTest, PipelineNotBound) {
3225 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003227 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003228
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003230
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003231 ASSERT_NO_FATAL_FAILURE(InitState());
3232 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003233
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003234 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003235 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3236 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003237
3238 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003239 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3240 ds_pool_ci.pNext = NULL;
3241 ds_pool_ci.maxSets = 1;
3242 ds_pool_ci.poolSizeCount = 1;
3243 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003244
3245 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003246 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003247 ASSERT_VK_SUCCESS(err);
3248
3249 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003250 dsl_binding.binding = 0;
3251 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3252 dsl_binding.descriptorCount = 1;
3253 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3254 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003255
3256 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003257 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3258 ds_layout_ci.pNext = NULL;
3259 ds_layout_ci.bindingCount = 1;
3260 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003261
3262 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003263 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003264 ASSERT_VK_SUCCESS(err);
3265
3266 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003267 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003268 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003269 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003270 alloc_info.descriptorPool = ds_pool;
3271 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003272 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003273 ASSERT_VK_SUCCESS(err);
3274
3275 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003276 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3277 pipeline_layout_ci.pNext = NULL;
3278 pipeline_layout_ci.setLayoutCount = 1;
3279 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003280
3281 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003282 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003283 ASSERT_VK_SUCCESS(err);
3284
Mark Youngad779052016-01-06 14:26:04 -07003285 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003286
3287 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003288 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003289
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003290 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003291
Chia-I Wuf7458c52015-10-26 21:10:41 +08003292 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3293 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3294 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003295}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003296
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003297TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
3298 VkResult err;
3299
3300 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
3301 "during bind[Buffer|Image]Memory time");
3302
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003303 ASSERT_NO_FATAL_FAILURE(InitState());
3304
3305 // Create an image, allocate memory, set a bad typeIndex and then try to
3306 // bind it
3307 VkImage image;
3308 VkDeviceMemory mem;
3309 VkMemoryRequirements mem_reqs;
3310 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3311 const int32_t tex_width = 32;
3312 const int32_t tex_height = 32;
3313
3314 VkImageCreateInfo image_create_info = {};
3315 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3316 image_create_info.pNext = NULL;
3317 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3318 image_create_info.format = tex_format;
3319 image_create_info.extent.width = tex_width;
3320 image_create_info.extent.height = tex_height;
3321 image_create_info.extent.depth = 1;
3322 image_create_info.mipLevels = 1;
3323 image_create_info.arrayLayers = 1;
3324 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3325 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3326 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3327 image_create_info.flags = 0;
3328
3329 VkMemoryAllocateInfo mem_alloc = {};
3330 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3331 mem_alloc.pNext = NULL;
3332 mem_alloc.allocationSize = 0;
3333 mem_alloc.memoryTypeIndex = 0;
3334
3335 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
3336 ASSERT_VK_SUCCESS(err);
3337
3338 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
3339 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003340
3341 // Introduce Failure, select invalid TypeIndex
3342 VkPhysicalDeviceMemoryProperties memory_info;
3343
3344 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
3345 unsigned int i;
3346 for (i = 0; i < memory_info.memoryTypeCount; i++) {
3347 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
3348 mem_alloc.memoryTypeIndex = i;
3349 break;
3350 }
3351 }
3352 if (i >= memory_info.memoryTypeCount) {
3353 printf("No invalid memory type index could be found; skipped.\n");
3354 vkDestroyImage(m_device->device(), image, NULL);
3355 return;
3356 }
3357
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003359
3360 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3361 ASSERT_VK_SUCCESS(err);
3362
3363 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3364 (void)err;
3365
3366 m_errorMonitor->VerifyFound();
3367
3368 vkDestroyImage(m_device->device(), image, NULL);
3369 vkFreeMemory(m_device->device(), mem, NULL);
3370}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003371
Karl Schultz6addd812016-02-02 17:17:23 -07003372TEST_F(VkLayerTest, BindInvalidMemory) {
3373 VkResult err;
3374 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003375
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003377
Tobin Ehlisec598302015-09-15 15:02:17 -06003378 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003379
3380 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07003381 VkImage image;
3382 VkDeviceMemory mem;
3383 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003384
Karl Schultz6addd812016-02-02 17:17:23 -07003385 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3386 const int32_t tex_width = 32;
3387 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003388
3389 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003390 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3391 image_create_info.pNext = NULL;
3392 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3393 image_create_info.format = tex_format;
3394 image_create_info.extent.width = tex_width;
3395 image_create_info.extent.height = tex_height;
3396 image_create_info.extent.depth = 1;
3397 image_create_info.mipLevels = 1;
3398 image_create_info.arrayLayers = 1;
3399 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3400 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3401 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3402 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003403
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003404 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003405 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3406 mem_alloc.pNext = NULL;
3407 mem_alloc.allocationSize = 0;
3408 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003409
Chia-I Wuf7458c52015-10-26 21:10:41 +08003410 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003411 ASSERT_VK_SUCCESS(err);
3412
Karl Schultz6addd812016-02-02 17:17:23 -07003413 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003414
3415 mem_alloc.allocationSize = mem_reqs.size;
3416
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003417 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003418 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003419
3420 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003421 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003422 ASSERT_VK_SUCCESS(err);
3423
3424 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003425 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003426
3427 // Try to bind free memory that has been freed
3428 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3429 // This may very well return an error.
3430 (void)err;
3431
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003432 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003433
Chia-I Wuf7458c52015-10-26 21:10:41 +08003434 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003435}
3436
Karl Schultz6addd812016-02-02 17:17:23 -07003437TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
3438 VkResult err;
3439 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003440
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003442
Tobin Ehlisec598302015-09-15 15:02:17 -06003443 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003444
Karl Schultz6addd812016-02-02 17:17:23 -07003445 // Create an image object, allocate memory, destroy the object and then try
3446 // to bind it
3447 VkImage image;
3448 VkDeviceMemory mem;
3449 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003450
Karl Schultz6addd812016-02-02 17:17:23 -07003451 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3452 const int32_t tex_width = 32;
3453 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003454
3455 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003456 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3457 image_create_info.pNext = NULL;
3458 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3459 image_create_info.format = tex_format;
3460 image_create_info.extent.width = tex_width;
3461 image_create_info.extent.height = tex_height;
3462 image_create_info.extent.depth = 1;
3463 image_create_info.mipLevels = 1;
3464 image_create_info.arrayLayers = 1;
3465 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3466 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3467 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3468 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003469
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003470 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003471 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3472 mem_alloc.pNext = NULL;
3473 mem_alloc.allocationSize = 0;
3474 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003475
Chia-I Wuf7458c52015-10-26 21:10:41 +08003476 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003477 ASSERT_VK_SUCCESS(err);
3478
Karl Schultz6addd812016-02-02 17:17:23 -07003479 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003480
3481 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003482 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003483 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003484
3485 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003486 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003487 ASSERT_VK_SUCCESS(err);
3488
3489 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003490 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003491 ASSERT_VK_SUCCESS(err);
3492
3493 // Now Try to bind memory to this destroyed object
3494 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3495 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07003496 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003497
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003498 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003499
Chia-I Wuf7458c52015-10-26 21:10:41 +08003500 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003501}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003502
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003503#endif // OBJ_TRACKER_TESTS
3504
Tobin Ehlis0788f522015-05-26 16:11:58 -06003505#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003506
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003507TEST_F(VkLayerTest, ImageSampleCounts) {
3508
3509 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
3510 "validation errors.");
3511 ASSERT_NO_FATAL_FAILURE(InitState());
3512
3513 VkMemoryPropertyFlags reqs = 0;
3514 VkImageCreateInfo image_create_info = {};
3515 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3516 image_create_info.pNext = NULL;
3517 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3518 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3519 image_create_info.extent.width = 256;
3520 image_create_info.extent.height = 256;
3521 image_create_info.extent.depth = 1;
3522 image_create_info.mipLevels = 1;
3523 image_create_info.arrayLayers = 1;
3524 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3525 image_create_info.flags = 0;
3526
3527 VkImageBlit blit_region = {};
3528 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3529 blit_region.srcSubresource.baseArrayLayer = 0;
3530 blit_region.srcSubresource.layerCount = 1;
3531 blit_region.srcSubresource.mipLevel = 0;
3532 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3533 blit_region.dstSubresource.baseArrayLayer = 0;
3534 blit_region.dstSubresource.layerCount = 1;
3535 blit_region.dstSubresource.mipLevel = 0;
3536
3537 // Create two images, the source with sampleCount = 2, and attempt to blit
3538 // between them
3539 {
3540 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003541 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003542 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003543 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003544 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003545 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003546 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003547 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003548 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3550 "of VK_SAMPLE_COUNT_2_BIT but "
3551 "must be VK_SAMPLE_COUNT_1_BIT");
3552 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3553 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003554 m_errorMonitor->VerifyFound();
3555 m_commandBuffer->EndCommandBuffer();
3556 }
3557
3558 // Create two images, the dest with sampleCount = 4, and attempt to blit
3559 // between them
3560 {
3561 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003562 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003563 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003564 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003565 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003566 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003567 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003568 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003569 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3571 "of VK_SAMPLE_COUNT_4_BIT but "
3572 "must be VK_SAMPLE_COUNT_1_BIT");
3573 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3574 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003575 m_errorMonitor->VerifyFound();
3576 m_commandBuffer->EndCommandBuffer();
3577 }
3578
3579 VkBufferImageCopy copy_region = {};
3580 copy_region.bufferRowLength = 128;
3581 copy_region.bufferImageHeight = 128;
3582 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3583 copy_region.imageSubresource.layerCount = 1;
3584 copy_region.imageExtent.height = 64;
3585 copy_region.imageExtent.width = 64;
3586 copy_region.imageExtent.depth = 1;
3587
3588 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3589 // buffer to image
3590 {
3591 vk_testing::Buffer src_buffer;
3592 VkMemoryPropertyFlags reqs = 0;
3593 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3594 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003595 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003596 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003597 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003598 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3600 "of VK_SAMPLE_COUNT_8_BIT but "
3601 "must be VK_SAMPLE_COUNT_1_BIT");
3602 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3603 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003604 m_errorMonitor->VerifyFound();
3605 m_commandBuffer->EndCommandBuffer();
3606 }
3607
3608 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3609 // image to buffer
3610 {
3611 vk_testing::Buffer dst_buffer;
3612 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3613 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003614 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003615 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003616 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003617 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3619 "of VK_SAMPLE_COUNT_2_BIT but "
3620 "must be VK_SAMPLE_COUNT_1_BIT");
3621 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003622 dst_buffer.handle(), 1, &copy_region);
3623 m_errorMonitor->VerifyFound();
3624 m_commandBuffer->EndCommandBuffer();
3625 }
3626}
3627
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003628TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3629 VkResult err;
3630 bool pass;
3631
3632 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3633 ASSERT_NO_FATAL_FAILURE(InitState());
3634
3635 // If w/d/h granularity is 1, test is not meaningful
3636 // TODO: When virtual device limits are available, create a set of limits for this test that
3637 // will always have a granularity of > 1 for w, h, and d
3638 auto index = m_device->graphics_queue_node_index_;
3639 auto queue_family_properties = m_device->phy().queue_properties();
3640
3641 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3642 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3643 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3644 return;
3645 }
3646
3647 // Create two images of different types and try to copy between them
3648 VkImage srcImage;
3649 VkImage dstImage;
3650 VkDeviceMemory srcMem;
3651 VkDeviceMemory destMem;
3652 VkMemoryRequirements memReqs;
3653
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003654 VkImageCreateInfo image_create_info = {};
3655 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3656 image_create_info.pNext = NULL;
3657 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3658 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3659 image_create_info.extent.width = 32;
3660 image_create_info.extent.height = 32;
3661 image_create_info.extent.depth = 1;
3662 image_create_info.mipLevels = 1;
3663 image_create_info.arrayLayers = 4;
3664 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3665 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3666 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3667 image_create_info.flags = 0;
3668
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003669 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003670 ASSERT_VK_SUCCESS(err);
3671
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003672 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003673 ASSERT_VK_SUCCESS(err);
3674
3675 // Allocate memory
3676 VkMemoryAllocateInfo memAlloc = {};
3677 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3678 memAlloc.pNext = NULL;
3679 memAlloc.allocationSize = 0;
3680 memAlloc.memoryTypeIndex = 0;
3681
3682 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3683 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003684 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003685 ASSERT_TRUE(pass);
3686 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3687 ASSERT_VK_SUCCESS(err);
3688
3689 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3690 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003691 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003692 ASSERT_VK_SUCCESS(err);
3693 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3694 ASSERT_VK_SUCCESS(err);
3695
3696 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3697 ASSERT_VK_SUCCESS(err);
3698 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3699 ASSERT_VK_SUCCESS(err);
3700
3701 BeginCommandBuffer();
3702 VkImageCopy copyRegion;
3703 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3704 copyRegion.srcSubresource.mipLevel = 0;
3705 copyRegion.srcSubresource.baseArrayLayer = 0;
3706 copyRegion.srcSubresource.layerCount = 1;
3707 copyRegion.srcOffset.x = 0;
3708 copyRegion.srcOffset.y = 0;
3709 copyRegion.srcOffset.z = 0;
3710 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3711 copyRegion.dstSubresource.mipLevel = 0;
3712 copyRegion.dstSubresource.baseArrayLayer = 0;
3713 copyRegion.dstSubresource.layerCount = 1;
3714 copyRegion.dstOffset.x = 0;
3715 copyRegion.dstOffset.y = 0;
3716 copyRegion.dstOffset.z = 0;
3717 copyRegion.extent.width = 1;
3718 copyRegion.extent.height = 1;
3719 copyRegion.extent.depth = 1;
3720
3721 // Introduce failure by setting srcOffset to a bad granularity value
3722 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3724 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003725 m_errorMonitor->VerifyFound();
3726
3727 // Introduce failure by setting extent to a bad granularity value
3728 copyRegion.srcOffset.y = 0;
3729 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3731 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003732 m_errorMonitor->VerifyFound();
3733
3734 // Now do some buffer/image copies
3735 vk_testing::Buffer buffer;
3736 VkMemoryPropertyFlags reqs = 0;
3737 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3738 VkBufferImageCopy region = {};
3739 region.bufferOffset = 0;
3740 region.bufferRowLength = 3;
3741 region.bufferImageHeight = 128;
3742 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3743 region.imageSubresource.layerCount = 1;
3744 region.imageExtent.height = 16;
3745 region.imageExtent.width = 16;
3746 region.imageExtent.depth = 1;
3747 region.imageOffset.x = 0;
3748 region.imageOffset.y = 0;
3749 region.imageOffset.z = 0;
3750
3751 // Introduce failure by setting bufferRowLength to a bad granularity value
3752 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3754 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3755 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003756 m_errorMonitor->VerifyFound();
3757 region.bufferRowLength = 128;
3758
3759 // Introduce failure by setting bufferOffset to a bad granularity value
3760 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3762 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3763 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003764 m_errorMonitor->VerifyFound();
3765 region.bufferOffset = 0;
3766
3767 // Introduce failure by setting bufferImageHeight to a bad granularity value
3768 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3770 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3771 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003772 m_errorMonitor->VerifyFound();
3773 region.bufferImageHeight = 128;
3774
3775 // Introduce failure by setting imageExtent to a bad granularity value
3776 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3778 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3779 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003780 m_errorMonitor->VerifyFound();
3781 region.imageExtent.width = 16;
3782
3783 // Introduce failure by setting imageOffset to a bad granularity value
3784 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3786 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3787 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003788 m_errorMonitor->VerifyFound();
3789
3790 EndCommandBuffer();
3791
3792 vkDestroyImage(m_device->device(), srcImage, NULL);
3793 vkDestroyImage(m_device->device(), dstImage, NULL);
3794 vkFreeMemory(m_device->device(), srcMem, NULL);
3795 vkFreeMemory(m_device->device(), destMem, NULL);
3796}
3797
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003798TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003799 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
3800 "attempt to submit them on a queue created in a different "
3801 "queue family.");
3802
Cody Northropc31a84f2016-08-22 10:41:47 -06003803 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003804 // This test is meaningless unless we have multiple queue families
3805 auto queue_family_properties = m_device->phy().queue_properties();
3806 if (queue_family_properties.size() < 2) {
3807 return;
3808 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003810 // Get safe index of another queue family
3811 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3812 ASSERT_NO_FATAL_FAILURE(InitState());
3813 // Create a second queue using a different queue family
3814 VkQueue other_queue;
3815 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3816
3817 // Record an empty cmd buffer
3818 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3819 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3820 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3821 vkEndCommandBuffer(m_commandBuffer->handle());
3822
3823 // And submit on the wrong queue
3824 VkSubmitInfo submit_info = {};
3825 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3826 submit_info.commandBufferCount = 1;
3827 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003828 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003829
3830 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003831}
3832
Chris Forbes48a53902016-06-30 11:46:27 +12003833TEST_F(VkLayerTest, RenderPassInitialLayoutUndefined) {
3834 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
3835 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
3836 "the command buffer has prior knowledge of that "
3837 "attachment's layout.");
3838
3839 m_errorMonitor->ExpectSuccess();
3840
3841 ASSERT_NO_FATAL_FAILURE(InitState());
3842
3843 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003844 VkAttachmentDescription attachment = {0,
3845 VK_FORMAT_R8G8B8A8_UNORM,
3846 VK_SAMPLE_COUNT_1_BIT,
3847 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3848 VK_ATTACHMENT_STORE_OP_STORE,
3849 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3850 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3851 VK_IMAGE_LAYOUT_UNDEFINED,
3852 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003853
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003854 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003855
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003856 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003857
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003858 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003859
3860 VkRenderPass rp;
3861 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3862 ASSERT_VK_SUCCESS(err);
3863
3864 // A compatible framebuffer.
3865 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003866 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbes48a53902016-06-30 11:46:27 +12003867 ASSERT_TRUE(image.initialized());
3868
3869 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003870 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3871 nullptr,
3872 0,
3873 image.handle(),
3874 VK_IMAGE_VIEW_TYPE_2D,
3875 VK_FORMAT_R8G8B8A8_UNORM,
3876 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3877 VK_COMPONENT_SWIZZLE_IDENTITY},
3878 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes48a53902016-06-30 11:46:27 +12003879 };
3880 VkImageView view;
3881 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3882 ASSERT_VK_SUCCESS(err);
3883
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003884 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes48a53902016-06-30 11:46:27 +12003885 VkFramebuffer fb;
3886 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3887 ASSERT_VK_SUCCESS(err);
3888
3889 // Record a single command buffer which uses this renderpass twice. The
3890 // bug is triggered at the beginning of the second renderpass, when the
3891 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003892 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003893 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003894 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003895 vkCmdEndRenderPass(m_commandBuffer->handle());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003896 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003897
3898 m_errorMonitor->VerifyNotFound();
3899
3900 vkCmdEndRenderPass(m_commandBuffer->handle());
3901 EndCommandBuffer();
3902
3903 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3904 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3905 vkDestroyImageView(m_device->device(), view, nullptr);
3906}
3907
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003908TEST_F(VkLayerTest, FramebufferBindingDestroyCommandPool) {
3909 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
3910 "command buffer, bind them together, then destroy "
3911 "command pool and framebuffer and verify there are no "
3912 "errors.");
3913
3914 m_errorMonitor->ExpectSuccess();
3915
3916 ASSERT_NO_FATAL_FAILURE(InitState());
3917
3918 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003919 VkAttachmentDescription attachment = {0,
3920 VK_FORMAT_R8G8B8A8_UNORM,
3921 VK_SAMPLE_COUNT_1_BIT,
3922 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3923 VK_ATTACHMENT_STORE_OP_STORE,
3924 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3925 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3926 VK_IMAGE_LAYOUT_UNDEFINED,
3927 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003928
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003929 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003930
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003931 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003933 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003934
3935 VkRenderPass rp;
3936 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3937 ASSERT_VK_SUCCESS(err);
3938
3939 // A compatible framebuffer.
3940 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003941 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003942 ASSERT_TRUE(image.initialized());
3943
3944 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003945 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3946 nullptr,
3947 0,
3948 image.handle(),
3949 VK_IMAGE_VIEW_TYPE_2D,
3950 VK_FORMAT_R8G8B8A8_UNORM,
3951 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3952 VK_COMPONENT_SWIZZLE_IDENTITY},
3953 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003954 };
3955 VkImageView view;
3956 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3957 ASSERT_VK_SUCCESS(err);
3958
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003959 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003960 VkFramebuffer fb;
3961 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3962 ASSERT_VK_SUCCESS(err);
3963
3964 // Explicitly create a command buffer to bind the FB to so that we can then
3965 // destroy the command pool in order to implicitly free command buffer
3966 VkCommandPool command_pool;
3967 VkCommandPoolCreateInfo pool_create_info{};
3968 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3969 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3970 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003971 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003972
3973 VkCommandBuffer command_buffer;
3974 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003975 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003976 command_buffer_allocate_info.commandPool = command_pool;
3977 command_buffer_allocate_info.commandBufferCount = 1;
3978 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003979 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003980
3981 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003982 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003983 VkCommandBufferBeginInfo begin_info{};
3984 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3985 vkBeginCommandBuffer(command_buffer, &begin_info);
3986
3987 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3988 vkCmdEndRenderPass(command_buffer);
3989 vkEndCommandBuffer(command_buffer);
Mark Lobodzinski7d10a822016-08-03 14:08:40 -06003990 vkDestroyImageView(m_device->device(), view, nullptr);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003991 // Destroy command pool to implicitly free command buffer
3992 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3993 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3994 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3995 m_errorMonitor->VerifyNotFound();
3996}
3997
Chris Forbes51bf7c92016-06-30 15:22:08 +12003998TEST_F(VkLayerTest, RenderPassSubpassZeroTransitionsApplied) {
3999 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
4000 "transitions for the first subpass");
4001
4002 m_errorMonitor->ExpectSuccess();
4003
4004 ASSERT_NO_FATAL_FAILURE(InitState());
4005
4006 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004007 VkAttachmentDescription attachment = {0,
4008 VK_FORMAT_R8G8B8A8_UNORM,
4009 VK_SAMPLE_COUNT_1_BIT,
4010 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4011 VK_ATTACHMENT_STORE_OP_STORE,
4012 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4013 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4014 VK_IMAGE_LAYOUT_UNDEFINED,
4015 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004016
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004017 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004018
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004019 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004021 VkSubpassDependency dep = {0,
4022 0,
4023 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4024 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4025 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4026 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4027 VK_DEPENDENCY_BY_REGION_BIT};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004028
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004029 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004030
4031 VkResult err;
4032 VkRenderPass rp;
4033 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4034 ASSERT_VK_SUCCESS(err);
4035
4036 // A compatible framebuffer.
4037 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004038 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004039 ASSERT_TRUE(image.initialized());
4040
4041 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004042 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4043 nullptr,
4044 0,
4045 image.handle(),
4046 VK_IMAGE_VIEW_TYPE_2D,
4047 VK_FORMAT_R8G8B8A8_UNORM,
4048 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
4049 VK_COMPONENT_SWIZZLE_IDENTITY},
4050 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes51bf7c92016-06-30 15:22:08 +12004051 };
4052 VkImageView view;
4053 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4054 ASSERT_VK_SUCCESS(err);
4055
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004056 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004057 VkFramebuffer fb;
4058 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4059 ASSERT_VK_SUCCESS(err);
4060
4061 // Record a single command buffer which issues a pipeline barrier w/
4062 // image memory barrier for the attachment. This detects the previously
4063 // missing tracking of the subpass layout by throwing a validation error
4064 // if it doesn't occur.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004065 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004066 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004067 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004068
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004069 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
4070 nullptr,
4071 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4072 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4073 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4074 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4075 VK_QUEUE_FAMILY_IGNORED,
4076 VK_QUEUE_FAMILY_IGNORED,
4077 image.handle(),
4078 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
4079 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4080 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
4081 &imb);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004082
4083 vkCmdEndRenderPass(m_commandBuffer->handle());
4084 m_errorMonitor->VerifyNotFound();
4085 EndCommandBuffer();
4086
4087 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4088 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4089 vkDestroyImageView(m_device->device(), view, nullptr);
4090}
4091
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004092TEST_F(VkLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
4093 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
4094 "is used as a depth/stencil framebuffer attachment, the "
4095 "aspectMask is ignored and both depth and stencil image "
4096 "subresources are used.");
4097
4098 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004099 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
4100 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004101 return;
4102 }
4103
4104 m_errorMonitor->ExpectSuccess();
4105
4106 ASSERT_NO_FATAL_FAILURE(InitState());
4107
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004108 VkAttachmentDescription attachment = {0,
4109 VK_FORMAT_D32_SFLOAT_S8_UINT,
4110 VK_SAMPLE_COUNT_1_BIT,
4111 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4112 VK_ATTACHMENT_STORE_OP_STORE,
4113 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4114 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4115 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
4116 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004117
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004118 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004119
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004120 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004121
4122 VkSubpassDependency dep = {0,
4123 0,
4124 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4125 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4126 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4127 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4128 VK_DEPENDENCY_BY_REGION_BIT};
4129
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004130 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004131
4132 VkResult err;
4133 VkRenderPass rp;
4134 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4135 ASSERT_VK_SUCCESS(err);
4136
4137 VkImageObj image(m_device);
4138 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
4139 0x26, // usage
4140 VK_IMAGE_TILING_OPTIMAL, 0);
4141 ASSERT_TRUE(image.initialized());
4142 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
4143
4144 VkImageViewCreateInfo ivci = {
4145 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4146 nullptr,
4147 0,
4148 image.handle(),
4149 VK_IMAGE_VIEW_TYPE_2D,
4150 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004151 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004152 {0x2, 0, 1, 0, 1},
4153 };
4154 VkImageView view;
4155 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4156 ASSERT_VK_SUCCESS(err);
4157
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004158 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004159 VkFramebuffer fb;
4160 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4161 ASSERT_VK_SUCCESS(err);
4162
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004163 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004164 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004165 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004166
4167 VkImageMemoryBarrier imb = {};
4168 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
4169 imb.pNext = nullptr;
4170 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4171 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
4172 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4173 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4174 imb.srcQueueFamilyIndex = 0;
4175 imb.dstQueueFamilyIndex = 0;
4176 imb.image = image.handle();
4177 imb.subresourceRange.aspectMask = 0x6;
4178 imb.subresourceRange.baseMipLevel = 0;
4179 imb.subresourceRange.levelCount = 0x1;
4180 imb.subresourceRange.baseArrayLayer = 0;
4181 imb.subresourceRange.layerCount = 0x1;
4182
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004183 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4184 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004185 &imb);
4186
4187 vkCmdEndRenderPass(m_commandBuffer->handle());
4188 EndCommandBuffer();
4189 QueueCommandBuffer(false);
4190 m_errorMonitor->VerifyNotFound();
4191
4192 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4193 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4194 vkDestroyImageView(m_device->device(), view, nullptr);
4195}
Tony Barbourd5f7b822016-08-02 15:39:33 -06004196
Tony Barbour4e919972016-08-09 13:27:40 -06004197TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
4198 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
4199 "with extent outside of framebuffer");
4200 ASSERT_NO_FATAL_FAILURE(InitState());
4201 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4202
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
4204 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06004205
4206 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
4207 m_renderPassBeginInfo.renderArea.extent.width = 257;
4208 m_renderPassBeginInfo.renderArea.extent.height = 257;
4209 BeginCommandBuffer();
4210 m_errorMonitor->VerifyFound();
4211}
4212
4213TEST_F(VkLayerTest, DisabledIndependentBlend) {
4214 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
4215 "blend and then specifying different blend states for two "
4216 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06004217 VkPhysicalDeviceFeatures features = {};
4218 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06004219 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06004220
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4222 "Invalid Pipeline CreateInfo: If independent blend feature not "
4223 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06004224
Cody Northropc31a84f2016-08-22 10:41:47 -06004225 VkDescriptorSetObj descriptorSet(m_device);
4226 descriptorSet.AppendDummy();
4227 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06004228
Cody Northropc31a84f2016-08-22 10:41:47 -06004229 VkPipelineObj pipeline(m_device);
4230 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004231 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06004232 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06004233
Cody Northropc31a84f2016-08-22 10:41:47 -06004234 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
4235 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4236 att_state1.blendEnable = VK_TRUE;
4237 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4238 att_state2.blendEnable = VK_FALSE;
4239 pipeline.AddColorAttachment(0, &att_state1);
4240 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004241 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06004242 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06004243}
4244
4245TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
4246 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
4247 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06004248 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06004249
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4251 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06004252
4253 // Create a renderPass with a single color attachment
4254 VkAttachmentReference attach = {};
4255 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4256 VkSubpassDescription subpass = {};
4257 VkRenderPassCreateInfo rpci = {};
4258 rpci.subpassCount = 1;
4259 rpci.pSubpasses = &subpass;
4260 rpci.attachmentCount = 1;
4261 VkAttachmentDescription attach_desc = {};
4262 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4263 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4264 rpci.pAttachments = &attach_desc;
4265 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4266 VkRenderPass rp;
4267 subpass.pDepthStencilAttachment = &attach;
4268 subpass.pColorAttachments = NULL;
4269 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4270 m_errorMonitor->VerifyFound();
4271}
4272
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004273TEST_F(VkLayerTest, RenderPassTransitionsAttachmentUnused) {
4274 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
4275 "errors, when an attachment reference is "
4276 "VK_ATTACHMENT_UNUSED");
4277
4278 m_errorMonitor->ExpectSuccess();
4279
4280 ASSERT_NO_FATAL_FAILURE(InitState());
4281
4282 // A renderpass with no attachments
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004283 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004284
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004285 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004287 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004288
4289 VkRenderPass rp;
4290 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4291 ASSERT_VK_SUCCESS(err);
4292
4293 // A compatible framebuffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004294 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004295 VkFramebuffer fb;
4296 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4297 ASSERT_VK_SUCCESS(err);
4298
4299 // Record a command buffer which just begins and ends the renderpass. The
4300 // bug manifests in BeginRenderPass.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004301 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004302 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004303 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004304 vkCmdEndRenderPass(m_commandBuffer->handle());
4305 m_errorMonitor->VerifyNotFound();
4306 EndCommandBuffer();
4307
4308 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4309 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4310}
4311
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004312// This is a positive test. No errors are expected.
4313TEST_F(VkLayerTest, StencilLoadOp) {
4314 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
4315 "CLEAR. stencil[Load|Store]Op used to be ignored.");
4316 VkResult result = VK_SUCCESS;
4317 VkImageFormatProperties formatProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004318 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
4319 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
4320 &formatProps);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004321 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
4322 return;
4323 }
4324
4325 ASSERT_NO_FATAL_FAILURE(InitState());
4326 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
4327 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004328 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004329 VkAttachmentDescription att = {};
4330 VkAttachmentReference ref = {};
4331 att.format = depth_stencil_fmt;
Chris Forbes787b4532016-09-16 16:45:16 +12004332 att.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004333 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
4334 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
4335 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
4336 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
4337 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4338 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4339
4340 VkClearValue clear;
4341 clear.depthStencil.depth = 1.0;
4342 clear.depthStencil.stencil = 0;
4343 ref.attachment = 0;
4344 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4345
4346 VkSubpassDescription subpass = {};
4347 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
4348 subpass.flags = 0;
4349 subpass.inputAttachmentCount = 0;
4350 subpass.pInputAttachments = NULL;
4351 subpass.colorAttachmentCount = 0;
4352 subpass.pColorAttachments = NULL;
4353 subpass.pResolveAttachments = NULL;
4354 subpass.pDepthStencilAttachment = &ref;
4355 subpass.preserveAttachmentCount = 0;
4356 subpass.pPreserveAttachments = NULL;
4357
4358 VkRenderPass rp;
4359 VkRenderPassCreateInfo rp_info = {};
4360 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4361 rp_info.attachmentCount = 1;
4362 rp_info.pAttachments = &att;
4363 rp_info.subpassCount = 1;
4364 rp_info.pSubpasses = &subpass;
4365 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
4366 ASSERT_VK_SUCCESS(result);
4367
4368 VkImageView *depthView = m_depthStencil->BindInfo();
4369 VkFramebufferCreateInfo fb_info = {};
4370 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4371 fb_info.pNext = NULL;
4372 fb_info.renderPass = rp;
4373 fb_info.attachmentCount = 1;
4374 fb_info.pAttachments = depthView;
4375 fb_info.width = 100;
4376 fb_info.height = 100;
4377 fb_info.layers = 1;
4378 VkFramebuffer fb;
4379 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4380 ASSERT_VK_SUCCESS(result);
4381
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004382 VkRenderPassBeginInfo rpbinfo = {};
4383 rpbinfo.clearValueCount = 1;
4384 rpbinfo.pClearValues = &clear;
4385 rpbinfo.pNext = NULL;
4386 rpbinfo.renderPass = rp;
4387 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
4388 rpbinfo.renderArea.extent.width = 100;
4389 rpbinfo.renderArea.extent.height = 100;
4390 rpbinfo.renderArea.offset.x = 0;
4391 rpbinfo.renderArea.offset.y = 0;
4392 rpbinfo.framebuffer = fb;
4393
4394 VkFence fence = {};
4395 VkFenceCreateInfo fence_ci = {};
4396 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4397 fence_ci.pNext = nullptr;
4398 fence_ci.flags = 0;
4399 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
4400 ASSERT_VK_SUCCESS(result);
4401
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004402 m_commandBuffer->BeginCommandBuffer();
4403 m_commandBuffer->BeginRenderPass(rpbinfo);
4404 m_commandBuffer->EndRenderPass();
4405 m_commandBuffer->EndCommandBuffer();
4406 m_commandBuffer->QueueCommandBuffer(fence);
4407
4408 VkImageObj destImage(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004409 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004410 VK_IMAGE_TILING_OPTIMAL, 0);
4411 VkImageMemoryBarrier barrier = {};
4412 VkImageSubresourceRange range;
4413 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004414 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4415 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004416 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4417 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4418 barrier.image = m_depthStencil->handle();
4419 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
4420 range.baseMipLevel = 0;
4421 range.levelCount = 1;
4422 range.baseArrayLayer = 0;
4423 range.layerCount = 1;
4424 barrier.subresourceRange = range;
4425 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4426 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
4427 cmdbuf.BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004428 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4429 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004430 barrier.srcAccessMask = 0;
4431 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4432 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4433 barrier.image = destImage.handle();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004434 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4435 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4436 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004437 VkImageCopy cregion;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004438 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004439 cregion.srcSubresource.mipLevel = 0;
4440 cregion.srcSubresource.baseArrayLayer = 0;
4441 cregion.srcSubresource.layerCount = 1;
4442 cregion.srcOffset.x = 0;
4443 cregion.srcOffset.y = 0;
4444 cregion.srcOffset.z = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004445 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004446 cregion.dstSubresource.mipLevel = 0;
4447 cregion.dstSubresource.baseArrayLayer = 0;
4448 cregion.dstSubresource.layerCount = 1;
4449 cregion.dstOffset.x = 0;
4450 cregion.dstOffset.y = 0;
4451 cregion.dstOffset.z = 0;
4452 cregion.extent.width = 100;
4453 cregion.extent.height = 100;
4454 cregion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004455 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004456 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
4457 cmdbuf.EndCommandBuffer();
4458
4459 VkSubmitInfo submit_info;
4460 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4461 submit_info.pNext = NULL;
4462 submit_info.waitSemaphoreCount = 0;
4463 submit_info.pWaitSemaphores = NULL;
4464 submit_info.pWaitDstStageMask = NULL;
4465 submit_info.commandBufferCount = 1;
4466 submit_info.pCommandBuffers = &cmdbuf.handle();
4467 submit_info.signalSemaphoreCount = 0;
4468 submit_info.pSignalSemaphores = NULL;
4469
4470 m_errorMonitor->ExpectSuccess();
4471 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4472 m_errorMonitor->VerifyNotFound();
4473
Mark Lobodzinskid0440da2016-06-17 15:10:03 -06004474 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004475 vkDestroyFence(m_device->device(), fence, nullptr);
4476 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4477 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4478}
4479
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004480TEST_F(VkLayerTest, UnusedPreserveAttachment) {
4481 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
4482 "attachment reference of VK_ATTACHMENT_UNUSED");
4483
4484 ASSERT_NO_FATAL_FAILURE(InitState());
4485 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4486
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004488
4489 VkAttachmentReference color_attach = {};
4490 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4491 color_attach.attachment = 0;
4492 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
4493 VkSubpassDescription subpass = {};
4494 subpass.colorAttachmentCount = 1;
4495 subpass.pColorAttachments = &color_attach;
4496 subpass.preserveAttachmentCount = 1;
4497 subpass.pPreserveAttachments = &preserve_attachment;
4498
4499 VkRenderPassCreateInfo rpci = {};
4500 rpci.subpassCount = 1;
4501 rpci.pSubpasses = &subpass;
4502 rpci.attachmentCount = 1;
4503 VkAttachmentDescription attach_desc = {};
4504 attach_desc.format = VK_FORMAT_UNDEFINED;
4505 rpci.pAttachments = &attach_desc;
4506 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4507 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004508 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004509
4510 m_errorMonitor->VerifyFound();
4511
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004512 if (result == VK_SUCCESS) {
4513 vkDestroyRenderPass(m_device->device(), rp, NULL);
4514 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004515}
4516
Chris Forbesc5389742016-06-29 11:49:23 +12004517TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004518 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
4519 "when the source of a subpass multisample resolve "
4520 "does not have multiple samples.");
4521
Chris Forbesc5389742016-06-29 11:49:23 +12004522 ASSERT_NO_FATAL_FAILURE(InitState());
4523
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4525 "Subpass 0 requests multisample resolve from attachment 0 which has "
4526 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004527
4528 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004529 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4530 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4531 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4532 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4533 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4534 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004535 };
4536
4537 VkAttachmentReference color = {
4538 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4539 };
4540
4541 VkAttachmentReference resolve = {
4542 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4543 };
4544
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004545 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004546
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004547 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004548
4549 VkRenderPass rp;
4550 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4551
4552 m_errorMonitor->VerifyFound();
4553
4554 if (err == VK_SUCCESS)
4555 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4556}
4557
4558TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004559 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4560 "when a subpass multisample resolve operation is "
4561 "requested, and the destination of that resolve has "
4562 "multiple samples.");
4563
Chris Forbesc5389742016-06-29 11:49:23 +12004564 ASSERT_NO_FATAL_FAILURE(InitState());
4565
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4567 "Subpass 0 requests multisample resolve into attachment 1, which "
4568 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004569
4570 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004571 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4572 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4573 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4574 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4575 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4576 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004577 };
4578
4579 VkAttachmentReference color = {
4580 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4581 };
4582
4583 VkAttachmentReference resolve = {
4584 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4585 };
4586
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004587 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004588
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004589 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004590
4591 VkRenderPass rp;
4592 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4593
4594 m_errorMonitor->VerifyFound();
4595
4596 if (err == VK_SUCCESS)
4597 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4598}
4599
Chris Forbes3f128ef2016-06-29 14:58:53 +12004600TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004601 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4602 "when the color and depth attachments used by a subpass "
4603 "have inconsistent sample counts");
4604
Chris Forbes3f128ef2016-06-29 14:58:53 +12004605 ASSERT_NO_FATAL_FAILURE(InitState());
4606
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4608 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12004609
4610 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004611 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4612 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4613 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4614 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4615 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4616 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12004617 };
4618
4619 VkAttachmentReference color[] = {
4620 {
4621 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4622 },
4623 {
4624 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4625 },
4626 };
4627
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004628 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004629
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004630 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004631
4632 VkRenderPass rp;
4633 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4634
4635 m_errorMonitor->VerifyFound();
4636
4637 if (err == VK_SUCCESS)
4638 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4639}
4640
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004641TEST_F(VkLayerTest, FramebufferCreateErrors) {
4642 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
4643 " 1. Mismatch between fb & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004644 " 2. Use a color image as depthStencil attachment\n"
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004645 " 3. Mismatch fb & renderPass attachment formats\n"
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004646 " 4. Mismatch fb & renderPass attachment #samples\n"
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004647 " 5. FB attachment w/ non-1 mip-levels\n"
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004648 " 6. FB attachment where dimensions don't match\n"
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004649 " 7. FB attachment w/o identity swizzle\n"
4650 " 8. FB dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004651
4652 ASSERT_NO_FATAL_FAILURE(InitState());
4653 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4654
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4656 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
4657 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004658
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004659 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004660 VkAttachmentReference attach = {};
4661 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4662 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004663 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004664 VkRenderPassCreateInfo rpci = {};
4665 rpci.subpassCount = 1;
4666 rpci.pSubpasses = &subpass;
4667 rpci.attachmentCount = 1;
4668 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004669 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004670 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004671 rpci.pAttachments = &attach_desc;
4672 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4673 VkRenderPass rp;
4674 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4675 ASSERT_VK_SUCCESS(err);
4676
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004677 VkImageView ivs[2];
4678 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
4679 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004680 VkFramebufferCreateInfo fb_info = {};
4681 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4682 fb_info.pNext = NULL;
4683 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004684 // Set mis-matching attachmentCount
4685 fb_info.attachmentCount = 2;
4686 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004687 fb_info.width = 100;
4688 fb_info.height = 100;
4689 fb_info.layers = 1;
4690
4691 VkFramebuffer fb;
4692 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4693
4694 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004695 if (err == VK_SUCCESS) {
4696 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4697 }
4698 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004699
4700 // Create a renderPass with a depth-stencil attachment created with
4701 // IMAGE_USAGE_COLOR_ATTACHMENT
4702 // Add our color attachment to pDepthStencilAttachment
4703 subpass.pDepthStencilAttachment = &attach;
4704 subpass.pColorAttachments = NULL;
4705 VkRenderPass rp_ds;
4706 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
4707 ASSERT_VK_SUCCESS(err);
4708 // Set correct attachment count, but attachment has COLOR usage bit set
4709 fb_info.attachmentCount = 1;
4710 fb_info.renderPass = rp_ds;
4711
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004713 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4714
4715 m_errorMonitor->VerifyFound();
4716 if (err == VK_SUCCESS) {
4717 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4718 }
4719 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004720
4721 // Create new renderpass with alternate attachment format from fb
4722 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
4723 subpass.pDepthStencilAttachment = NULL;
4724 subpass.pColorAttachments = &attach;
4725 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4726 ASSERT_VK_SUCCESS(err);
4727
4728 // Cause error due to mis-matched formats between rp & fb
4729 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
4730 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4732 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004733 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4734
4735 m_errorMonitor->VerifyFound();
4736 if (err == VK_SUCCESS) {
4737 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4738 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004739 vkDestroyRenderPass(m_device->device(), rp, NULL);
4740
4741 // Create new renderpass with alternate sample count from fb
4742 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4743 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
4744 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4745 ASSERT_VK_SUCCESS(err);
4746
4747 // Cause error due to mis-matched sample count between rp & fb
4748 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
4750 "that do not match the "
4751 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004752 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4753
4754 m_errorMonitor->VerifyFound();
4755 if (err == VK_SUCCESS) {
4756 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4757 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004758
4759 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004760
4761 // Create a custom imageView with non-1 mip levels
4762 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004763 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004764 ASSERT_TRUE(image.initialized());
4765
4766 VkImageView view;
4767 VkImageViewCreateInfo ivci = {};
4768 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4769 ivci.image = image.handle();
4770 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4771 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4772 ivci.subresourceRange.layerCount = 1;
4773 ivci.subresourceRange.baseMipLevel = 0;
4774 // Set level count 2 (only 1 is allowed for FB attachment)
4775 ivci.subresourceRange.levelCount = 2;
4776 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4777 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4778 ASSERT_VK_SUCCESS(err);
4779 // Re-create renderpass to have matching sample count
4780 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4781 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4782 ASSERT_VK_SUCCESS(err);
4783
4784 fb_info.renderPass = rp;
4785 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004787 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4788
4789 m_errorMonitor->VerifyFound();
4790 if (err == VK_SUCCESS) {
4791 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4792 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004793 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004794 // Update view to original color buffer and grow FB dimensions too big
4795 fb_info.pAttachments = ivs;
4796 fb_info.height = 1024;
4797 fb_info.width = 1024;
4798 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
4800 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004801 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4802
4803 m_errorMonitor->VerifyFound();
4804 if (err == VK_SUCCESS) {
4805 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4806 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004807 // Create view attachment with non-identity swizzle
4808 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4809 ivci.image = image.handle();
4810 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4811 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4812 ivci.subresourceRange.layerCount = 1;
4813 ivci.subresourceRange.baseMipLevel = 0;
4814 ivci.subresourceRange.levelCount = 1;
4815 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4816 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4817 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4818 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4819 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4820 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4821 ASSERT_VK_SUCCESS(err);
4822
4823 fb_info.pAttachments = &view;
4824 fb_info.height = 100;
4825 fb_info.width = 100;
4826 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
4828 "framebuffer attachments must have "
4829 "been created with the identity "
4830 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004831 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4832
4833 m_errorMonitor->VerifyFound();
4834 if (err == VK_SUCCESS) {
4835 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4836 }
4837 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004838 // Request fb that exceeds max dimensions
4839 // reset attachment to color attachment
4840 fb_info.pAttachments = ivs;
4841 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
4842 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
4843 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
4845 "dimensions exceed physical device "
4846 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004847 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4848
4849 m_errorMonitor->VerifyFound();
4850 if (err == VK_SUCCESS) {
4851 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4852 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004853
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004854 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004855}
4856
Mark Lobodzinskic808d442016-04-14 10:57:23 -06004857// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05004858TEST_F(VkLayerTest, WaitEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004859 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05004860
Michael Lentine860b0fe2016-05-20 10:14:00 -05004861 m_errorMonitor->ExpectSuccess();
Cody Northropc31a84f2016-08-22 10:41:47 -06004862 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05004863
4864 VkEvent event;
4865 VkEventCreateInfo event_create_info{};
4866 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4867 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
4868
4869 VkCommandPool command_pool;
4870 VkCommandPoolCreateInfo pool_create_info{};
4871 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4872 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4873 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004874 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004875
4876 VkCommandBuffer command_buffer;
4877 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004878 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05004879 command_buffer_allocate_info.commandPool = command_pool;
4880 command_buffer_allocate_info.commandBufferCount = 1;
4881 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004882 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004883
4884 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004885 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004886
4887 {
4888 VkCommandBufferBeginInfo begin_info{};
4889 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4890 vkBeginCommandBuffer(command_buffer, &begin_info);
4891
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004892 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
Michael Lentine860b0fe2016-05-20 10:14:00 -05004893 nullptr, 0, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004894 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004895 vkEndCommandBuffer(command_buffer);
4896 }
4897 {
4898 VkSubmitInfo submit_info{};
4899 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4900 submit_info.commandBufferCount = 1;
4901 submit_info.pCommandBuffers = &command_buffer;
4902 submit_info.signalSemaphoreCount = 0;
4903 submit_info.pSignalSemaphores = nullptr;
4904 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
4905 }
4906 { vkSetEvent(m_device->device(), event); }
4907
4908 vkQueueWaitIdle(queue);
4909
4910 vkDestroyEvent(m_device->device(), event, nullptr);
4911 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
4912 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4913
4914 m_errorMonitor->VerifyNotFound();
4915}
Michael Lentine5627e692016-05-20 17:45:02 -05004916// This is a positive test. No errors should be generated.
Michael Lentinef01fb382016-07-21 17:24:56 -05004917TEST_F(VkLayerTest, QueryAndCopySecondaryCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004918 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
Michael Lentinef01fb382016-07-21 17:24:56 -05004919
Cody Northropc31a84f2016-08-22 10:41:47 -06004920 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004921 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentinef01fb382016-07-21 17:24:56 -05004922 return;
4923
4924 m_errorMonitor->ExpectSuccess();
4925
4926 VkQueryPool query_pool;
4927 VkQueryPoolCreateInfo query_pool_create_info{};
4928 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4929 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
4930 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004931 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004932
4933 VkCommandPool command_pool;
4934 VkCommandPoolCreateInfo pool_create_info{};
4935 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4936 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4937 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004938 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004939
4940 VkCommandBuffer command_buffer;
4941 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004942 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentinef01fb382016-07-21 17:24:56 -05004943 command_buffer_allocate_info.commandPool = command_pool;
4944 command_buffer_allocate_info.commandBufferCount = 1;
4945 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004946 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004947
4948 VkCommandBuffer secondary_command_buffer;
4949 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004950 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004951
4952 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004953 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentinef01fb382016-07-21 17:24:56 -05004954
4955 uint32_t qfi = 0;
4956 VkBufferCreateInfo buff_create_info = {};
4957 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4958 buff_create_info.size = 1024;
4959 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
4960 buff_create_info.queueFamilyIndexCount = 1;
4961 buff_create_info.pQueueFamilyIndices = &qfi;
4962
4963 VkResult err;
4964 VkBuffer buffer;
4965 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
4966 ASSERT_VK_SUCCESS(err);
4967 VkMemoryAllocateInfo mem_alloc = {};
4968 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4969 mem_alloc.pNext = NULL;
4970 mem_alloc.allocationSize = 1024;
4971 mem_alloc.memoryTypeIndex = 0;
4972
4973 VkMemoryRequirements memReqs;
4974 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004975 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05004976 if (!pass) {
4977 vkDestroyBuffer(m_device->device(), buffer, NULL);
4978 return;
4979 }
4980
4981 VkDeviceMemory mem;
4982 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4983 ASSERT_VK_SUCCESS(err);
4984 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4985 ASSERT_VK_SUCCESS(err);
4986
4987 VkCommandBufferInheritanceInfo hinfo = {};
4988 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
4989 hinfo.renderPass = VK_NULL_HANDLE;
4990 hinfo.subpass = 0;
4991 hinfo.framebuffer = VK_NULL_HANDLE;
4992 hinfo.occlusionQueryEnable = VK_FALSE;
4993 hinfo.queryFlags = 0;
4994 hinfo.pipelineStatistics = 0;
4995
4996 {
4997 VkCommandBufferBeginInfo begin_info{};
4998 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4999 begin_info.pInheritanceInfo = &hinfo;
5000 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
5001
5002 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005003 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05005004
5005 vkEndCommandBuffer(secondary_command_buffer);
5006
5007 begin_info.pInheritanceInfo = nullptr;
5008 vkBeginCommandBuffer(command_buffer, &begin_info);
5009
5010 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005011 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05005012
5013 vkEndCommandBuffer(command_buffer);
5014 }
5015 {
5016 VkSubmitInfo submit_info{};
5017 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5018 submit_info.commandBufferCount = 1;
5019 submit_info.pCommandBuffers = &command_buffer;
5020 submit_info.signalSemaphoreCount = 0;
5021 submit_info.pSignalSemaphores = nullptr;
5022 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5023 }
5024
5025 vkQueueWaitIdle(queue);
5026
5027 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5028 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5029 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
5030 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5031 vkDestroyBuffer(m_device->device(), buffer, NULL);
5032 vkFreeMemory(m_device->device(), mem, NULL);
5033
5034 m_errorMonitor->VerifyNotFound();
5035}
5036
5037// This is a positive test. No errors should be generated.
Michael Lentine5627e692016-05-20 17:45:02 -05005038TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005039 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
Michael Lentine5627e692016-05-20 17:45:02 -05005040
Cody Northropc31a84f2016-08-22 10:41:47 -06005041 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005042 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentine5627e692016-05-20 17:45:02 -05005043 return;
5044
5045 m_errorMonitor->ExpectSuccess();
5046
5047 VkQueryPool query_pool;
5048 VkQueryPoolCreateInfo query_pool_create_info{};
5049 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5050 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
5051 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005052 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005053
5054 VkCommandPool command_pool;
5055 VkCommandPoolCreateInfo pool_create_info{};
5056 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5057 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5058 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005059 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005060
5061 VkCommandBuffer command_buffer[2];
5062 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005063 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine5627e692016-05-20 17:45:02 -05005064 command_buffer_allocate_info.commandPool = command_pool;
5065 command_buffer_allocate_info.commandBufferCount = 2;
5066 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005067 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Michael Lentine5627e692016-05-20 17:45:02 -05005068
5069 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005070 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentine5627e692016-05-20 17:45:02 -05005071
5072 uint32_t qfi = 0;
5073 VkBufferCreateInfo buff_create_info = {};
5074 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5075 buff_create_info.size = 1024;
5076 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
5077 buff_create_info.queueFamilyIndexCount = 1;
5078 buff_create_info.pQueueFamilyIndices = &qfi;
5079
5080 VkResult err;
5081 VkBuffer buffer;
5082 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
5083 ASSERT_VK_SUCCESS(err);
5084 VkMemoryAllocateInfo mem_alloc = {};
5085 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5086 mem_alloc.pNext = NULL;
5087 mem_alloc.allocationSize = 1024;
5088 mem_alloc.memoryTypeIndex = 0;
5089
5090 VkMemoryRequirements memReqs;
5091 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005092 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005093 if (!pass) {
5094 vkDestroyBuffer(m_device->device(), buffer, NULL);
5095 return;
5096 }
5097
5098 VkDeviceMemory mem;
5099 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5100 ASSERT_VK_SUCCESS(err);
5101 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5102 ASSERT_VK_SUCCESS(err);
5103
5104 {
5105 VkCommandBufferBeginInfo begin_info{};
5106 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5107 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5108
5109 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005110 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005111
5112 vkEndCommandBuffer(command_buffer[0]);
5113
5114 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5115
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005116 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005117
5118 vkEndCommandBuffer(command_buffer[1]);
5119 }
5120 {
5121 VkSubmitInfo submit_info{};
5122 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5123 submit_info.commandBufferCount = 2;
5124 submit_info.pCommandBuffers = command_buffer;
5125 submit_info.signalSemaphoreCount = 0;
5126 submit_info.pSignalSemaphores = nullptr;
5127 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5128 }
5129
5130 vkQueueWaitIdle(queue);
5131
5132 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5133 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
5134 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005135 vkDestroyBuffer(m_device->device(), buffer, NULL);
5136 vkFreeMemory(m_device->device(), mem, NULL);
Michael Lentine5627e692016-05-20 17:45:02 -05005137
5138 m_errorMonitor->VerifyNotFound();
5139}
Michael Lentine860b0fe2016-05-20 10:14:00 -05005140
5141TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005142 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005143
Michael Lentine860b0fe2016-05-20 10:14:00 -05005144 m_errorMonitor->ExpectSuccess();
5145
Cody Northropc31a84f2016-08-22 10:41:47 -06005146 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05005147 VkEvent event;
5148 VkEventCreateInfo event_create_info{};
5149 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5150 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
5151
5152 VkCommandPool command_pool;
5153 VkCommandPoolCreateInfo pool_create_info{};
5154 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5155 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5156 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005157 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005158
5159 VkCommandBuffer command_buffer;
5160 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005161 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05005162 command_buffer_allocate_info.commandPool = command_pool;
5163 command_buffer_allocate_info.commandBufferCount = 1;
5164 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005165 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005166
5167 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005168 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005169
5170 {
5171 VkCommandBufferBeginInfo begin_info{};
5172 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5173 vkBeginCommandBuffer(command_buffer, &begin_info);
5174
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005175 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
5176 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
5177 nullptr, 0, nullptr, 0, nullptr);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005178 vkEndCommandBuffer(command_buffer);
5179 }
5180 {
5181 VkSubmitInfo submit_info{};
5182 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5183 submit_info.commandBufferCount = 1;
5184 submit_info.pCommandBuffers = &command_buffer;
5185 submit_info.signalSemaphoreCount = 0;
5186 submit_info.pSignalSemaphores = nullptr;
5187 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5188 }
5189 {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
5191 "command buffer.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005192 vkSetEvent(m_device->device(), event);
5193 m_errorMonitor->VerifyFound();
5194 }
5195
5196 vkQueueWaitIdle(queue);
5197
5198 vkDestroyEvent(m_device->device(), event, nullptr);
5199 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5200 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5201}
5202
5203// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005204TEST_F(VkLayerTest, TwoFencesThreeFrames) {
5205 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
5206 "run through a Submit & WaitForFences cycle 3 times. This "
5207 "previously revealed a bug so running this positive test "
5208 "to prevent a regression.");
5209 m_errorMonitor->ExpectSuccess();
5210
5211 ASSERT_NO_FATAL_FAILURE(InitState());
5212 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005213 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005214
5215 static const uint32_t NUM_OBJECTS = 2;
5216 static const uint32_t NUM_FRAMES = 3;
5217 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
5218 VkFence fences[NUM_OBJECTS] = {};
5219
5220 VkCommandPool cmd_pool;
5221 VkCommandPoolCreateInfo cmd_pool_ci = {};
5222 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5223 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
5224 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005225 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005226 ASSERT_VK_SUCCESS(err);
5227
5228 VkCommandBufferAllocateInfo cmd_buf_info = {};
5229 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
5230 cmd_buf_info.commandPool = cmd_pool;
5231 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
5232 cmd_buf_info.commandBufferCount = 1;
5233
5234 VkFenceCreateInfo fence_ci = {};
5235 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5236 fence_ci.pNext = nullptr;
5237 fence_ci.flags = 0;
5238
5239 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005240 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005241 ASSERT_VK_SUCCESS(err);
5242 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
5243 ASSERT_VK_SUCCESS(err);
5244 }
5245
5246 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06005247 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
5248 // Create empty cmd buffer
5249 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
5250 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005251
Tobin Ehlisf9025162016-05-26 06:55:21 -06005252 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
5253 ASSERT_VK_SUCCESS(err);
5254 err = vkEndCommandBuffer(cmd_buffers[obj]);
5255 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005256
Tobin Ehlisf9025162016-05-26 06:55:21 -06005257 VkSubmitInfo submit_info = {};
5258 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5259 submit_info.commandBufferCount = 1;
5260 submit_info.pCommandBuffers = &cmd_buffers[obj];
5261 // Submit cmd buffer and wait for fence
5262 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
5263 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005264 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
Tobin Ehlisf9025162016-05-26 06:55:21 -06005265 ASSERT_VK_SUCCESS(err);
5266 err = vkResetFences(m_device->device(), 1, &fences[obj]);
5267 ASSERT_VK_SUCCESS(err);
5268 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005269 }
5270 m_errorMonitor->VerifyNotFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06005271 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
5272 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
5273 vkDestroyFence(m_device->device(), fences[i], nullptr);
5274 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005275}
5276// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005277TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
5278
5279 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005280 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005281
Cody Northropc31a84f2016-08-22 10:41:47 -06005282 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005283 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005284 return;
5285
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005286 m_errorMonitor->ExpectSuccess();
5287
5288 VkSemaphore semaphore;
5289 VkSemaphoreCreateInfo semaphore_create_info{};
5290 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005291 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005292
5293 VkCommandPool command_pool;
5294 VkCommandPoolCreateInfo pool_create_info{};
5295 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5296 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5297 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005298 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005299
5300 VkCommandBuffer command_buffer[2];
5301 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005302 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005303 command_buffer_allocate_info.commandPool = command_pool;
5304 command_buffer_allocate_info.commandBufferCount = 2;
5305 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005306 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005307
5308 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005309 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005310
5311 {
5312 VkCommandBufferBeginInfo begin_info{};
5313 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5314 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5315
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005316 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5317 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005318
5319 VkViewport viewport{};
5320 viewport.maxDepth = 1.0f;
5321 viewport.minDepth = 0.0f;
5322 viewport.width = 512;
5323 viewport.height = 512;
5324 viewport.x = 0;
5325 viewport.y = 0;
5326 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5327 vkEndCommandBuffer(command_buffer[0]);
5328 }
5329 {
5330 VkCommandBufferBeginInfo begin_info{};
5331 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5332 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5333
5334 VkViewport viewport{};
5335 viewport.maxDepth = 1.0f;
5336 viewport.minDepth = 0.0f;
5337 viewport.width = 512;
5338 viewport.height = 512;
5339 viewport.x = 0;
5340 viewport.y = 0;
5341 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5342 vkEndCommandBuffer(command_buffer[1]);
5343 }
5344 {
5345 VkSubmitInfo submit_info{};
5346 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5347 submit_info.commandBufferCount = 1;
5348 submit_info.pCommandBuffers = &command_buffer[0];
5349 submit_info.signalSemaphoreCount = 1;
5350 submit_info.pSignalSemaphores = &semaphore;
5351 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5352 }
5353 {
5354 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5355 VkSubmitInfo submit_info{};
5356 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5357 submit_info.commandBufferCount = 1;
5358 submit_info.pCommandBuffers = &command_buffer[1];
5359 submit_info.waitSemaphoreCount = 1;
5360 submit_info.pWaitSemaphores = &semaphore;
5361 submit_info.pWaitDstStageMask = flags;
5362 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5363 }
5364
5365 vkQueueWaitIdle(m_device->m_queue);
5366
5367 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005368 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005369 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5370
5371 m_errorMonitor->VerifyNotFound();
5372}
5373
5374// This is a positive test. No errors should be generated.
5375TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
5376
5377 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5378 "submitted on separate queues, the second having a fence"
5379 "followed by a QueueWaitIdle.");
5380
Cody Northropc31a84f2016-08-22 10:41:47 -06005381 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005382 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005383 return;
5384
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005385 m_errorMonitor->ExpectSuccess();
5386
5387 VkFence fence;
5388 VkFenceCreateInfo fence_create_info{};
5389 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5390 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5391
5392 VkSemaphore semaphore;
5393 VkSemaphoreCreateInfo semaphore_create_info{};
5394 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005395 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005396
5397 VkCommandPool command_pool;
5398 VkCommandPoolCreateInfo pool_create_info{};
5399 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5400 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5401 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005402 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005403
5404 VkCommandBuffer command_buffer[2];
5405 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005406 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005407 command_buffer_allocate_info.commandPool = command_pool;
5408 command_buffer_allocate_info.commandBufferCount = 2;
5409 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005410 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005411
5412 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005413 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005414
5415 {
5416 VkCommandBufferBeginInfo begin_info{};
5417 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5418 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5419
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005420 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5421 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005422
5423 VkViewport viewport{};
5424 viewport.maxDepth = 1.0f;
5425 viewport.minDepth = 0.0f;
5426 viewport.width = 512;
5427 viewport.height = 512;
5428 viewport.x = 0;
5429 viewport.y = 0;
5430 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5431 vkEndCommandBuffer(command_buffer[0]);
5432 }
5433 {
5434 VkCommandBufferBeginInfo begin_info{};
5435 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5436 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5437
5438 VkViewport viewport{};
5439 viewport.maxDepth = 1.0f;
5440 viewport.minDepth = 0.0f;
5441 viewport.width = 512;
5442 viewport.height = 512;
5443 viewport.x = 0;
5444 viewport.y = 0;
5445 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5446 vkEndCommandBuffer(command_buffer[1]);
5447 }
5448 {
5449 VkSubmitInfo submit_info{};
5450 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5451 submit_info.commandBufferCount = 1;
5452 submit_info.pCommandBuffers = &command_buffer[0];
5453 submit_info.signalSemaphoreCount = 1;
5454 submit_info.pSignalSemaphores = &semaphore;
5455 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5456 }
5457 {
5458 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5459 VkSubmitInfo submit_info{};
5460 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5461 submit_info.commandBufferCount = 1;
5462 submit_info.pCommandBuffers = &command_buffer[1];
5463 submit_info.waitSemaphoreCount = 1;
5464 submit_info.pWaitSemaphores = &semaphore;
5465 submit_info.pWaitDstStageMask = flags;
5466 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5467 }
5468
5469 vkQueueWaitIdle(m_device->m_queue);
5470
5471 vkDestroyFence(m_device->device(), fence, nullptr);
5472 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005473 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005474 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5475
5476 m_errorMonitor->VerifyNotFound();
5477}
5478
5479// This is a positive test. No errors should be generated.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005480TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005481
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005482 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5483 "submitted on separate queues, the second having a fence"
5484 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005485
Cody Northropc31a84f2016-08-22 10:41:47 -06005486 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005487 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005488 return;
5489
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005490 m_errorMonitor->ExpectSuccess();
5491
5492 VkFence fence;
5493 VkFenceCreateInfo fence_create_info{};
5494 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5495 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5496
5497 VkSemaphore semaphore;
5498 VkSemaphoreCreateInfo semaphore_create_info{};
5499 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005500 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005501
5502 VkCommandPool command_pool;
5503 VkCommandPoolCreateInfo pool_create_info{};
5504 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5505 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5506 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005507 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005508
5509 VkCommandBuffer command_buffer[2];
5510 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005511 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005512 command_buffer_allocate_info.commandPool = command_pool;
5513 command_buffer_allocate_info.commandBufferCount = 2;
5514 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005515 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005516
5517 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005518 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005519
5520 {
5521 VkCommandBufferBeginInfo begin_info{};
5522 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5523 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5524
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005525 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5526 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005527
5528 VkViewport viewport{};
5529 viewport.maxDepth = 1.0f;
5530 viewport.minDepth = 0.0f;
5531 viewport.width = 512;
5532 viewport.height = 512;
5533 viewport.x = 0;
5534 viewport.y = 0;
5535 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5536 vkEndCommandBuffer(command_buffer[0]);
5537 }
5538 {
5539 VkCommandBufferBeginInfo begin_info{};
5540 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5541 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5542
5543 VkViewport viewport{};
5544 viewport.maxDepth = 1.0f;
5545 viewport.minDepth = 0.0f;
5546 viewport.width = 512;
5547 viewport.height = 512;
5548 viewport.x = 0;
5549 viewport.y = 0;
5550 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5551 vkEndCommandBuffer(command_buffer[1]);
5552 }
5553 {
5554 VkSubmitInfo submit_info{};
5555 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5556 submit_info.commandBufferCount = 1;
5557 submit_info.pCommandBuffers = &command_buffer[0];
5558 submit_info.signalSemaphoreCount = 1;
5559 submit_info.pSignalSemaphores = &semaphore;
5560 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5561 }
5562 {
5563 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5564 VkSubmitInfo submit_info{};
5565 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5566 submit_info.commandBufferCount = 1;
5567 submit_info.pCommandBuffers = &command_buffer[1];
5568 submit_info.waitSemaphoreCount = 1;
5569 submit_info.pWaitSemaphores = &semaphore;
5570 submit_info.pWaitDstStageMask = flags;
5571 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5572 }
5573
5574 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5575 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5576
5577 vkDestroyFence(m_device->device(), fence, nullptr);
5578 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005579 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005580 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5581
5582 m_errorMonitor->VerifyNotFound();
5583}
5584
Chris Forbes0f8126b2016-06-20 17:48:22 +12005585TEST_F(VkLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Cody Northropc31a84f2016-08-22 10:41:47 -06005586
5587 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005588 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Chris Forbes0f8126b2016-06-20 17:48:22 +12005589 printf("Test requires two queues, skipping\n");
5590 return;
5591 }
5592
5593 VkResult err;
5594
5595 m_errorMonitor->ExpectSuccess();
5596
5597 VkQueue q0 = m_device->m_queue;
5598 VkQueue q1 = nullptr;
5599 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
5600 ASSERT_NE(q1, nullptr);
5601
5602 // An (empty) command buffer. We must have work in the first submission --
5603 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005604 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005605 VkCommandPool pool;
5606 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
5607 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005608 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
5609 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005610 VkCommandBuffer cb;
5611 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
5612 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005613 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005614 err = vkBeginCommandBuffer(cb, &cbbi);
5615 ASSERT_VK_SUCCESS(err);
5616 err = vkEndCommandBuffer(cb);
5617 ASSERT_VK_SUCCESS(err);
5618
5619 // A semaphore
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005620 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005621 VkSemaphore s;
5622 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
5623 ASSERT_VK_SUCCESS(err);
5624
5625 // First submission, to q0
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005626 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005627
5628 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
5629 ASSERT_VK_SUCCESS(err);
5630
5631 // Second submission, to q1, waiting on s
5632 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005633 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005634
5635 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
5636 ASSERT_VK_SUCCESS(err);
5637
5638 // Wait for q0 idle
5639 err = vkQueueWaitIdle(q0);
5640 ASSERT_VK_SUCCESS(err);
5641
5642 // Command buffer should have been completed (it was on q0); reset the pool.
5643 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
5644
5645 m_errorMonitor->VerifyNotFound();
5646
5647 // Force device completely idle and clean up resources
5648 vkDeviceWaitIdle(m_device->device());
5649 vkDestroyCommandPool(m_device->device(), pool, nullptr);
5650 vkDestroySemaphore(m_device->device(), s, nullptr);
5651}
Chris Forbes0f8126b2016-06-20 17:48:22 +12005652
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005653// This is a positive test. No errors should be generated.
5654TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
5655
5656 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5657 "submitted on separate queues, the second having a fence, "
5658 "followed by a WaitForFences call.");
5659
Cody Northropc31a84f2016-08-22 10:41:47 -06005660 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005661 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005662 return;
5663
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005664 m_errorMonitor->ExpectSuccess();
5665
Cody Northropc31a84f2016-08-22 10:41:47 -06005666 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005667 VkFence fence;
5668 VkFenceCreateInfo fence_create_info{};
5669 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5670 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5671
5672 VkSemaphore semaphore;
5673 VkSemaphoreCreateInfo semaphore_create_info{};
5674 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005675 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005676
5677 VkCommandPool command_pool;
5678 VkCommandPoolCreateInfo pool_create_info{};
5679 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5680 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5681 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005682 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005683
5684 VkCommandBuffer command_buffer[2];
5685 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005686 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005687 command_buffer_allocate_info.commandPool = command_pool;
5688 command_buffer_allocate_info.commandBufferCount = 2;
5689 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005690 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005691
5692 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005693 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005694
5695 {
5696 VkCommandBufferBeginInfo begin_info{};
5697 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5698 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5699
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005700 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5701 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005702
5703 VkViewport viewport{};
5704 viewport.maxDepth = 1.0f;
5705 viewport.minDepth = 0.0f;
5706 viewport.width = 512;
5707 viewport.height = 512;
5708 viewport.x = 0;
5709 viewport.y = 0;
5710 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5711 vkEndCommandBuffer(command_buffer[0]);
5712 }
5713 {
5714 VkCommandBufferBeginInfo begin_info{};
5715 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5716 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5717
5718 VkViewport viewport{};
5719 viewport.maxDepth = 1.0f;
5720 viewport.minDepth = 0.0f;
5721 viewport.width = 512;
5722 viewport.height = 512;
5723 viewport.x = 0;
5724 viewport.y = 0;
5725 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5726 vkEndCommandBuffer(command_buffer[1]);
5727 }
5728 {
5729 VkSubmitInfo submit_info{};
5730 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5731 submit_info.commandBufferCount = 1;
5732 submit_info.pCommandBuffers = &command_buffer[0];
5733 submit_info.signalSemaphoreCount = 1;
5734 submit_info.pSignalSemaphores = &semaphore;
5735 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5736 }
5737 {
5738 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5739 VkSubmitInfo submit_info{};
5740 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5741 submit_info.commandBufferCount = 1;
5742 submit_info.pCommandBuffers = &command_buffer[1];
5743 submit_info.waitSemaphoreCount = 1;
5744 submit_info.pWaitSemaphores = &semaphore;
5745 submit_info.pWaitDstStageMask = flags;
5746 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5747 }
5748
5749 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5750
5751 vkDestroyFence(m_device->device(), fence, nullptr);
5752 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005753 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005754 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5755
5756 m_errorMonitor->VerifyNotFound();
5757}
5758
5759// This is a positive test. No errors should be generated.
5760TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
5761
5762 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5763 "on the same queue, sharing a signal/wait semaphore, the "
5764 "second having a fence, "
5765 "followed by a WaitForFences call.");
5766
5767 m_errorMonitor->ExpectSuccess();
5768
Cody Northropc31a84f2016-08-22 10:41:47 -06005769 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005770 VkFence fence;
5771 VkFenceCreateInfo fence_create_info{};
5772 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5773 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5774
5775 VkSemaphore semaphore;
5776 VkSemaphoreCreateInfo semaphore_create_info{};
5777 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005778 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005779
5780 VkCommandPool command_pool;
5781 VkCommandPoolCreateInfo pool_create_info{};
5782 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5783 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5784 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005785 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005786
5787 VkCommandBuffer command_buffer[2];
5788 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005789 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005790 command_buffer_allocate_info.commandPool = command_pool;
5791 command_buffer_allocate_info.commandBufferCount = 2;
5792 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005793 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005794
5795 {
5796 VkCommandBufferBeginInfo begin_info{};
5797 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5798 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5799
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005800 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5801 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005802
5803 VkViewport viewport{};
5804 viewport.maxDepth = 1.0f;
5805 viewport.minDepth = 0.0f;
5806 viewport.width = 512;
5807 viewport.height = 512;
5808 viewport.x = 0;
5809 viewport.y = 0;
5810 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5811 vkEndCommandBuffer(command_buffer[0]);
5812 }
5813 {
5814 VkCommandBufferBeginInfo begin_info{};
5815 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5816 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5817
5818 VkViewport viewport{};
5819 viewport.maxDepth = 1.0f;
5820 viewport.minDepth = 0.0f;
5821 viewport.width = 512;
5822 viewport.height = 512;
5823 viewport.x = 0;
5824 viewport.y = 0;
5825 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5826 vkEndCommandBuffer(command_buffer[1]);
5827 }
5828 {
5829 VkSubmitInfo submit_info{};
5830 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5831 submit_info.commandBufferCount = 1;
5832 submit_info.pCommandBuffers = &command_buffer[0];
5833 submit_info.signalSemaphoreCount = 1;
5834 submit_info.pSignalSemaphores = &semaphore;
5835 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5836 }
5837 {
5838 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5839 VkSubmitInfo submit_info{};
5840 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5841 submit_info.commandBufferCount = 1;
5842 submit_info.pCommandBuffers = &command_buffer[1];
5843 submit_info.waitSemaphoreCount = 1;
5844 submit_info.pWaitSemaphores = &semaphore;
5845 submit_info.pWaitDstStageMask = flags;
5846 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5847 }
5848
5849 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5850
5851 vkDestroyFence(m_device->device(), fence, nullptr);
5852 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005853 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005854 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5855
5856 m_errorMonitor->VerifyNotFound();
5857}
5858
5859// This is a positive test. No errors should be generated.
5860TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
5861
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005862 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5863 "on the same queue, no fences, followed by a third QueueSubmit with NO "
5864 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005865
5866 m_errorMonitor->ExpectSuccess();
5867
Cody Northropc31a84f2016-08-22 10:41:47 -06005868 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005869 VkFence fence;
5870 VkFenceCreateInfo fence_create_info{};
5871 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5872 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5873
5874 VkCommandPool command_pool;
5875 VkCommandPoolCreateInfo pool_create_info{};
5876 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5877 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5878 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005879 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005880
5881 VkCommandBuffer command_buffer[2];
5882 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005883 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005884 command_buffer_allocate_info.commandPool = command_pool;
5885 command_buffer_allocate_info.commandBufferCount = 2;
5886 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005887 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005888
5889 {
5890 VkCommandBufferBeginInfo begin_info{};
5891 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5892 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5893
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005894 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5895 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005896
5897 VkViewport viewport{};
5898 viewport.maxDepth = 1.0f;
5899 viewport.minDepth = 0.0f;
5900 viewport.width = 512;
5901 viewport.height = 512;
5902 viewport.x = 0;
5903 viewport.y = 0;
5904 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5905 vkEndCommandBuffer(command_buffer[0]);
5906 }
5907 {
5908 VkCommandBufferBeginInfo begin_info{};
5909 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5910 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5911
5912 VkViewport viewport{};
5913 viewport.maxDepth = 1.0f;
5914 viewport.minDepth = 0.0f;
5915 viewport.width = 512;
5916 viewport.height = 512;
5917 viewport.x = 0;
5918 viewport.y = 0;
5919 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5920 vkEndCommandBuffer(command_buffer[1]);
5921 }
5922 {
5923 VkSubmitInfo submit_info{};
5924 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5925 submit_info.commandBufferCount = 1;
5926 submit_info.pCommandBuffers = &command_buffer[0];
5927 submit_info.signalSemaphoreCount = 0;
5928 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
5929 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5930 }
5931 {
5932 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5933 VkSubmitInfo submit_info{};
5934 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5935 submit_info.commandBufferCount = 1;
5936 submit_info.pCommandBuffers = &command_buffer[1];
5937 submit_info.waitSemaphoreCount = 0;
5938 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
5939 submit_info.pWaitDstStageMask = flags;
5940 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5941 }
5942
5943 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
5944
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005945 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
Mike Stroyancd1c3e52016-06-21 09:20:01 -06005946 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005947
5948 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005949 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005950 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5951
5952 m_errorMonitor->VerifyNotFound();
5953}
5954
5955// This is a positive test. No errors should be generated.
5956TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
5957
5958 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5959 "on the same queue, the second having a fence, followed "
5960 "by a WaitForFences call.");
5961
5962 m_errorMonitor->ExpectSuccess();
5963
Cody Northropc31a84f2016-08-22 10:41:47 -06005964 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005965 VkFence fence;
5966 VkFenceCreateInfo fence_create_info{};
5967 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5968 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5969
5970 VkCommandPool command_pool;
5971 VkCommandPoolCreateInfo pool_create_info{};
5972 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5973 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5974 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005975 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005976
5977 VkCommandBuffer command_buffer[2];
5978 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005979 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005980 command_buffer_allocate_info.commandPool = command_pool;
5981 command_buffer_allocate_info.commandBufferCount = 2;
5982 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005983 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005984
5985 {
5986 VkCommandBufferBeginInfo begin_info{};
5987 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5988 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5989
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005990 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5991 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005992
5993 VkViewport viewport{};
5994 viewport.maxDepth = 1.0f;
5995 viewport.minDepth = 0.0f;
5996 viewport.width = 512;
5997 viewport.height = 512;
5998 viewport.x = 0;
5999 viewport.y = 0;
6000 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
6001 vkEndCommandBuffer(command_buffer[0]);
6002 }
6003 {
6004 VkCommandBufferBeginInfo begin_info{};
6005 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6006 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6007
6008 VkViewport viewport{};
6009 viewport.maxDepth = 1.0f;
6010 viewport.minDepth = 0.0f;
6011 viewport.width = 512;
6012 viewport.height = 512;
6013 viewport.x = 0;
6014 viewport.y = 0;
6015 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6016 vkEndCommandBuffer(command_buffer[1]);
6017 }
6018 {
6019 VkSubmitInfo submit_info{};
6020 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6021 submit_info.commandBufferCount = 1;
6022 submit_info.pCommandBuffers = &command_buffer[0];
6023 submit_info.signalSemaphoreCount = 0;
6024 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
6025 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6026 }
6027 {
6028 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6029 VkSubmitInfo submit_info{};
6030 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6031 submit_info.commandBufferCount = 1;
6032 submit_info.pCommandBuffers = &command_buffer[1];
6033 submit_info.waitSemaphoreCount = 0;
6034 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
6035 submit_info.pWaitDstStageMask = flags;
6036 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
6037 }
6038
6039 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6040
6041 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006042 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006043 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
6044
6045 m_errorMonitor->VerifyNotFound();
6046}
6047
6048// This is a positive test. No errors should be generated.
6049TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
6050
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006051 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
6052 "QueueSubmit call followed by a WaitForFences call.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006053 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006054
6055 m_errorMonitor->ExpectSuccess();
6056
6057 VkFence fence;
6058 VkFenceCreateInfo fence_create_info{};
6059 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
6060 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
6061
6062 VkSemaphore semaphore;
6063 VkSemaphoreCreateInfo semaphore_create_info{};
6064 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006065 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006066
6067 VkCommandPool command_pool;
6068 VkCommandPoolCreateInfo pool_create_info{};
6069 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
6070 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
6071 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006072 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006073
6074 VkCommandBuffer command_buffer[2];
6075 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006076 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006077 command_buffer_allocate_info.commandPool = command_pool;
6078 command_buffer_allocate_info.commandBufferCount = 2;
6079 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006080 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006081
6082 {
6083 VkCommandBufferBeginInfo begin_info{};
6084 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6085 vkBeginCommandBuffer(command_buffer[0], &begin_info);
6086
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006087 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
6088 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006089
6090 VkViewport viewport{};
6091 viewport.maxDepth = 1.0f;
6092 viewport.minDepth = 0.0f;
6093 viewport.width = 512;
6094 viewport.height = 512;
6095 viewport.x = 0;
6096 viewport.y = 0;
6097 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
6098 vkEndCommandBuffer(command_buffer[0]);
6099 }
6100 {
6101 VkCommandBufferBeginInfo begin_info{};
6102 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6103 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6104
6105 VkViewport viewport{};
6106 viewport.maxDepth = 1.0f;
6107 viewport.minDepth = 0.0f;
6108 viewport.width = 512;
6109 viewport.height = 512;
6110 viewport.x = 0;
6111 viewport.y = 0;
6112 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6113 vkEndCommandBuffer(command_buffer[1]);
6114 }
6115 {
6116 VkSubmitInfo submit_info[2];
6117 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6118
6119 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6120 submit_info[0].pNext = NULL;
6121 submit_info[0].commandBufferCount = 1;
6122 submit_info[0].pCommandBuffers = &command_buffer[0];
6123 submit_info[0].signalSemaphoreCount = 1;
6124 submit_info[0].pSignalSemaphores = &semaphore;
6125 submit_info[0].waitSemaphoreCount = 0;
6126 submit_info[0].pWaitSemaphores = NULL;
6127 submit_info[0].pWaitDstStageMask = 0;
6128
6129 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6130 submit_info[1].pNext = NULL;
6131 submit_info[1].commandBufferCount = 1;
6132 submit_info[1].pCommandBuffers = &command_buffer[1];
6133 submit_info[1].waitSemaphoreCount = 1;
6134 submit_info[1].pWaitSemaphores = &semaphore;
6135 submit_info[1].pWaitDstStageMask = flags;
6136 submit_info[1].signalSemaphoreCount = 0;
6137 submit_info[1].pSignalSemaphores = NULL;
6138 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
6139 }
6140
6141 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6142
6143 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006144 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006145 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006146 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006147
6148 m_errorMonitor->VerifyNotFound();
6149}
6150
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006151TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006152 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
6153 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006154
Cody Northropc31a84f2016-08-22 10:41:47 -06006155 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006156 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
6158 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006159 m_errorMonitor->VerifyFound();
6160}
6161
6162TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006163 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
6164 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006165
Cody Northropc31a84f2016-08-22 10:41:47 -06006166 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006167 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
6169 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006170 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006171}
6172
6173TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006174 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
6175 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006176
Cody Northropc31a84f2016-08-22 10:41:47 -06006177 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006178 // Dynamic viewport state
Chris Forbesb2ba95b2016-09-16 17:11:50 +12006179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by PSO, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006180 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006181 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006182}
6183
6184TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006185 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
6186 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006187
Cody Northropc31a84f2016-08-22 10:41:47 -06006188 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006189 // Dynamic scissor state
Chris Forbesb2ba95b2016-09-16 17:11:50 +12006190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by PSO, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006191 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006192 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006193}
6194
Cortd713fe82016-07-27 09:51:27 -07006195TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006196 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
6197 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006198
6199 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006200 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6202 "Dynamic blend constants state not set for this command buffer");
6203 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06006204 m_errorMonitor->VerifyFound();
6205}
6206
6207TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006208 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
6209 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006210
6211 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006212 if (!m_device->phy().features().depthBounds) {
6213 printf("Device does not support depthBounds test; skipped.\n");
6214 return;
6215 }
6216 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6218 "Dynamic depth bounds state not set for this command buffer");
6219 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006220 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006221}
6222
6223TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006224 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
6225 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006226
6227 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006228 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6230 "Dynamic stencil read mask state not set for this command buffer");
6231 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006232 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006233}
6234
6235TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006236 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
6237 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006238
6239 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006240 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6242 "Dynamic stencil write mask state not set for this command buffer");
6243 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006244 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006245}
6246
6247TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006248 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
6249 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006250
6251 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006252 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6254 "Dynamic stencil reference state not set for this command buffer");
6255 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006256 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06006257}
6258
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006259TEST_F(VkLayerTest, IndexBufferNotBound) {
6260 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006261
6262 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6264 "Index buffer object not bound to this command buffer when Indexed ");
6265 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006266 m_errorMonitor->VerifyFound();
6267}
6268
Karl Schultz6addd812016-02-02 17:17:23 -07006269TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6271 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
6272 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006273
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006274 ASSERT_NO_FATAL_FAILURE(InitState());
6275 ASSERT_NO_FATAL_FAILURE(InitViewport());
6276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6277
Karl Schultz6addd812016-02-02 17:17:23 -07006278 // We luck out b/c by default the framework creates CB w/ the
6279 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006280 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006281 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006282 EndCommandBuffer();
6283
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006284 // Bypass framework since it does the waits automatically
6285 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006286 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08006287 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6288 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006289 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006290 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07006291 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006292 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006293 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08006294 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006295 submit_info.pSignalSemaphores = NULL;
6296
Chris Forbes40028e22016-06-13 09:59:34 +12006297 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07006298 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006299
Karl Schultz6addd812016-02-02 17:17:23 -07006300 // Cause validation error by re-submitting cmd buffer that should only be
6301 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12006302 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006303
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006304 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006305}
6306
Karl Schultz6addd812016-02-02 17:17:23 -07006307TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006308 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07006309 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006310
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
6312 "type "
6313 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006314
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006315 ASSERT_NO_FATAL_FAILURE(InitState());
6316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006317
Karl Schultz6addd812016-02-02 17:17:23 -07006318 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
6319 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006320 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006321 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
6322 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006323
6324 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006325 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6326 ds_pool_ci.pNext = NULL;
6327 ds_pool_ci.flags = 0;
6328 ds_pool_ci.maxSets = 1;
6329 ds_pool_ci.poolSizeCount = 1;
6330 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006331
6332 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006333 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006334 ASSERT_VK_SUCCESS(err);
6335
6336 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006337 dsl_binding.binding = 0;
6338 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6339 dsl_binding.descriptorCount = 1;
6340 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6341 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006342
6343 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006344 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6345 ds_layout_ci.pNext = NULL;
6346 ds_layout_ci.bindingCount = 1;
6347 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006348
6349 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006350 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006351 ASSERT_VK_SUCCESS(err);
6352
6353 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006354 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006355 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006356 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006357 alloc_info.descriptorPool = ds_pool;
6358 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006359 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006360
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006361 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006362
Chia-I Wuf7458c52015-10-26 21:10:41 +08006363 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6364 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006365}
6366
Karl Schultz6addd812016-02-02 17:17:23 -07006367TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
6368 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06006369
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6371 "It is invalid to call vkFreeDescriptorSets() with a pool created "
6372 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006373
Tobin Ehlise735c692015-10-08 13:13:50 -06006374 ASSERT_NO_FATAL_FAILURE(InitState());
6375 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06006376
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006377 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006378 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6379 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06006380
6381 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006382 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6383 ds_pool_ci.pNext = NULL;
6384 ds_pool_ci.maxSets = 1;
6385 ds_pool_ci.poolSizeCount = 1;
6386 ds_pool_ci.flags = 0;
6387 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
6388 // app can only call vkResetDescriptorPool on this pool.;
6389 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06006390
6391 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006392 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06006393 ASSERT_VK_SUCCESS(err);
6394
6395 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006396 dsl_binding.binding = 0;
6397 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6398 dsl_binding.descriptorCount = 1;
6399 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6400 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06006401
6402 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006403 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6404 ds_layout_ci.pNext = NULL;
6405 ds_layout_ci.bindingCount = 1;
6406 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06006407
6408 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006409 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06006410 ASSERT_VK_SUCCESS(err);
6411
6412 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006413 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006414 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006415 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006416 alloc_info.descriptorPool = ds_pool;
6417 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006418 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06006419 ASSERT_VK_SUCCESS(err);
6420
6421 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006422 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06006423
Chia-I Wuf7458c52015-10-26 21:10:41 +08006424 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6425 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06006426}
6427
Karl Schultz6addd812016-02-02 17:17:23 -07006428TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006429 // Attempt to clear Descriptor Pool with bad object.
6430 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06006431
6432 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006434 uint64_t fake_pool_handle = 0xbaad6001;
6435 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
6436 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06006437 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006438}
6439
Karl Schultz6addd812016-02-02 17:17:23 -07006440TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006441 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
6442 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006443 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06006444 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006445
6446 uint64_t fake_set_handle = 0xbaad6001;
6447 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006448 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06006450
6451 ASSERT_NO_FATAL_FAILURE(InitState());
6452
6453 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
6454 layout_bindings[0].binding = 0;
6455 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6456 layout_bindings[0].descriptorCount = 1;
6457 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
6458 layout_bindings[0].pImmutableSamplers = NULL;
6459
6460 VkDescriptorSetLayout descriptor_set_layout;
6461 VkDescriptorSetLayoutCreateInfo dslci = {};
6462 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6463 dslci.pNext = NULL;
6464 dslci.bindingCount = 1;
6465 dslci.pBindings = layout_bindings;
6466 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006467 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006468
6469 VkPipelineLayout pipeline_layout;
6470 VkPipelineLayoutCreateInfo plci = {};
6471 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6472 plci.pNext = NULL;
6473 plci.setLayoutCount = 1;
6474 plci.pSetLayouts = &descriptor_set_layout;
6475 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006476 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006477
6478 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006479 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
6480 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06006481 m_errorMonitor->VerifyFound();
6482 EndCommandBuffer();
6483 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
6484 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006485}
6486
Karl Schultz6addd812016-02-02 17:17:23 -07006487TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006488 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
6489 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006490 uint64_t fake_layout_handle = 0xbaad6001;
6491 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06006493 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06006494 VkPipelineLayout pipeline_layout;
6495 VkPipelineLayoutCreateInfo plci = {};
6496 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6497 plci.pNext = NULL;
6498 plci.setLayoutCount = 1;
6499 plci.pSetLayouts = &bad_layout;
6500 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
6501
6502 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006503}
6504
Mark Muellerd4914412016-06-13 17:52:06 -06006505TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
6506 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
6507 "1) A uniform buffer update must have a valid buffer index."
6508 "2) When using an array of descriptors in a single WriteDescriptor,"
6509 " the descriptor types and stageflags must all be the same."
6510 "3) Immutable Sampler state must match across descriptors");
6511
6512 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006513 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
6514 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
6515 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
6516 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
6517 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06006518
Mark Muellerd4914412016-06-13 17:52:06 -06006519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
6520
6521 ASSERT_NO_FATAL_FAILURE(InitState());
6522 VkDescriptorPoolSize ds_type_count[4] = {};
6523 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6524 ds_type_count[0].descriptorCount = 1;
6525 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6526 ds_type_count[1].descriptorCount = 1;
6527 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6528 ds_type_count[2].descriptorCount = 1;
6529 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6530 ds_type_count[3].descriptorCount = 1;
6531
6532 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6533 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6534 ds_pool_ci.maxSets = 1;
6535 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
6536 ds_pool_ci.pPoolSizes = ds_type_count;
6537
6538 VkDescriptorPool ds_pool;
6539 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6540 ASSERT_VK_SUCCESS(err);
6541
Mark Muellerb9896722016-06-16 09:54:29 -06006542 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006543 layout_binding[0].binding = 0;
6544 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6545 layout_binding[0].descriptorCount = 1;
6546 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6547 layout_binding[0].pImmutableSamplers = NULL;
6548
6549 layout_binding[1].binding = 1;
6550 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6551 layout_binding[1].descriptorCount = 1;
6552 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6553 layout_binding[1].pImmutableSamplers = NULL;
6554
6555 VkSamplerCreateInfo sampler_ci = {};
6556 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6557 sampler_ci.pNext = NULL;
6558 sampler_ci.magFilter = VK_FILTER_NEAREST;
6559 sampler_ci.minFilter = VK_FILTER_NEAREST;
6560 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6561 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6562 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6563 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6564 sampler_ci.mipLodBias = 1.0;
6565 sampler_ci.anisotropyEnable = VK_FALSE;
6566 sampler_ci.maxAnisotropy = 1;
6567 sampler_ci.compareEnable = VK_FALSE;
6568 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6569 sampler_ci.minLod = 1.0;
6570 sampler_ci.maxLod = 1.0;
6571 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6572 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6573 VkSampler sampler;
6574
6575 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6576 ASSERT_VK_SUCCESS(err);
6577
6578 layout_binding[2].binding = 2;
6579 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6580 layout_binding[2].descriptorCount = 1;
6581 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6582 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
6583
Mark Muellerd4914412016-06-13 17:52:06 -06006584 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6585 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6586 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
6587 ds_layout_ci.pBindings = layout_binding;
6588 VkDescriptorSetLayout ds_layout;
6589 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6590 ASSERT_VK_SUCCESS(err);
6591
6592 VkDescriptorSetAllocateInfo alloc_info = {};
6593 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6594 alloc_info.descriptorSetCount = 1;
6595 alloc_info.descriptorPool = ds_pool;
6596 alloc_info.pSetLayouts = &ds_layout;
6597 VkDescriptorSet descriptorSet;
6598 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6599 ASSERT_VK_SUCCESS(err);
6600
6601 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6602 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6603 pipeline_layout_ci.pNext = NULL;
6604 pipeline_layout_ci.setLayoutCount = 1;
6605 pipeline_layout_ci.pSetLayouts = &ds_layout;
6606
6607 VkPipelineLayout pipeline_layout;
6608 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6609 ASSERT_VK_SUCCESS(err);
6610
Mark Mueller5c838ce2016-06-16 09:54:29 -06006611 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006612 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6613 descriptor_write.dstSet = descriptorSet;
6614 descriptor_write.dstBinding = 0;
6615 descriptor_write.descriptorCount = 1;
6616 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6617
Mark Mueller5c838ce2016-06-16 09:54:29 -06006618 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06006619 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6620 m_errorMonitor->VerifyFound();
6621
6622 // Create a buffer to update the descriptor with
6623 uint32_t qfi = 0;
6624 VkBufferCreateInfo buffCI = {};
6625 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6626 buffCI.size = 1024;
6627 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6628 buffCI.queueFamilyIndexCount = 1;
6629 buffCI.pQueueFamilyIndices = &qfi;
6630
6631 VkBuffer dyub;
6632 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6633 ASSERT_VK_SUCCESS(err);
6634 VkDescriptorBufferInfo buffInfo = {};
6635 buffInfo.buffer = dyub;
6636 buffInfo.offset = 0;
6637 buffInfo.range = 1024;
6638
6639 descriptor_write.pBufferInfo = &buffInfo;
6640 descriptor_write.descriptorCount = 2;
6641
Mark Mueller5c838ce2016-06-16 09:54:29 -06006642 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06006643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
6644 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6645 m_errorMonitor->VerifyFound();
6646
Mark Mueller5c838ce2016-06-16 09:54:29 -06006647 // 3) The second descriptor has a null_ptr pImmutableSamplers and
6648 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06006649 descriptor_write.dstBinding = 1;
6650 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06006651
Mark Mueller5c838ce2016-06-16 09:54:29 -06006652 // Make pImageInfo index non-null to avoid complaints of it missing
6653 VkDescriptorImageInfo imageInfo = {};
6654 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6655 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06006656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
6657 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6658 m_errorMonitor->VerifyFound();
6659
Mark Muellerd4914412016-06-13 17:52:06 -06006660 vkDestroyBuffer(m_device->device(), dyub, NULL);
6661 vkDestroySampler(m_device->device(), sampler, NULL);
6662 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6663 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6664 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6665}
6666
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006667TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
6668 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6669 "due to a buffer dependency being destroyed.");
6670 ASSERT_NO_FATAL_FAILURE(InitState());
6671
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006672 VkBuffer buffer;
6673 VkDeviceMemory mem;
6674 VkMemoryRequirements mem_reqs;
6675
6676 VkBufferCreateInfo buf_info = {};
6677 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12006678 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006679 buf_info.size = 256;
6680 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6681 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
6682 ASSERT_VK_SUCCESS(err);
6683
6684 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
6685
6686 VkMemoryAllocateInfo alloc_info = {};
6687 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6688 alloc_info.allocationSize = 256;
6689 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006690 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006691 if (!pass) {
6692 vkDestroyBuffer(m_device->device(), buffer, NULL);
6693 return;
6694 }
6695 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
6696 ASSERT_VK_SUCCESS(err);
6697
6698 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
6699 ASSERT_VK_SUCCESS(err);
6700
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006701 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12006702 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006703 m_commandBuffer->EndCommandBuffer();
6704
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006706 // Destroy buffer dependency prior to submit to cause ERROR
6707 vkDestroyBuffer(m_device->device(), buffer, NULL);
6708
6709 VkSubmitInfo submit_info = {};
6710 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6711 submit_info.commandBufferCount = 1;
6712 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6713 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6714
6715 m_errorMonitor->VerifyFound();
6716 vkFreeMemory(m_device->handle(), mem, NULL);
6717}
6718
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006719TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
6720 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6721 "due to an image dependency being destroyed.");
6722 ASSERT_NO_FATAL_FAILURE(InitState());
6723
6724 VkImage image;
6725 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6726 VkImageCreateInfo image_create_info = {};
6727 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6728 image_create_info.pNext = NULL;
6729 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6730 image_create_info.format = tex_format;
6731 image_create_info.extent.width = 32;
6732 image_create_info.extent.height = 32;
6733 image_create_info.extent.depth = 1;
6734 image_create_info.mipLevels = 1;
6735 image_create_info.arrayLayers = 1;
6736 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6737 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006738 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006739 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006740 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006741 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006742 // Have to bind memory to image before recording cmd in cmd buffer using it
6743 VkMemoryRequirements mem_reqs;
6744 VkDeviceMemory image_mem;
6745 bool pass;
6746 VkMemoryAllocateInfo mem_alloc = {};
6747 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6748 mem_alloc.pNext = NULL;
6749 mem_alloc.memoryTypeIndex = 0;
6750 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6751 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006752 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006753 ASSERT_TRUE(pass);
6754 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6755 ASSERT_VK_SUCCESS(err);
6756 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
6757 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006758
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006759 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06006760 VkClearColorValue ccv;
6761 ccv.float32[0] = 1.0f;
6762 ccv.float32[1] = 1.0f;
6763 ccv.float32[2] = 1.0f;
6764 ccv.float32[3] = 1.0f;
6765 VkImageSubresourceRange isr = {};
6766 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006767 isr.baseArrayLayer = 0;
6768 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06006769 isr.layerCount = 1;
6770 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006771 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006772 m_commandBuffer->EndCommandBuffer();
6773
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006775 // Destroy image dependency prior to submit to cause ERROR
6776 vkDestroyImage(m_device->device(), image, NULL);
6777
6778 VkSubmitInfo submit_info = {};
6779 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6780 submit_info.commandBufferCount = 1;
6781 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6782 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6783
6784 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006785 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006786}
6787
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006788TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
6789 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6790 "due to a framebuffer image dependency being destroyed.");
6791 VkFormatProperties format_properties;
6792 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006793 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
6794 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006795 return;
6796 }
6797
6798 ASSERT_NO_FATAL_FAILURE(InitState());
6799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6800
6801 VkImageCreateInfo image_ci = {};
6802 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6803 image_ci.pNext = NULL;
6804 image_ci.imageType = VK_IMAGE_TYPE_2D;
6805 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
6806 image_ci.extent.width = 32;
6807 image_ci.extent.height = 32;
6808 image_ci.extent.depth = 1;
6809 image_ci.mipLevels = 1;
6810 image_ci.arrayLayers = 1;
6811 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
6812 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006813 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006814 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6815 image_ci.flags = 0;
6816 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006817 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006818
6819 VkMemoryRequirements memory_reqs;
6820 VkDeviceMemory image_memory;
6821 bool pass;
6822 VkMemoryAllocateInfo memory_info = {};
6823 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6824 memory_info.pNext = NULL;
6825 memory_info.allocationSize = 0;
6826 memory_info.memoryTypeIndex = 0;
6827 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6828 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006829 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006830 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006831 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006832 ASSERT_VK_SUCCESS(err);
6833 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6834 ASSERT_VK_SUCCESS(err);
6835
6836 VkImageViewCreateInfo ivci = {
6837 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
6838 nullptr,
6839 0,
6840 image,
6841 VK_IMAGE_VIEW_TYPE_2D,
6842 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006843 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006844 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
6845 };
6846 VkImageView view;
6847 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
6848 ASSERT_VK_SUCCESS(err);
6849
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006850 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006851 VkFramebuffer fb;
6852 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
6853 ASSERT_VK_SUCCESS(err);
6854
6855 // Just use default renderpass with our framebuffer
6856 m_renderPassBeginInfo.framebuffer = fb;
6857 // Create Null cmd buffer for submit
6858 BeginCommandBuffer();
6859 EndCommandBuffer();
6860 // Destroy image attached to framebuffer to invalidate cmd buffer
6861 vkDestroyImage(m_device->device(), image, NULL);
6862 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006864 QueueCommandBuffer(false);
6865 m_errorMonitor->VerifyFound();
6866
6867 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
6868 vkDestroyImageView(m_device->device(), view, nullptr);
6869 vkFreeMemory(m_device->device(), image_memory, nullptr);
6870}
6871
Tobin Ehlis88becd72016-09-21 14:33:41 -06006872TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
6873 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
6874 VkFormatProperties format_properties;
6875 VkResult err = VK_SUCCESS;
6876 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06006877
6878 ASSERT_NO_FATAL_FAILURE(InitState());
6879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6880
6881 VkImageCreateInfo image_ci = {};
6882 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6883 image_ci.pNext = NULL;
6884 image_ci.imageType = VK_IMAGE_TYPE_2D;
6885 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
6886 image_ci.extent.width = 256;
6887 image_ci.extent.height = 256;
6888 image_ci.extent.depth = 1;
6889 image_ci.mipLevels = 1;
6890 image_ci.arrayLayers = 1;
6891 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
6892 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06006893 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06006894 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6895 image_ci.flags = 0;
6896 VkImage image;
6897 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
6898
6899 VkMemoryRequirements memory_reqs;
6900 VkDeviceMemory image_memory;
6901 bool pass;
6902 VkMemoryAllocateInfo memory_info = {};
6903 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6904 memory_info.pNext = NULL;
6905 memory_info.allocationSize = 0;
6906 memory_info.memoryTypeIndex = 0;
6907 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6908 memory_info.allocationSize = memory_reqs.size;
6909 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6910 ASSERT_TRUE(pass);
6911 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6912 ASSERT_VK_SUCCESS(err);
6913 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6914 ASSERT_VK_SUCCESS(err);
6915
6916 VkImageViewCreateInfo ivci = {
6917 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
6918 nullptr,
6919 0,
6920 image,
6921 VK_IMAGE_VIEW_TYPE_2D,
6922 VK_FORMAT_B8G8R8A8_UNORM,
6923 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
6924 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
6925 };
6926 VkImageView view;
6927 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
6928 ASSERT_VK_SUCCESS(err);
6929
6930 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
6931 VkFramebuffer fb;
6932 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
6933 ASSERT_VK_SUCCESS(err);
6934
6935 // Just use default renderpass with our framebuffer
6936 m_renderPassBeginInfo.framebuffer = fb;
6937 // Create Null cmd buffer for submit
6938 BeginCommandBuffer();
6939 EndCommandBuffer();
6940 // Submit cmd buffer to put it (and attached imageView) in-flight
6941 VkSubmitInfo submit_info = {};
6942 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6943 submit_info.commandBufferCount = 1;
6944 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6945 // Submit cmd buffer to put framebuffer and children in-flight
6946 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6947 // Destroy image attached to framebuffer while in-flight
6948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
6949 vkDestroyImage(m_device->device(), image, NULL);
6950 m_errorMonitor->VerifyFound();
6951 // Wait for queue to complete so we can safely destroy image and other objects
6952 vkQueueWaitIdle(m_device->m_queue);
6953 vkDestroyImage(m_device->device(), image, NULL);
6954 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
6955 vkDestroyImageView(m_device->device(), view, nullptr);
6956 vkFreeMemory(m_device->device(), image_memory, nullptr);
6957}
6958
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006959TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006960 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006961 ASSERT_NO_FATAL_FAILURE(InitState());
6962
6963 VkImage image;
6964 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6965 VkImageCreateInfo image_create_info = {};
6966 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6967 image_create_info.pNext = NULL;
6968 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6969 image_create_info.format = tex_format;
6970 image_create_info.extent.width = 32;
6971 image_create_info.extent.height = 32;
6972 image_create_info.extent.depth = 1;
6973 image_create_info.mipLevels = 1;
6974 image_create_info.arrayLayers = 1;
6975 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6976 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006977 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006978 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006979 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006980 ASSERT_VK_SUCCESS(err);
6981 // Have to bind memory to image before recording cmd in cmd buffer using it
6982 VkMemoryRequirements mem_reqs;
6983 VkDeviceMemory image_mem;
6984 bool pass;
6985 VkMemoryAllocateInfo mem_alloc = {};
6986 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6987 mem_alloc.pNext = NULL;
6988 mem_alloc.memoryTypeIndex = 0;
6989 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6990 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006991 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006992 ASSERT_TRUE(pass);
6993 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6994 ASSERT_VK_SUCCESS(err);
6995
6996 // Introduce error, do not call vkBindImageMemory(m_device->device(), image,
6997 // image_mem, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindImageMemory");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006999
7000 m_commandBuffer->BeginCommandBuffer();
7001 VkClearColorValue ccv;
7002 ccv.float32[0] = 1.0f;
7003 ccv.float32[1] = 1.0f;
7004 ccv.float32[2] = 1.0f;
7005 ccv.float32[3] = 1.0f;
7006 VkImageSubresourceRange isr = {};
7007 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7008 isr.baseArrayLayer = 0;
7009 isr.baseMipLevel = 0;
7010 isr.layerCount = 1;
7011 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007012 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007013 m_commandBuffer->EndCommandBuffer();
7014
7015 m_errorMonitor->VerifyFound();
7016 vkDestroyImage(m_device->device(), image, NULL);
7017 vkFreeMemory(m_device->device(), image_mem, nullptr);
7018}
7019
7020TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007021 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007022 ASSERT_NO_FATAL_FAILURE(InitState());
7023
7024 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007025 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 -06007026 VK_IMAGE_TILING_OPTIMAL, 0);
7027 ASSERT_TRUE(image.initialized());
7028
7029 VkBuffer buffer;
7030 VkDeviceMemory mem;
7031 VkMemoryRequirements mem_reqs;
7032
7033 VkBufferCreateInfo buf_info = {};
7034 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12007035 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007036 buf_info.size = 256;
7037 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7038 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
7039 ASSERT_VK_SUCCESS(err);
7040
7041 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
7042
7043 VkMemoryAllocateInfo alloc_info = {};
7044 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7045 alloc_info.allocationSize = 256;
7046 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007047 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 -06007048 if (!pass) {
7049 vkDestroyBuffer(m_device->device(), buffer, NULL);
7050 return;
7051 }
7052 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
7053 ASSERT_VK_SUCCESS(err);
7054
7055 // Introduce failure by not calling vkBindBufferMemory(m_device->device(),
7056 // buffer, mem, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindBufferMemory");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007058 VkBufferImageCopy region = {};
7059 region.bufferRowLength = 128;
7060 region.bufferImageHeight = 128;
7061 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7062
7063 region.imageSubresource.layerCount = 1;
7064 region.imageExtent.height = 4;
7065 region.imageExtent.width = 4;
7066 region.imageExtent.depth = 1;
7067 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007068 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
7069 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007070 m_commandBuffer->EndCommandBuffer();
7071
7072 m_errorMonitor->VerifyFound();
7073
7074 vkDestroyBuffer(m_device->device(), buffer, NULL);
7075 vkFreeMemory(m_device->handle(), mem, NULL);
7076}
7077
Tobin Ehlis85940f52016-07-07 16:57:21 -06007078TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
7079 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7080 "due to an event dependency being destroyed.");
7081 ASSERT_NO_FATAL_FAILURE(InitState());
7082
7083 VkEvent event;
7084 VkEventCreateInfo evci = {};
7085 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
7086 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
7087 ASSERT_VK_SUCCESS(result);
7088
7089 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007090 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06007091 m_commandBuffer->EndCommandBuffer();
7092
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06007094 // Destroy event dependency prior to submit to cause ERROR
7095 vkDestroyEvent(m_device->device(), event, NULL);
7096
7097 VkSubmitInfo submit_info = {};
7098 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7099 submit_info.commandBufferCount = 1;
7100 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7101 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7102
7103 m_errorMonitor->VerifyFound();
7104}
7105
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007106TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
7107 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7108 "due to a query pool dependency being destroyed.");
7109 ASSERT_NO_FATAL_FAILURE(InitState());
7110
7111 VkQueryPool query_pool;
7112 VkQueryPoolCreateInfo qpci{};
7113 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
7114 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
7115 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007116 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007117 ASSERT_VK_SUCCESS(result);
7118
7119 m_commandBuffer->BeginCommandBuffer();
7120 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
7121 m_commandBuffer->EndCommandBuffer();
7122
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007124 // Destroy query pool dependency prior to submit to cause ERROR
7125 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
7126
7127 VkSubmitInfo submit_info = {};
7128 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7129 submit_info.commandBufferCount = 1;
7130 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7131 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7132
7133 m_errorMonitor->VerifyFound();
7134}
7135
Tobin Ehlis24130d92016-07-08 15:50:53 -06007136TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
7137 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7138 "due to a pipeline dependency being destroyed.");
7139 ASSERT_NO_FATAL_FAILURE(InitState());
7140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7141
7142 VkResult err;
7143
7144 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7145 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7146
7147 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007148 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007149 ASSERT_VK_SUCCESS(err);
7150
7151 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7152 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7153 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007154 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06007155 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007156 vp_state_ci.scissorCount = 1;
7157 VkRect2D scissors = {}; // Dummy scissors to point to
7158 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007159
7160 VkPipelineShaderStageCreateInfo shaderStages[2];
7161 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7162
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007163 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7164 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7165 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06007166 shaderStages[0] = vs.GetStageCreateInfo();
7167 shaderStages[1] = fs.GetStageCreateInfo();
7168
7169 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7170 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7171
7172 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7173 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7174 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7175
7176 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7177 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12007178 rs_ci.rasterizerDiscardEnable = true;
7179 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007180
7181 VkPipelineColorBlendAttachmentState att = {};
7182 att.blendEnable = VK_FALSE;
7183 att.colorWriteMask = 0xf;
7184
7185 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7186 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7187 cb_ci.attachmentCount = 1;
7188 cb_ci.pAttachments = &att;
7189
7190 VkGraphicsPipelineCreateInfo gp_ci = {};
7191 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7192 gp_ci.stageCount = 2;
7193 gp_ci.pStages = shaderStages;
7194 gp_ci.pVertexInputState = &vi_ci;
7195 gp_ci.pInputAssemblyState = &ia_ci;
7196 gp_ci.pViewportState = &vp_state_ci;
7197 gp_ci.pRasterizationState = &rs_ci;
7198 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007199 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7200 gp_ci.layout = pipeline_layout;
7201 gp_ci.renderPass = renderPass();
7202
7203 VkPipelineCacheCreateInfo pc_ci = {};
7204 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7205
7206 VkPipeline pipeline;
7207 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007208 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007209 ASSERT_VK_SUCCESS(err);
7210
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007211 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007212 ASSERT_VK_SUCCESS(err);
7213
7214 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007215 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007216 m_commandBuffer->EndCommandBuffer();
7217 // Now destroy pipeline in order to cause error when submitting
7218 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
7219
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06007221
7222 VkSubmitInfo submit_info = {};
7223 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7224 submit_info.commandBufferCount = 1;
7225 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7226 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7227
7228 m_errorMonitor->VerifyFound();
7229 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7230 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7231}
7232
Tobin Ehlis31289162016-08-17 14:57:58 -06007233TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
7234 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7235 "due to a bound descriptor set with a buffer dependency "
7236 "being destroyed.");
7237 ASSERT_NO_FATAL_FAILURE(InitState());
7238 ASSERT_NO_FATAL_FAILURE(InitViewport());
7239 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7240
7241 VkDescriptorPoolSize ds_type_count = {};
7242 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7243 ds_type_count.descriptorCount = 1;
7244
7245 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7246 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7247 ds_pool_ci.pNext = NULL;
7248 ds_pool_ci.maxSets = 1;
7249 ds_pool_ci.poolSizeCount = 1;
7250 ds_pool_ci.pPoolSizes = &ds_type_count;
7251
7252 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007253 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06007254 ASSERT_VK_SUCCESS(err);
7255
7256 VkDescriptorSetLayoutBinding dsl_binding = {};
7257 dsl_binding.binding = 0;
7258 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7259 dsl_binding.descriptorCount = 1;
7260 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7261 dsl_binding.pImmutableSamplers = NULL;
7262
7263 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7264 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7265 ds_layout_ci.pNext = NULL;
7266 ds_layout_ci.bindingCount = 1;
7267 ds_layout_ci.pBindings = &dsl_binding;
7268 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007269 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007270 ASSERT_VK_SUCCESS(err);
7271
7272 VkDescriptorSet descriptorSet;
7273 VkDescriptorSetAllocateInfo alloc_info = {};
7274 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7275 alloc_info.descriptorSetCount = 1;
7276 alloc_info.descriptorPool = ds_pool;
7277 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007278 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06007279 ASSERT_VK_SUCCESS(err);
7280
7281 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7282 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7283 pipeline_layout_ci.pNext = NULL;
7284 pipeline_layout_ci.setLayoutCount = 1;
7285 pipeline_layout_ci.pSetLayouts = &ds_layout;
7286
7287 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007288 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007289 ASSERT_VK_SUCCESS(err);
7290
7291 // Create a buffer to update the descriptor with
7292 uint32_t qfi = 0;
7293 VkBufferCreateInfo buffCI = {};
7294 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7295 buffCI.size = 1024;
7296 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7297 buffCI.queueFamilyIndexCount = 1;
7298 buffCI.pQueueFamilyIndices = &qfi;
7299
7300 VkBuffer buffer;
7301 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
7302 ASSERT_VK_SUCCESS(err);
7303 // Allocate memory and bind to buffer so we can make it to the appropriate
7304 // error
7305 VkMemoryAllocateInfo mem_alloc = {};
7306 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7307 mem_alloc.pNext = NULL;
7308 mem_alloc.allocationSize = 1024;
7309 mem_alloc.memoryTypeIndex = 0;
7310
7311 VkMemoryRequirements memReqs;
7312 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007313 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06007314 if (!pass) {
7315 vkDestroyBuffer(m_device->device(), buffer, NULL);
7316 return;
7317 }
7318
7319 VkDeviceMemory mem;
7320 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7321 ASSERT_VK_SUCCESS(err);
7322 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
7323 ASSERT_VK_SUCCESS(err);
7324 // Correctly update descriptor to avoid "NOT_UPDATED" error
7325 VkDescriptorBufferInfo buffInfo = {};
7326 buffInfo.buffer = buffer;
7327 buffInfo.offset = 0;
7328 buffInfo.range = 1024;
7329
7330 VkWriteDescriptorSet descriptor_write;
7331 memset(&descriptor_write, 0, sizeof(descriptor_write));
7332 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7333 descriptor_write.dstSet = descriptorSet;
7334 descriptor_write.dstBinding = 0;
7335 descriptor_write.descriptorCount = 1;
7336 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7337 descriptor_write.pBufferInfo = &buffInfo;
7338
7339 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7340
7341 // Create PSO to be used for draw-time errors below
7342 char const *vsSource = "#version 450\n"
7343 "\n"
7344 "out gl_PerVertex { \n"
7345 " vec4 gl_Position;\n"
7346 "};\n"
7347 "void main(){\n"
7348 " gl_Position = vec4(1);\n"
7349 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007350 char const *fsSource = "#version 450\n"
7351 "\n"
7352 "layout(location=0) out vec4 x;\n"
7353 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7354 "void main(){\n"
7355 " x = vec4(bar.y);\n"
7356 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06007357 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7358 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7359 VkPipelineObj pipe(m_device);
7360 pipe.AddShader(&vs);
7361 pipe.AddShader(&fs);
7362 pipe.AddColorAttachment();
7363 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7364
7365 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007366 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7367 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7368 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06007369 Draw(1, 0, 0, 0);
7370 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06007372 // Destroy buffer should invalidate the cmd buffer, causing error on submit
7373 vkDestroyBuffer(m_device->device(), buffer, NULL);
7374 // Attempt to submit cmd buffer
7375 VkSubmitInfo submit_info = {};
7376 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7377 submit_info.commandBufferCount = 1;
7378 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7379 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7380 m_errorMonitor->VerifyFound();
7381 // Cleanup
7382 vkFreeMemory(m_device->device(), mem, NULL);
7383
7384 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7385 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7386 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7387}
7388
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007389TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
7390 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7391 "due to a bound descriptor sets with a combined image "
7392 "sampler having their image, sampler, and descriptor set "
7393 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06007394 "submit associated cmd buffers. Attempt to destroy a "
7395 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007396 ASSERT_NO_FATAL_FAILURE(InitState());
7397 ASSERT_NO_FATAL_FAILURE(InitViewport());
7398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7399
7400 VkDescriptorPoolSize ds_type_count = {};
7401 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7402 ds_type_count.descriptorCount = 1;
7403
7404 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7405 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7406 ds_pool_ci.pNext = NULL;
7407 ds_pool_ci.maxSets = 1;
7408 ds_pool_ci.poolSizeCount = 1;
7409 ds_pool_ci.pPoolSizes = &ds_type_count;
7410
7411 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007412 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007413 ASSERT_VK_SUCCESS(err);
7414
7415 VkDescriptorSetLayoutBinding dsl_binding = {};
7416 dsl_binding.binding = 0;
7417 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7418 dsl_binding.descriptorCount = 1;
7419 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7420 dsl_binding.pImmutableSamplers = NULL;
7421
7422 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7423 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7424 ds_layout_ci.pNext = NULL;
7425 ds_layout_ci.bindingCount = 1;
7426 ds_layout_ci.pBindings = &dsl_binding;
7427 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007428 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007429 ASSERT_VK_SUCCESS(err);
7430
7431 VkDescriptorSet descriptorSet;
7432 VkDescriptorSetAllocateInfo alloc_info = {};
7433 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7434 alloc_info.descriptorSetCount = 1;
7435 alloc_info.descriptorPool = ds_pool;
7436 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007437 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007438 ASSERT_VK_SUCCESS(err);
7439
7440 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7441 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7442 pipeline_layout_ci.pNext = NULL;
7443 pipeline_layout_ci.setLayoutCount = 1;
7444 pipeline_layout_ci.pSetLayouts = &ds_layout;
7445
7446 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007447 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007448 ASSERT_VK_SUCCESS(err);
7449
7450 // Create images to update the descriptor with
7451 VkImage image;
7452 VkImage image2;
7453 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7454 const int32_t tex_width = 32;
7455 const int32_t tex_height = 32;
7456 VkImageCreateInfo image_create_info = {};
7457 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7458 image_create_info.pNext = NULL;
7459 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7460 image_create_info.format = tex_format;
7461 image_create_info.extent.width = tex_width;
7462 image_create_info.extent.height = tex_height;
7463 image_create_info.extent.depth = 1;
7464 image_create_info.mipLevels = 1;
7465 image_create_info.arrayLayers = 1;
7466 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7467 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7468 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7469 image_create_info.flags = 0;
7470 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
7471 ASSERT_VK_SUCCESS(err);
7472 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
7473 ASSERT_VK_SUCCESS(err);
7474
7475 VkMemoryRequirements memory_reqs;
7476 VkDeviceMemory image_memory;
7477 bool pass;
7478 VkMemoryAllocateInfo memory_info = {};
7479 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7480 memory_info.pNext = NULL;
7481 memory_info.allocationSize = 0;
7482 memory_info.memoryTypeIndex = 0;
7483 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
7484 // Allocate enough memory for both images
7485 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007486 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007487 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007488 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007489 ASSERT_VK_SUCCESS(err);
7490 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
7491 ASSERT_VK_SUCCESS(err);
7492 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007493 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007494 ASSERT_VK_SUCCESS(err);
7495
7496 VkImageViewCreateInfo image_view_create_info = {};
7497 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7498 image_view_create_info.image = image;
7499 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
7500 image_view_create_info.format = tex_format;
7501 image_view_create_info.subresourceRange.layerCount = 1;
7502 image_view_create_info.subresourceRange.baseMipLevel = 0;
7503 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007504 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007505
7506 VkImageView view;
7507 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007508 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007509 ASSERT_VK_SUCCESS(err);
7510 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007511 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007512 ASSERT_VK_SUCCESS(err);
7513 // Create Samplers
7514 VkSamplerCreateInfo sampler_ci = {};
7515 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7516 sampler_ci.pNext = NULL;
7517 sampler_ci.magFilter = VK_FILTER_NEAREST;
7518 sampler_ci.minFilter = VK_FILTER_NEAREST;
7519 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7520 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7521 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7522 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7523 sampler_ci.mipLodBias = 1.0;
7524 sampler_ci.anisotropyEnable = VK_FALSE;
7525 sampler_ci.maxAnisotropy = 1;
7526 sampler_ci.compareEnable = VK_FALSE;
7527 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7528 sampler_ci.minLod = 1.0;
7529 sampler_ci.maxLod = 1.0;
7530 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7531 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7532 VkSampler sampler;
7533 VkSampler sampler2;
7534 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7535 ASSERT_VK_SUCCESS(err);
7536 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
7537 ASSERT_VK_SUCCESS(err);
7538 // Update descriptor with image and sampler
7539 VkDescriptorImageInfo img_info = {};
7540 img_info.sampler = sampler;
7541 img_info.imageView = view;
7542 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
7543
7544 VkWriteDescriptorSet descriptor_write;
7545 memset(&descriptor_write, 0, sizeof(descriptor_write));
7546 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7547 descriptor_write.dstSet = descriptorSet;
7548 descriptor_write.dstBinding = 0;
7549 descriptor_write.descriptorCount = 1;
7550 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7551 descriptor_write.pImageInfo = &img_info;
7552
7553 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7554
7555 // Create PSO to be used for draw-time errors below
7556 char const *vsSource = "#version 450\n"
7557 "\n"
7558 "out gl_PerVertex { \n"
7559 " vec4 gl_Position;\n"
7560 "};\n"
7561 "void main(){\n"
7562 " gl_Position = vec4(1);\n"
7563 "}\n";
7564 char const *fsSource = "#version 450\n"
7565 "\n"
7566 "layout(set=0, binding=0) uniform sampler2D s;\n"
7567 "layout(location=0) out vec4 x;\n"
7568 "void main(){\n"
7569 " x = texture(s, vec2(1));\n"
7570 "}\n";
7571 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7572 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7573 VkPipelineObj pipe(m_device);
7574 pipe.AddShader(&vs);
7575 pipe.AddShader(&fs);
7576 pipe.AddColorAttachment();
7577 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7578
7579 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007581 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007582 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7583 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7584 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007585 Draw(1, 0, 0, 0);
7586 EndCommandBuffer();
7587 // Destroy sampler invalidates the cmd buffer, causing error on submit
7588 vkDestroySampler(m_device->device(), sampler, NULL);
7589 // Attempt to submit cmd buffer
7590 VkSubmitInfo submit_info = {};
7591 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7592 submit_info.commandBufferCount = 1;
7593 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7594 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7595 m_errorMonitor->VerifyFound();
7596 // Now re-update descriptor with valid sampler and delete image
7597 img_info.sampler = sampler2;
7598 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007600 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007601 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7602 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7603 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007604 Draw(1, 0, 0, 0);
7605 EndCommandBuffer();
7606 // Destroy image invalidates the cmd buffer, causing error on submit
7607 vkDestroyImage(m_device->device(), image, NULL);
7608 // Attempt to submit cmd buffer
7609 submit_info = {};
7610 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7611 submit_info.commandBufferCount = 1;
7612 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7613 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7614 m_errorMonitor->VerifyFound();
7615 // Now update descriptor to be valid, but then free descriptor
7616 img_info.imageView = view2;
7617 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007619 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007620 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7621 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7622 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007623 Draw(1, 0, 0, 0);
7624 EndCommandBuffer();
7625 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007627 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06007628 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007629 // Attempt to submit cmd buffer
7630 submit_info = {};
7631 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7632 submit_info.commandBufferCount = 1;
7633 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7634 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7635 m_errorMonitor->VerifyFound();
7636 // Cleanup
7637 vkFreeMemory(m_device->device(), image_memory, NULL);
7638 vkDestroySampler(m_device->device(), sampler2, NULL);
7639 vkDestroyImage(m_device->device(), image2, NULL);
7640 vkDestroyImageView(m_device->device(), view, NULL);
7641 vkDestroyImageView(m_device->device(), view2, NULL);
7642 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7643 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7644 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7645}
7646
Karl Schultz6addd812016-02-02 17:17:23 -07007647TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06007648 // Attempt to bind an invalid Pipeline to a valid Command Buffer
7649 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007650 // Create a valid cmd buffer
7651 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06007652 uint64_t fake_pipeline_handle = 0xbaad6001;
7653 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06007654 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12007655 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7656
7657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06007658 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007659 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06007660 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12007661
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007662 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007663 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 -06007664 Draw(1, 0, 0, 0);
7665 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12007666
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007667 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Chris Forbes4dbf70f2016-09-16 17:58:00 +12007669 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007670 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
7671 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007672}
7673
Karl Schultz6addd812016-02-02 17:17:23 -07007674TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06007675 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07007676 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007677
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007679
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007680 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06007681 ASSERT_NO_FATAL_FAILURE(InitViewport());
7682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007683 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007684 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7685 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007686
7687 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007688 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7689 ds_pool_ci.pNext = NULL;
7690 ds_pool_ci.maxSets = 1;
7691 ds_pool_ci.poolSizeCount = 1;
7692 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06007693
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007694 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007695 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007696 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007697
Tony Barboureb254902015-07-15 12:50:33 -06007698 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007699 dsl_binding.binding = 0;
7700 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7701 dsl_binding.descriptorCount = 1;
7702 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7703 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007704
Tony Barboureb254902015-07-15 12:50:33 -06007705 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007706 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7707 ds_layout_ci.pNext = NULL;
7708 ds_layout_ci.bindingCount = 1;
7709 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007710 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007711 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007712 ASSERT_VK_SUCCESS(err);
7713
7714 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007715 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007716 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007717 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007718 alloc_info.descriptorPool = ds_pool;
7719 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007720 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007721 ASSERT_VK_SUCCESS(err);
7722
Tony Barboureb254902015-07-15 12:50:33 -06007723 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007724 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7725 pipeline_layout_ci.pNext = NULL;
7726 pipeline_layout_ci.setLayoutCount = 1;
7727 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007728
7729 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007730 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007731 ASSERT_VK_SUCCESS(err);
7732
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007733 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06007734 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07007735 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007736 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007737
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007738 VkPipelineObj pipe(m_device);
7739 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007740 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06007741 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007742 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06007743
7744 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007745 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7746 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7747 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007748
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007749 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007750
Chia-I Wuf7458c52015-10-26 21:10:41 +08007751 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7752 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7753 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007754}
7755
Karl Schultz6addd812016-02-02 17:17:23 -07007756TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007757 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07007758 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007759
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
7761 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007762
7763 ASSERT_NO_FATAL_FAILURE(InitState());
7764 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007765 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7766 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007767
7768 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007769 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7770 ds_pool_ci.pNext = NULL;
7771 ds_pool_ci.maxSets = 1;
7772 ds_pool_ci.poolSizeCount = 1;
7773 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007774
7775 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007776 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007777 ASSERT_VK_SUCCESS(err);
7778
7779 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007780 dsl_binding.binding = 0;
7781 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7782 dsl_binding.descriptorCount = 1;
7783 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7784 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007785
7786 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007787 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7788 ds_layout_ci.pNext = NULL;
7789 ds_layout_ci.bindingCount = 1;
7790 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007791 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007792 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007793 ASSERT_VK_SUCCESS(err);
7794
7795 VkDescriptorSet descriptorSet;
7796 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007797 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007798 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007799 alloc_info.descriptorPool = ds_pool;
7800 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007801 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007802 ASSERT_VK_SUCCESS(err);
7803
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007804 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007805 VkWriteDescriptorSet descriptor_write;
7806 memset(&descriptor_write, 0, sizeof(descriptor_write));
7807 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7808 descriptor_write.dstSet = descriptorSet;
7809 descriptor_write.dstBinding = 0;
7810 descriptor_write.descriptorCount = 1;
7811 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7812 descriptor_write.pTexelBufferView = &view;
7813
7814 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7815
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007816 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007817
7818 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7819 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7820}
7821
Mark Youngd339ba32016-05-30 13:28:35 -06007822TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
7823 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has"
7824 " no memory bound to it.");
7825
7826 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindBufferMemory");
Mark Youngd339ba32016-05-30 13:28:35 -06007828
7829 ASSERT_NO_FATAL_FAILURE(InitState());
7830
7831 // Create a buffer with no bound memory and then attempt to create
7832 // a buffer view.
7833 VkBufferCreateInfo buff_ci = {};
7834 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12007835 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06007836 buff_ci.size = 256;
7837 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7838 VkBuffer buffer;
7839 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7840 ASSERT_VK_SUCCESS(err);
7841
7842 VkBufferViewCreateInfo buff_view_ci = {};
7843 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7844 buff_view_ci.buffer = buffer;
7845 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7846 buff_view_ci.range = VK_WHOLE_SIZE;
7847 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007848 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06007849
7850 m_errorMonitor->VerifyFound();
7851 vkDestroyBuffer(m_device->device(), buffer, NULL);
7852 // If last error is success, it still created the view, so delete it.
7853 if (err == VK_SUCCESS) {
7854 vkDestroyBufferView(m_device->device(), buff_view, NULL);
7855 }
7856}
7857
Karl Schultz6addd812016-02-02 17:17:23 -07007858TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
7859 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
7860 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07007861 // 1. No dynamicOffset supplied
7862 // 2. Too many dynamicOffsets supplied
7863 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07007864 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
7866 "0 dynamicOffsets are left in "
7867 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007868
7869 ASSERT_NO_FATAL_FAILURE(InitState());
7870 ASSERT_NO_FATAL_FAILURE(InitViewport());
7871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7872
7873 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007874 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7875 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007876
7877 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007878 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7879 ds_pool_ci.pNext = NULL;
7880 ds_pool_ci.maxSets = 1;
7881 ds_pool_ci.poolSizeCount = 1;
7882 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007883
7884 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007885 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007886 ASSERT_VK_SUCCESS(err);
7887
7888 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007889 dsl_binding.binding = 0;
7890 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7891 dsl_binding.descriptorCount = 1;
7892 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7893 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007894
7895 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007896 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7897 ds_layout_ci.pNext = NULL;
7898 ds_layout_ci.bindingCount = 1;
7899 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007900 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007901 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007902 ASSERT_VK_SUCCESS(err);
7903
7904 VkDescriptorSet descriptorSet;
7905 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007906 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007907 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007908 alloc_info.descriptorPool = ds_pool;
7909 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007910 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007911 ASSERT_VK_SUCCESS(err);
7912
7913 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007914 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7915 pipeline_layout_ci.pNext = NULL;
7916 pipeline_layout_ci.setLayoutCount = 1;
7917 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007918
7919 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007920 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007921 ASSERT_VK_SUCCESS(err);
7922
7923 // Create a buffer to update the descriptor with
7924 uint32_t qfi = 0;
7925 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007926 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7927 buffCI.size = 1024;
7928 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7929 buffCI.queueFamilyIndexCount = 1;
7930 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007931
7932 VkBuffer dyub;
7933 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
7934 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007935 // Allocate memory and bind to buffer so we can make it to the appropriate
7936 // error
7937 VkMemoryAllocateInfo mem_alloc = {};
7938 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7939 mem_alloc.pNext = NULL;
7940 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12007941 mem_alloc.memoryTypeIndex = 0;
7942
7943 VkMemoryRequirements memReqs;
7944 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007945 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12007946 if (!pass) {
7947 vkDestroyBuffer(m_device->device(), dyub, NULL);
7948 return;
7949 }
7950
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007951 VkDeviceMemory mem;
7952 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7953 ASSERT_VK_SUCCESS(err);
7954 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
7955 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007956 // Correctly update descriptor to avoid "NOT_UPDATED" error
7957 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007958 buffInfo.buffer = dyub;
7959 buffInfo.offset = 0;
7960 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007961
7962 VkWriteDescriptorSet descriptor_write;
7963 memset(&descriptor_write, 0, sizeof(descriptor_write));
7964 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7965 descriptor_write.dstSet = descriptorSet;
7966 descriptor_write.dstBinding = 0;
7967 descriptor_write.descriptorCount = 1;
7968 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7969 descriptor_write.pBufferInfo = &buffInfo;
7970
7971 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7972
7973 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007974 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7975 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007976 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007977 uint32_t pDynOff[2] = {512, 756};
7978 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7980 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
7981 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7982 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12007983 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007984 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
7986 "offset 0 and range 1024 that "
7987 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07007988 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007989 char const *vsSource = "#version 450\n"
7990 "\n"
7991 "out gl_PerVertex { \n"
7992 " vec4 gl_Position;\n"
7993 "};\n"
7994 "void main(){\n"
7995 " gl_Position = vec4(1);\n"
7996 "}\n";
7997 char const *fsSource = "#version 450\n"
7998 "\n"
7999 "layout(location=0) out vec4 x;\n"
8000 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8001 "void main(){\n"
8002 " x = vec4(bar.y);\n"
8003 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07008004 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8005 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8006 VkPipelineObj pipe(m_device);
8007 pipe.AddShader(&vs);
8008 pipe.AddShader(&fs);
8009 pipe.AddColorAttachment();
8010 pipe.CreateVKPipeline(pipeline_layout, renderPass());
8011
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008012 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008013 // This update should succeed, but offset size of 512 will overstep buffer
8014 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008015 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
8016 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07008017 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008018 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008019
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008020 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06008021 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008022
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008023 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008024 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008025 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8026}
8027
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008028TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
8029 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
8030 "that doesn't have memory bound");
8031 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " used without first calling vkBindBufferMemory.");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008033
8034 ASSERT_NO_FATAL_FAILURE(InitState());
8035 ASSERT_NO_FATAL_FAILURE(InitViewport());
8036 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8037
8038 VkDescriptorPoolSize ds_type_count = {};
8039 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8040 ds_type_count.descriptorCount = 1;
8041
8042 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8043 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8044 ds_pool_ci.pNext = NULL;
8045 ds_pool_ci.maxSets = 1;
8046 ds_pool_ci.poolSizeCount = 1;
8047 ds_pool_ci.pPoolSizes = &ds_type_count;
8048
8049 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008050 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008051 ASSERT_VK_SUCCESS(err);
8052
8053 VkDescriptorSetLayoutBinding dsl_binding = {};
8054 dsl_binding.binding = 0;
8055 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8056 dsl_binding.descriptorCount = 1;
8057 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8058 dsl_binding.pImmutableSamplers = NULL;
8059
8060 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8061 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8062 ds_layout_ci.pNext = NULL;
8063 ds_layout_ci.bindingCount = 1;
8064 ds_layout_ci.pBindings = &dsl_binding;
8065 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008066 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008067 ASSERT_VK_SUCCESS(err);
8068
8069 VkDescriptorSet descriptorSet;
8070 VkDescriptorSetAllocateInfo alloc_info = {};
8071 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8072 alloc_info.descriptorSetCount = 1;
8073 alloc_info.descriptorPool = ds_pool;
8074 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008075 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008076 ASSERT_VK_SUCCESS(err);
8077
8078 // Create a buffer to update the descriptor with
8079 uint32_t qfi = 0;
8080 VkBufferCreateInfo buffCI = {};
8081 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8082 buffCI.size = 1024;
8083 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8084 buffCI.queueFamilyIndexCount = 1;
8085 buffCI.pQueueFamilyIndices = &qfi;
8086
8087 VkBuffer dyub;
8088 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8089 ASSERT_VK_SUCCESS(err);
8090
8091 // Attempt to update descriptor without binding memory to it
8092 VkDescriptorBufferInfo buffInfo = {};
8093 buffInfo.buffer = dyub;
8094 buffInfo.offset = 0;
8095 buffInfo.range = 1024;
8096
8097 VkWriteDescriptorSet descriptor_write;
8098 memset(&descriptor_write, 0, sizeof(descriptor_write));
8099 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8100 descriptor_write.dstSet = descriptorSet;
8101 descriptor_write.dstBinding = 0;
8102 descriptor_write.descriptorCount = 1;
8103 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8104 descriptor_write.pBufferInfo = &buffInfo;
8105
8106 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8107 m_errorMonitor->VerifyFound();
8108
8109 vkDestroyBuffer(m_device->device(), dyub, NULL);
8110 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8111 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8112}
8113
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008114TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008115 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008116 ASSERT_NO_FATAL_FAILURE(InitState());
8117 ASSERT_NO_FATAL_FAILURE(InitViewport());
8118 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8119
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008120 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008121 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008122 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8123 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8124 pipeline_layout_ci.pushConstantRangeCount = 1;
8125 pipeline_layout_ci.pPushConstantRanges = &pc_range;
8126
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008127 //
8128 // Check for invalid push constant ranges in pipeline layouts.
8129 //
8130 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008131 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008132 char const *msg;
8133 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008134
Karl Schultzc81037d2016-05-12 08:11:23 -06008135 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
8136 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
8137 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
8138 "vkCreatePipelineLayout() call has push constants index 0 with "
8139 "size 0."},
8140 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8141 "vkCreatePipelineLayout() call has push constants index 0 with "
8142 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008143 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008144 "vkCreatePipelineLayout() call has push constants index 0 with "
8145 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008146 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06008147 "vkCreatePipelineLayout() call has push constants index 0 with "
8148 "size 0."},
8149 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8150 "vkCreatePipelineLayout() call has push constants index 0 with "
8151 "offset 1. Offset must"},
8152 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
8153 "vkCreatePipelineLayout() call has push constants index 0 "
8154 "with offset "},
8155 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
8156 "vkCreatePipelineLayout() call has push constants "
8157 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008158 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008159 "vkCreatePipelineLayout() call has push constants index 0 "
8160 "with offset "},
8161 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
8162 "vkCreatePipelineLayout() call has push "
8163 "constants index 0 with offset "},
8164 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
8165 "vkCreatePipelineLayout() call has push "
8166 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008167 }};
8168
8169 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06008170 for (const auto &iter : range_tests) {
8171 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8173 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008174 m_errorMonitor->VerifyFound();
8175 if (VK_SUCCESS == err) {
8176 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8177 }
8178 }
8179
8180 // Check for invalid stage flag
8181 pc_range.offset = 0;
8182 pc_range.size = 16;
8183 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008184 m_errorMonitor->SetDesiredFailureMsg(
8185 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8186 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008187 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008188 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008189 if (VK_SUCCESS == err) {
8190 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8191 }
8192
8193 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06008194 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008195 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008196 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008197 char const *msg;
8198 };
8199
Karl Schultzc81037d2016-05-12 08:11:23 -06008200 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008201 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8202 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8203 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8204 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8205 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008206 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008207 {
8208 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8209 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8210 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8211 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8212 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008213 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008214 },
8215 {
8216 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8217 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8218 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8219 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8220 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008221 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008222 },
8223 {
8224 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8225 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8226 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8227 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8228 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008229 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008230 },
8231 {
8232 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8233 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
8234 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
8235 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
8236 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008237 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008238 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008239
Karl Schultzc81037d2016-05-12 08:11:23 -06008240 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008241 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06008242 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
8244 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008245 m_errorMonitor->VerifyFound();
8246 if (VK_SUCCESS == err) {
8247 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8248 }
8249 }
8250
8251 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008252 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8253 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8254 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8255 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
8256 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
8257 ""},
8258 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
8259 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
8260 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
8261 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
8262 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8263 ""}}};
Karl Schultzc81037d2016-05-12 08:11:23 -06008264 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008265 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
8266 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008267 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008268 m_errorMonitor->VerifyNotFound();
8269 if (VK_SUCCESS == err) {
8270 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8271 }
8272 }
8273
8274 //
8275 // CmdPushConstants tests
8276 //
Karl Schultzc81037d2016-05-12 08:11:23 -06008277 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008278
8279 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008280 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
8281 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06008282 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8283 "vkCmdPushConstants() call has push constants with size 1. Size "
8284 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008285 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008286 "vkCmdPushConstants() call has push constants with size 1. Size "
8287 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008288 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008289 "vkCmdPushConstants() call has push constants with offset 1. "
8290 "Offset must be a multiple of 4."},
8291 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8292 "vkCmdPushConstants() call has push constants with offset 1. "
8293 "Offset must be a multiple of 4."},
8294 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8295 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8296 "0x1 not within flag-matching ranges in pipeline layout"},
8297 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
8298 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
8299 "0x1 not within flag-matching ranges in pipeline layout"},
8300 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
8301 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
8302 "0x1 not within flag-matching ranges in pipeline layout"},
8303 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
8304 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
8305 "0x1 not within flag-matching ranges in pipeline layout"},
8306 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
8307 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
8308 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008309 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06008310 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
8311 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008312 }};
8313
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008314 BeginCommandBuffer();
8315
8316 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06008317 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008318 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008319 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008320 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008321 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008322 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008323 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008324 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8326 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008327 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008328 m_errorMonitor->VerifyFound();
8329 }
8330
8331 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008333 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008334 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06008335 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008336
Karl Schultzc81037d2016-05-12 08:11:23 -06008337 // overlapping range tests with cmd
8338 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
8339 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8340 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8341 "0x1 not within flag-matching ranges in pipeline layout"},
8342 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8343 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
8344 "0x1 not within flag-matching ranges in pipeline layout"},
8345 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
8346 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
8347 "0x1 not within flag-matching ranges in pipeline layout"},
8348 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008349 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008350 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008351 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8352 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06008353 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008354 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008355 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008356 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008357 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008358 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8360 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008361 iter.range.size, dummy_values);
8362 m_errorMonitor->VerifyFound();
8363 }
Karl Schultzc81037d2016-05-12 08:11:23 -06008364 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8365
8366 // positive overlapping range tests with cmd
8367 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
8368 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
8369 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
8370 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
8371 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
8372 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008373 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008374 const VkPushConstantRange pc_range4[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008375 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8376 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, {VK_SHADER_STAGE_VERTEX_BIT, 56, 24},
Karl Schultzc81037d2016-05-12 08:11:23 -06008377 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008378 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008379 pipeline_layout_ci.pPushConstantRanges = pc_range4;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008380 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008381 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008382 for (const auto &iter : cmd_overlap_tests_pos) {
8383 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008384 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008385 iter.range.size, dummy_values);
8386 m_errorMonitor->VerifyNotFound();
8387 }
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008388 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008389
8390 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008391}
8392
Karl Schultz6addd812016-02-02 17:17:23 -07008393TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008394 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07008395 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008396
8397 ASSERT_NO_FATAL_FAILURE(InitState());
8398 ASSERT_NO_FATAL_FAILURE(InitViewport());
8399 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8400
Mike Stroyanb8a61002016-06-20 16:00:28 -06008401 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
8402 VkImageTiling tiling;
8403 VkFormatProperties format_properties;
8404 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008405 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008406 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008407 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008408 tiling = VK_IMAGE_TILING_OPTIMAL;
8409 } else {
8410 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
8411 "skipped.\n");
8412 return;
8413 }
8414
Tobin Ehlis559c6382015-11-05 09:52:49 -07008415 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
8416 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008417 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8418 ds_type_count[0].descriptorCount = 10;
8419 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8420 ds_type_count[1].descriptorCount = 2;
8421 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8422 ds_type_count[2].descriptorCount = 2;
8423 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8424 ds_type_count[3].descriptorCount = 5;
8425 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
8426 // type
8427 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8428 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
8429 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008430
8431 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008432 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8433 ds_pool_ci.pNext = NULL;
8434 ds_pool_ci.maxSets = 5;
8435 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
8436 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008437
8438 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008439 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008440 ASSERT_VK_SUCCESS(err);
8441
8442 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
8443 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008444 dsl_binding[0].binding = 0;
8445 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8446 dsl_binding[0].descriptorCount = 5;
8447 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8448 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008449
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008450 // Create layout identical to set0 layout but w/ different stageFlags
8451 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008452 dsl_fs_stage_only.binding = 0;
8453 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8454 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008455 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
8456 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07008457 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008458 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008459 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8460 ds_layout_ci.pNext = NULL;
8461 ds_layout_ci.bindingCount = 1;
8462 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008463 static const uint32_t NUM_LAYOUTS = 4;
8464 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008465 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008466 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
8467 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008468 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008469 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008470 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008471 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008472 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008473 dsl_binding[0].binding = 0;
8474 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008475 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008476 dsl_binding[1].binding = 1;
8477 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8478 dsl_binding[1].descriptorCount = 2;
8479 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8480 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008481 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008482 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008483 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008484 ASSERT_VK_SUCCESS(err);
8485 dsl_binding[0].binding = 0;
8486 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008487 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008488 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008489 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008490 ASSERT_VK_SUCCESS(err);
8491 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008492 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008493 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008494 ASSERT_VK_SUCCESS(err);
8495
8496 static const uint32_t NUM_SETS = 4;
8497 VkDescriptorSet descriptorSet[NUM_SETS] = {};
8498 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008499 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008500 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008501 alloc_info.descriptorPool = ds_pool;
8502 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008503 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008504 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008505 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008506 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008507 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008508 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008509 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008510
8511 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008512 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8513 pipeline_layout_ci.pNext = NULL;
8514 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
8515 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008516
8517 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008518 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008519 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008520 // Create pipelineLayout with only one setLayout
8521 pipeline_layout_ci.setLayoutCount = 1;
8522 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008523 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008524 ASSERT_VK_SUCCESS(err);
8525 // Create pipelineLayout with 2 descriptor setLayout at index 0
8526 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
8527 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008528 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008529 ASSERT_VK_SUCCESS(err);
8530 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
8531 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
8532 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008533 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008534 ASSERT_VK_SUCCESS(err);
8535 // Create pipelineLayout with UB type, but stageFlags for FS only
8536 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
8537 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008538 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008539 ASSERT_VK_SUCCESS(err);
8540 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
8541 VkDescriptorSetLayout pl_bad_s0[2] = {};
8542 pl_bad_s0[0] = ds_layout_fs_only;
8543 pl_bad_s0[1] = ds_layout[1];
8544 pipeline_layout_ci.setLayoutCount = 2;
8545 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
8546 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008547 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008548 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008549
8550 // Create a buffer to update the descriptor with
8551 uint32_t qfi = 0;
8552 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008553 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8554 buffCI.size = 1024;
8555 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8556 buffCI.queueFamilyIndexCount = 1;
8557 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008558
8559 VkBuffer dyub;
8560 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8561 ASSERT_VK_SUCCESS(err);
8562 // Correctly update descriptor to avoid "NOT_UPDATED" error
8563 static const uint32_t NUM_BUFFS = 5;
8564 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008565 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008566 buffInfo[i].buffer = dyub;
8567 buffInfo[i].offset = 0;
8568 buffInfo[i].range = 1024;
8569 }
Karl Schultz6addd812016-02-02 17:17:23 -07008570 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07008571 const int32_t tex_width = 32;
8572 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008573 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008574 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8575 image_create_info.pNext = NULL;
8576 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8577 image_create_info.format = tex_format;
8578 image_create_info.extent.width = tex_width;
8579 image_create_info.extent.height = tex_height;
8580 image_create_info.extent.depth = 1;
8581 image_create_info.mipLevels = 1;
8582 image_create_info.arrayLayers = 1;
8583 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06008584 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008585 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07008586 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008587 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
8588 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008589
Karl Schultz6addd812016-02-02 17:17:23 -07008590 VkMemoryRequirements memReqs;
8591 VkDeviceMemory imageMem;
8592 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008593 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008594 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8595 memAlloc.pNext = NULL;
8596 memAlloc.allocationSize = 0;
8597 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008598 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
8599 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008600 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008601 ASSERT_TRUE(pass);
8602 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
8603 ASSERT_VK_SUCCESS(err);
8604 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
8605 ASSERT_VK_SUCCESS(err);
8606
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008607 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008608 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8609 image_view_create_info.image = image;
8610 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
8611 image_view_create_info.format = tex_format;
8612 image_view_create_info.subresourceRange.layerCount = 1;
8613 image_view_create_info.subresourceRange.baseMipLevel = 0;
8614 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008615 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008616
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008617 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008618 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008619 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008620 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008621 imageInfo[0].imageView = view;
8622 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8623 imageInfo[1].imageView = view;
8624 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008625 imageInfo[2].imageView = view;
8626 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8627 imageInfo[3].imageView = view;
8628 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008629
8630 static const uint32_t NUM_SET_UPDATES = 3;
8631 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
8632 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8633 descriptor_write[0].dstSet = descriptorSet[0];
8634 descriptor_write[0].dstBinding = 0;
8635 descriptor_write[0].descriptorCount = 5;
8636 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8637 descriptor_write[0].pBufferInfo = buffInfo;
8638 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8639 descriptor_write[1].dstSet = descriptorSet[1];
8640 descriptor_write[1].dstBinding = 0;
8641 descriptor_write[1].descriptorCount = 2;
8642 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8643 descriptor_write[1].pImageInfo = imageInfo;
8644 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8645 descriptor_write[2].dstSet = descriptorSet[1];
8646 descriptor_write[2].dstBinding = 1;
8647 descriptor_write[2].descriptorCount = 2;
8648 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008649 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008650
8651 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008652
Tobin Ehlis88452832015-12-03 09:40:56 -07008653 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008654 char const *vsSource = "#version 450\n"
8655 "\n"
8656 "out gl_PerVertex {\n"
8657 " vec4 gl_Position;\n"
8658 "};\n"
8659 "void main(){\n"
8660 " gl_Position = vec4(1);\n"
8661 "}\n";
8662 char const *fsSource = "#version 450\n"
8663 "\n"
8664 "layout(location=0) out vec4 x;\n"
8665 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8666 "void main(){\n"
8667 " x = vec4(bar.y);\n"
8668 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07008669 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8670 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008671 VkPipelineObj pipe(m_device);
8672 pipe.AddShader(&vs);
8673 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07008674 pipe.AddColorAttachment();
8675 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07008676
8677 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07008678
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008679 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008680 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
8681 // of PSO
8682 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
8683 // cmd_pipeline.c
8684 // due to the fact that cmd_alloc_dset_data() has not been called in
8685 // cmd_bind_graphics_pipeline()
8686 // TODO : Want to cause various binding incompatibility issues here to test
8687 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07008688 // First cause various verify_layout_compatibility() fails
8689 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008690 // verify_set_layout_compatibility fail cases:
8691 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
8693 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
8694 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008695 m_errorMonitor->VerifyFound();
8696
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008697 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
8699 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
8700 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008701 m_errorMonitor->VerifyFound();
8702
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008703 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008704 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
8705 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
8707 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
8708 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008709 m_errorMonitor->VerifyFound();
8710
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008711 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
8712 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
8714 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
8715 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008716 m_errorMonitor->VerifyFound();
8717
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008718 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
8719 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8721 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
8722 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8723 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008724 m_errorMonitor->VerifyFound();
8725
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008726 // Cause INFO messages due to disturbing previously bound Sets
8727 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008728 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8729 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008730 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
8732 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8733 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008734 m_errorMonitor->VerifyFound();
8735
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008736 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8737 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008738 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
8740 "any subsequent sets were disturbed ");
8741 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8742 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008743 m_errorMonitor->VerifyFound();
8744
Tobin Ehlis10fad692016-07-07 12:00:36 -06008745 // Now that we're done actively using the pipelineLayout that gfx pipeline
8746 // was created with, we should be able to delete it. Do that now to verify
8747 // that validation obeys pipelineLayout lifetime
8748 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
8749
Tobin Ehlis88452832015-12-03 09:40:56 -07008750 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07008751 // 1. Error due to not binding required set (we actually use same code as
8752 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008753 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8754 &descriptorSet[0], 0, NULL);
8755 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8756 &descriptorSet[1], 0, NULL);
8757 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 -07008758 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008759 m_errorMonitor->VerifyFound();
8760
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008761 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008762 // 2. Error due to bound set not being compatible with PSO's
8763 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008764 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8765 &descriptorSet[0], 0, NULL);
8766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07008767 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008768 m_errorMonitor->VerifyFound();
8769
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008770 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07008771 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008772 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
8773 }
8774 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06008775 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
8776 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008777 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008778 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8779 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008780 vkFreeMemory(m_device->device(), imageMem, NULL);
8781 vkDestroyImage(m_device->device(), image, NULL);
8782 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008783}
Tobin Ehlis559c6382015-11-05 09:52:49 -07008784
Karl Schultz6addd812016-02-02 17:17:23 -07008785TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008786
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8788 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008789
8790 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008791 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008792 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008793 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008794
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008795 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008796}
8797
Karl Schultz6addd812016-02-02 17:17:23 -07008798TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
8799 VkResult err;
8800 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008801
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008803
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008804 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008805
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008806 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008807 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008808 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008809 cmd.commandPool = m_commandPool;
8810 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008811 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06008812
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008813 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06008814 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008815
8816 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008817 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008818 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008819 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008820 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008821 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 -07008822 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008823
8824 // The error should be caught by validation of the BeginCommandBuffer call
8825 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
8826
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008827 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008828 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008829}
8830
Karl Schultz6addd812016-02-02 17:17:23 -07008831TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008832 // Cause error due to Begin while recording CB
8833 // Then cause 2 errors for attempting to reset CB w/o having
8834 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
8835 // which CBs were allocated. Note that this bit is off by default.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008837
8838 ASSERT_NO_FATAL_FAILURE(InitState());
8839
8840 // Calls AllocateCommandBuffers
8841 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
8842
Karl Schultz6addd812016-02-02 17:17:23 -07008843 // Force the failure by setting the Renderpass and Framebuffer fields with
8844 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008845 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008846 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008847 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8848 cmd_buf_info.pNext = NULL;
8849 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008850 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008851
8852 // Begin CB to transition to recording state
8853 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
8854 // Can't re-begin. This should trigger error
8855 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008856 m_errorMonitor->VerifyFound();
8857
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008859 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
8860 // Reset attempt will trigger error due to incorrect CommandPool state
8861 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008862 m_errorMonitor->VerifyFound();
8863
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008865 // Transition CB to RECORDED state
8866 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
8867 // Now attempting to Begin will implicitly reset, which triggers error
8868 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008869 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008870}
8871
Karl Schultz6addd812016-02-02 17:17:23 -07008872TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008873 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07008874 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008875
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vtx Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008877
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008878 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008880
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008881 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008882 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8883 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008884
8885 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008886 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8887 ds_pool_ci.pNext = NULL;
8888 ds_pool_ci.maxSets = 1;
8889 ds_pool_ci.poolSizeCount = 1;
8890 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008891
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008892 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008893 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008894 ASSERT_VK_SUCCESS(err);
8895
Tony Barboureb254902015-07-15 12:50:33 -06008896 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008897 dsl_binding.binding = 0;
8898 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8899 dsl_binding.descriptorCount = 1;
8900 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8901 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008902
Tony Barboureb254902015-07-15 12:50:33 -06008903 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008904 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8905 ds_layout_ci.pNext = NULL;
8906 ds_layout_ci.bindingCount = 1;
8907 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008908
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008909 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008910 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008911 ASSERT_VK_SUCCESS(err);
8912
8913 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008914 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008915 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008916 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008917 alloc_info.descriptorPool = ds_pool;
8918 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008919 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008920 ASSERT_VK_SUCCESS(err);
8921
Tony Barboureb254902015-07-15 12:50:33 -06008922 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008923 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8924 pipeline_layout_ci.setLayoutCount = 1;
8925 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008926
8927 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008928 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008929 ASSERT_VK_SUCCESS(err);
8930
Tobin Ehlise68360f2015-10-01 11:15:13 -06008931 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008932 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06008933
8934 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008935 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8936 vp_state_ci.scissorCount = 1;
8937 vp_state_ci.pScissors = &sc;
8938 vp_state_ci.viewportCount = 1;
8939 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008940
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008941 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8942 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8943 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8944 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8945 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8946 rs_state_ci.depthClampEnable = VK_FALSE;
8947 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8948 rs_state_ci.depthBiasEnable = VK_FALSE;
8949
Tony Barboureb254902015-07-15 12:50:33 -06008950 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008951 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8952 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008953 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008954 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8955 gp_ci.layout = pipeline_layout;
8956 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06008957
8958 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008959 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8960 pc_ci.initialDataSize = 0;
8961 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008962
8963 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06008964 VkPipelineCache pipelineCache;
8965
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008966 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06008967 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008968 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06008969
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008970 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008971
Chia-I Wuf7458c52015-10-26 21:10:41 +08008972 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8973 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8974 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8975 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008976}
Tobin Ehlis912df022015-09-17 08:46:18 -06008977/*// TODO : This test should be good, but needs Tess support in compiler to run
8978TEST_F(VkLayerTest, InvalidPatchControlPoints)
8979{
8980 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06008981 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008982
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008984 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
8985primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008986
Tobin Ehlis912df022015-09-17 08:46:18 -06008987 ASSERT_NO_FATAL_FAILURE(InitState());
8988 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06008989
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008990 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06008991 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008992 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008993
8994 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8995 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8996 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008997 ds_pool_ci.poolSizeCount = 1;
8998 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06008999
9000 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009001 err = vkCreateDescriptorPool(m_device->device(),
9002VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06009003 ASSERT_VK_SUCCESS(err);
9004
9005 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009006 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06009007 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009008 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06009009 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9010 dsl_binding.pImmutableSamplers = NULL;
9011
9012 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009013 ds_layout_ci.sType =
9014VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06009015 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009016 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009017 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06009018
9019 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009020 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9021&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06009022 ASSERT_VK_SUCCESS(err);
9023
9024 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009025 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
9026VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06009027 ASSERT_VK_SUCCESS(err);
9028
9029 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009030 pipeline_layout_ci.sType =
9031VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06009032 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009033 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06009034 pipeline_layout_ci.pSetLayouts = &ds_layout;
9035
9036 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009037 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9038&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06009039 ASSERT_VK_SUCCESS(err);
9040
9041 VkPipelineShaderStageCreateInfo shaderStages[3];
9042 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
9043
Karl Schultz6addd812016-02-02 17:17:23 -07009044 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
9045this);
Tobin Ehlis912df022015-09-17 08:46:18 -06009046 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07009047 VkShaderObj
9048tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
9049this);
9050 VkShaderObj
9051te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
9052this);
Tobin Ehlis912df022015-09-17 08:46:18 -06009053
Karl Schultz6addd812016-02-02 17:17:23 -07009054 shaderStages[0].sType =
9055VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009056 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009057 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07009058 shaderStages[1].sType =
9059VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009060 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009061 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07009062 shaderStages[2].sType =
9063VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009064 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009065 shaderStages[2].shader = te.handle();
9066
9067 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009068 iaCI.sType =
9069VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08009070 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06009071
9072 VkPipelineTessellationStateCreateInfo tsCI = {};
9073 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
9074 tsCI.patchControlPoints = 0; // This will cause an error
9075
9076 VkGraphicsPipelineCreateInfo gp_ci = {};
9077 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9078 gp_ci.pNext = NULL;
9079 gp_ci.stageCount = 3;
9080 gp_ci.pStages = shaderStages;
9081 gp_ci.pVertexInputState = NULL;
9082 gp_ci.pInputAssemblyState = &iaCI;
9083 gp_ci.pTessellationState = &tsCI;
9084 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009085 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06009086 gp_ci.pMultisampleState = NULL;
9087 gp_ci.pDepthStencilState = NULL;
9088 gp_ci.pColorBlendState = NULL;
9089 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9090 gp_ci.layout = pipeline_layout;
9091 gp_ci.renderPass = renderPass();
9092
9093 VkPipelineCacheCreateInfo pc_ci = {};
9094 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9095 pc_ci.pNext = NULL;
9096 pc_ci.initialSize = 0;
9097 pc_ci.initialData = 0;
9098 pc_ci.maxSize = 0;
9099
9100 VkPipeline pipeline;
9101 VkPipelineCache pipelineCache;
9102
Karl Schultz6addd812016-02-02 17:17:23 -07009103 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
9104&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06009105 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009106 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
9107&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06009108
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009109 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009110
Chia-I Wuf7458c52015-10-26 21:10:41 +08009111 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9112 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9113 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9114 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06009115}
9116*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06009117// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07009118TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07009119 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009120
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9122 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009123
Tobin Ehlise68360f2015-10-01 11:15:13 -06009124 ASSERT_NO_FATAL_FAILURE(InitState());
9125 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009126
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009127 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009128 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9129 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009130
9131 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009132 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9133 ds_pool_ci.maxSets = 1;
9134 ds_pool_ci.poolSizeCount = 1;
9135 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009136
9137 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009138 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009139 ASSERT_VK_SUCCESS(err);
9140
9141 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009142 dsl_binding.binding = 0;
9143 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9144 dsl_binding.descriptorCount = 1;
9145 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009146
9147 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009148 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9149 ds_layout_ci.bindingCount = 1;
9150 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009151
9152 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009153 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009154 ASSERT_VK_SUCCESS(err);
9155
9156 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009157 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009158 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009159 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009160 alloc_info.descriptorPool = ds_pool;
9161 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009162 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009163 ASSERT_VK_SUCCESS(err);
9164
9165 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009166 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9167 pipeline_layout_ci.setLayoutCount = 1;
9168 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009169
9170 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009171 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009172 ASSERT_VK_SUCCESS(err);
9173
9174 VkViewport vp = {}; // Just need dummy vp to point to
9175
9176 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009177 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9178 vp_state_ci.scissorCount = 0;
9179 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
9180 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009181
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009182 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9183 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9184 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9185 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9186 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9187 rs_state_ci.depthClampEnable = VK_FALSE;
9188 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9189 rs_state_ci.depthBiasEnable = VK_FALSE;
9190
Cody Northropeb3a6c12015-10-05 14:44:45 -06009191 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009192 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009193
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009194 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9195 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9196 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009197 shaderStages[0] = vs.GetStageCreateInfo();
9198 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009199
9200 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009201 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9202 gp_ci.stageCount = 2;
9203 gp_ci.pStages = shaderStages;
9204 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009205 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009206 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9207 gp_ci.layout = pipeline_layout;
9208 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009209
9210 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009211 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009212
9213 VkPipeline pipeline;
9214 VkPipelineCache pipelineCache;
9215
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009216 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009217 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009218 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009219
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009220 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009221
Chia-I Wuf7458c52015-10-26 21:10:41 +08009222 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9223 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9224 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9225 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009226}
Karl Schultz6addd812016-02-02 17:17:23 -07009227// Don't set viewport state in PSO. This is an error b/c we always need this
9228// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06009229// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07009230TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06009231 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07009232 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009233
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009235
Tobin Ehlise68360f2015-10-01 11:15:13 -06009236 ASSERT_NO_FATAL_FAILURE(InitState());
9237 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009238
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009239 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009240 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9241 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009242
9243 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009244 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9245 ds_pool_ci.maxSets = 1;
9246 ds_pool_ci.poolSizeCount = 1;
9247 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009248
9249 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009250 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009251 ASSERT_VK_SUCCESS(err);
9252
9253 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009254 dsl_binding.binding = 0;
9255 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9256 dsl_binding.descriptorCount = 1;
9257 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009258
9259 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009260 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9261 ds_layout_ci.bindingCount = 1;
9262 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009263
9264 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009265 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009266 ASSERT_VK_SUCCESS(err);
9267
9268 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009269 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009270 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009271 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009272 alloc_info.descriptorPool = ds_pool;
9273 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009274 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009275 ASSERT_VK_SUCCESS(err);
9276
9277 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009278 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9279 pipeline_layout_ci.setLayoutCount = 1;
9280 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009281
9282 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009283 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009284 ASSERT_VK_SUCCESS(err);
9285
9286 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9287 // Set scissor as dynamic to avoid second error
9288 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009289 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9290 dyn_state_ci.dynamicStateCount = 1;
9291 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009292
Cody Northropeb3a6c12015-10-05 14:44:45 -06009293 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009294 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009295
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009296 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9297 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9298 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009299 shaderStages[0] = vs.GetStageCreateInfo();
9300 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009301
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009302 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9303 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9304 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9305 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9306 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9307 rs_state_ci.depthClampEnable = VK_FALSE;
9308 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9309 rs_state_ci.depthBiasEnable = VK_FALSE;
9310
Tobin Ehlise68360f2015-10-01 11:15:13 -06009311 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009312 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9313 gp_ci.stageCount = 2;
9314 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009315 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009316 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
9317 // should cause validation error
9318 gp_ci.pDynamicState = &dyn_state_ci;
9319 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9320 gp_ci.layout = pipeline_layout;
9321 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009322
9323 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009324 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009325
9326 VkPipeline pipeline;
9327 VkPipelineCache pipelineCache;
9328
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009329 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009330 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009331 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009332
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009333 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009334
Chia-I Wuf7458c52015-10-26 21:10:41 +08009335 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9336 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9337 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9338 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009339}
9340// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07009341// Then run second test where dynamic scissor count doesn't match PSO scissor
9342// count
9343TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
9344 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009345
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9347 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009348
Tobin Ehlise68360f2015-10-01 11:15:13 -06009349 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009350
9351 if (!m_device->phy().features().multiViewport) {
9352 printf("Device does not support multiple viewports/scissors; skipped.\n");
9353 return;
9354 }
9355
Tobin Ehlise68360f2015-10-01 11:15:13 -06009356 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009357
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009358 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009359 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9360 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009361
9362 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009363 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9364 ds_pool_ci.maxSets = 1;
9365 ds_pool_ci.poolSizeCount = 1;
9366 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009367
9368 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009369 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009370 ASSERT_VK_SUCCESS(err);
9371
9372 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009373 dsl_binding.binding = 0;
9374 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9375 dsl_binding.descriptorCount = 1;
9376 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009377
9378 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009379 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9380 ds_layout_ci.bindingCount = 1;
9381 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009382
9383 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009384 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009385 ASSERT_VK_SUCCESS(err);
9386
9387 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009388 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009389 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009390 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009391 alloc_info.descriptorPool = ds_pool;
9392 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009393 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009394 ASSERT_VK_SUCCESS(err);
9395
9396 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009397 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9398 pipeline_layout_ci.setLayoutCount = 1;
9399 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009400
9401 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009402 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009403 ASSERT_VK_SUCCESS(err);
9404
9405 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009406 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9407 vp_state_ci.viewportCount = 1;
9408 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
9409 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009410 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06009411
9412 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9413 // Set scissor as dynamic to avoid that error
9414 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009415 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9416 dyn_state_ci.dynamicStateCount = 1;
9417 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009418
Cody Northropeb3a6c12015-10-05 14:44:45 -06009419 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009420 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009421
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009422 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9423 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9424 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009425 shaderStages[0] = vs.GetStageCreateInfo();
9426 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009427
Cody Northropf6622dc2015-10-06 10:33:21 -06009428 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9429 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9430 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009431 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009432 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009433 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009434 vi_ci.pVertexAttributeDescriptions = nullptr;
9435
9436 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9437 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9438 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9439
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009440 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009441 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06009442 rs_ci.pNext = nullptr;
9443
Mark Youngc89c6312016-03-31 16:03:20 -06009444 VkPipelineColorBlendAttachmentState att = {};
9445 att.blendEnable = VK_FALSE;
9446 att.colorWriteMask = 0xf;
9447
Cody Northropf6622dc2015-10-06 10:33:21 -06009448 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9449 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9450 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009451 cb_ci.attachmentCount = 1;
9452 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06009453
Tobin Ehlise68360f2015-10-01 11:15:13 -06009454 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009455 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9456 gp_ci.stageCount = 2;
9457 gp_ci.pStages = shaderStages;
9458 gp_ci.pVertexInputState = &vi_ci;
9459 gp_ci.pInputAssemblyState = &ia_ci;
9460 gp_ci.pViewportState = &vp_state_ci;
9461 gp_ci.pRasterizationState = &rs_ci;
9462 gp_ci.pColorBlendState = &cb_ci;
9463 gp_ci.pDynamicState = &dyn_state_ci;
9464 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9465 gp_ci.layout = pipeline_layout;
9466 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009467
9468 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009469 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009470
9471 VkPipeline pipeline;
9472 VkPipelineCache pipelineCache;
9473
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009474 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009475 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009476 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009477
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009478 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009479
Tobin Ehlisd332f282015-10-02 11:00:56 -06009480 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07009481 // First need to successfully create the PSO from above by setting
9482 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by PSO, ");
Karl Schultz6addd812016-02-02 17:17:23 -07009484
9485 VkViewport vp = {}; // Just need dummy vp to point to
9486 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009487 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009488 ASSERT_VK_SUCCESS(err);
9489 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009490 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009491 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07009492 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009493 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07009494 Draw(1, 0, 0, 0);
9495
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009496 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009497
9498 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9499 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9500 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9501 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009502 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07009503}
9504// Create PSO w/o non-zero scissorCount but no scissor data
9505// Then run second test where dynamic viewportCount doesn't match PSO
9506// viewportCount
9507TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
9508 VkResult err;
9509
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009510 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 -07009511
9512 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009513
9514 if (!m_device->phy().features().multiViewport) {
9515 printf("Device does not support multiple viewports/scissors; skipped.\n");
9516 return;
9517 }
9518
Karl Schultz6addd812016-02-02 17:17:23 -07009519 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9520
9521 VkDescriptorPoolSize ds_type_count = {};
9522 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9523 ds_type_count.descriptorCount = 1;
9524
9525 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9526 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9527 ds_pool_ci.maxSets = 1;
9528 ds_pool_ci.poolSizeCount = 1;
9529 ds_pool_ci.pPoolSizes = &ds_type_count;
9530
9531 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009532 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07009533 ASSERT_VK_SUCCESS(err);
9534
9535 VkDescriptorSetLayoutBinding dsl_binding = {};
9536 dsl_binding.binding = 0;
9537 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9538 dsl_binding.descriptorCount = 1;
9539 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9540
9541 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9542 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9543 ds_layout_ci.bindingCount = 1;
9544 ds_layout_ci.pBindings = &dsl_binding;
9545
9546 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009547 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009548 ASSERT_VK_SUCCESS(err);
9549
9550 VkDescriptorSet descriptorSet;
9551 VkDescriptorSetAllocateInfo alloc_info = {};
9552 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9553 alloc_info.descriptorSetCount = 1;
9554 alloc_info.descriptorPool = ds_pool;
9555 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009556 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07009557 ASSERT_VK_SUCCESS(err);
9558
9559 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9560 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9561 pipeline_layout_ci.setLayoutCount = 1;
9562 pipeline_layout_ci.pSetLayouts = &ds_layout;
9563
9564 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009565 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009566 ASSERT_VK_SUCCESS(err);
9567
9568 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9569 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9570 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009571 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009572 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009573 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009574
9575 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
9576 // Set scissor as dynamic to avoid that error
9577 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9578 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9579 dyn_state_ci.dynamicStateCount = 1;
9580 dyn_state_ci.pDynamicStates = &vp_state;
9581
9582 VkPipelineShaderStageCreateInfo shaderStages[2];
9583 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9584
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009585 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9586 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9587 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07009588 shaderStages[0] = vs.GetStageCreateInfo();
9589 shaderStages[1] = fs.GetStageCreateInfo();
9590
9591 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9592 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9593 vi_ci.pNext = nullptr;
9594 vi_ci.vertexBindingDescriptionCount = 0;
9595 vi_ci.pVertexBindingDescriptions = nullptr;
9596 vi_ci.vertexAttributeDescriptionCount = 0;
9597 vi_ci.pVertexAttributeDescriptions = nullptr;
9598
9599 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9600 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9601 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9602
9603 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9604 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9605 rs_ci.pNext = nullptr;
9606
Mark Youngc89c6312016-03-31 16:03:20 -06009607 VkPipelineColorBlendAttachmentState att = {};
9608 att.blendEnable = VK_FALSE;
9609 att.colorWriteMask = 0xf;
9610
Karl Schultz6addd812016-02-02 17:17:23 -07009611 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9612 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9613 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009614 cb_ci.attachmentCount = 1;
9615 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07009616
9617 VkGraphicsPipelineCreateInfo gp_ci = {};
9618 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9619 gp_ci.stageCount = 2;
9620 gp_ci.pStages = shaderStages;
9621 gp_ci.pVertexInputState = &vi_ci;
9622 gp_ci.pInputAssemblyState = &ia_ci;
9623 gp_ci.pViewportState = &vp_state_ci;
9624 gp_ci.pRasterizationState = &rs_ci;
9625 gp_ci.pColorBlendState = &cb_ci;
9626 gp_ci.pDynamicState = &dyn_state_ci;
9627 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9628 gp_ci.layout = pipeline_layout;
9629 gp_ci.renderPass = renderPass();
9630
9631 VkPipelineCacheCreateInfo pc_ci = {};
9632 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9633
9634 VkPipeline pipeline;
9635 VkPipelineCache pipelineCache;
9636
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009637 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07009638 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009639 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009640
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009641 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009642
9643 // Now hit second fail case where we set scissor w/ different count than PSO
9644 // First need to successfully create the PSO from above by setting
9645 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by PSO, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009647
Tobin Ehlisd332f282015-10-02 11:00:56 -06009648 VkRect2D sc = {}; // Just need dummy vp to point to
9649 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009650 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009651 ASSERT_VK_SUCCESS(err);
9652 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009653 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009654 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06009655 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009656 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009657 Draw(1, 0, 0, 0);
9658
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009659 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009660
Chia-I Wuf7458c52015-10-26 21:10:41 +08009661 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9662 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9663 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9664 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009665 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009666}
9667
Mark Young7394fdd2016-03-31 14:56:43 -06009668TEST_F(VkLayerTest, PSOLineWidthInvalid) {
9669 VkResult err;
9670
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009672
9673 ASSERT_NO_FATAL_FAILURE(InitState());
9674 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9675
9676 VkDescriptorPoolSize ds_type_count = {};
9677 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9678 ds_type_count.descriptorCount = 1;
9679
9680 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9681 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9682 ds_pool_ci.maxSets = 1;
9683 ds_pool_ci.poolSizeCount = 1;
9684 ds_pool_ci.pPoolSizes = &ds_type_count;
9685
9686 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009687 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06009688 ASSERT_VK_SUCCESS(err);
9689
9690 VkDescriptorSetLayoutBinding dsl_binding = {};
9691 dsl_binding.binding = 0;
9692 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9693 dsl_binding.descriptorCount = 1;
9694 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9695
9696 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9697 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9698 ds_layout_ci.bindingCount = 1;
9699 ds_layout_ci.pBindings = &dsl_binding;
9700
9701 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009702 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009703 ASSERT_VK_SUCCESS(err);
9704
9705 VkDescriptorSet descriptorSet;
9706 VkDescriptorSetAllocateInfo alloc_info = {};
9707 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9708 alloc_info.descriptorSetCount = 1;
9709 alloc_info.descriptorPool = ds_pool;
9710 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009711 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06009712 ASSERT_VK_SUCCESS(err);
9713
9714 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9715 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9716 pipeline_layout_ci.setLayoutCount = 1;
9717 pipeline_layout_ci.pSetLayouts = &ds_layout;
9718
9719 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009720 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009721 ASSERT_VK_SUCCESS(err);
9722
9723 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9724 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9725 vp_state_ci.scissorCount = 1;
9726 vp_state_ci.pScissors = NULL;
9727 vp_state_ci.viewportCount = 1;
9728 vp_state_ci.pViewports = NULL;
9729
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009730 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06009731 // Set scissor as dynamic to avoid that error
9732 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9733 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9734 dyn_state_ci.dynamicStateCount = 2;
9735 dyn_state_ci.pDynamicStates = dynamic_states;
9736
9737 VkPipelineShaderStageCreateInfo shaderStages[2];
9738 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9739
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009740 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9741 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06009742 this); // TODO - We shouldn't need a fragment shader
9743 // but add it to be able to run on more devices
9744 shaderStages[0] = vs.GetStageCreateInfo();
9745 shaderStages[1] = fs.GetStageCreateInfo();
9746
9747 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9748 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9749 vi_ci.pNext = nullptr;
9750 vi_ci.vertexBindingDescriptionCount = 0;
9751 vi_ci.pVertexBindingDescriptions = nullptr;
9752 vi_ci.vertexAttributeDescriptionCount = 0;
9753 vi_ci.pVertexAttributeDescriptions = nullptr;
9754
9755 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9756 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9757 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9758
9759 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9760 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9761 rs_ci.pNext = nullptr;
9762
Mark Young47107952016-05-02 15:59:55 -06009763 // Check too low (line width of -1.0f).
9764 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06009765
9766 VkPipelineColorBlendAttachmentState att = {};
9767 att.blendEnable = VK_FALSE;
9768 att.colorWriteMask = 0xf;
9769
9770 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9771 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9772 cb_ci.pNext = nullptr;
9773 cb_ci.attachmentCount = 1;
9774 cb_ci.pAttachments = &att;
9775
9776 VkGraphicsPipelineCreateInfo gp_ci = {};
9777 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9778 gp_ci.stageCount = 2;
9779 gp_ci.pStages = shaderStages;
9780 gp_ci.pVertexInputState = &vi_ci;
9781 gp_ci.pInputAssemblyState = &ia_ci;
9782 gp_ci.pViewportState = &vp_state_ci;
9783 gp_ci.pRasterizationState = &rs_ci;
9784 gp_ci.pColorBlendState = &cb_ci;
9785 gp_ci.pDynamicState = &dyn_state_ci;
9786 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9787 gp_ci.layout = pipeline_layout;
9788 gp_ci.renderPass = renderPass();
9789
9790 VkPipelineCacheCreateInfo pc_ci = {};
9791 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9792
9793 VkPipeline pipeline;
9794 VkPipelineCache pipelineCache;
9795
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009796 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009797 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009798 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009799
9800 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009801 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009802
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009804
9805 // Check too high (line width of 65536.0f).
9806 rs_ci.lineWidth = 65536.0f;
9807
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009808 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009809 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009810 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009811
9812 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009813 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009814
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009816
9817 dyn_state_ci.dynamicStateCount = 3;
9818
9819 rs_ci.lineWidth = 1.0f;
9820
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009821 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009822 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009823 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009824 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009825 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009826
9827 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06009828 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06009829 m_errorMonitor->VerifyFound();
9830
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009832
9833 // Check too high with dynamic setting.
9834 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
9835 m_errorMonitor->VerifyFound();
9836 EndCommandBuffer();
9837
9838 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9839 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9840 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9841 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009842 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009843}
9844
Karl Schultz6addd812016-02-02 17:17:23 -07009845TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009846 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9848 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009849
9850 ASSERT_NO_FATAL_FAILURE(InitState());
9851 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009852
Tony Barbourfe3351b2015-07-28 10:17:20 -06009853 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009854 // Don't care about RenderPass handle b/c error should be flagged before
9855 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009856 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009857
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009858 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009859}
9860
Karl Schultz6addd812016-02-02 17:17:23 -07009861TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009862 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9864 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009865
9866 ASSERT_NO_FATAL_FAILURE(InitState());
9867 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009868
Tony Barbourfe3351b2015-07-28 10:17:20 -06009869 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009870 // Just create a dummy Renderpass that's non-NULL so we can get to the
9871 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009872 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009873
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009874 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009875}
9876
Chris Forbes2eeabe32016-06-21 20:52:34 +12009877TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
9878 m_errorMonitor->ExpectSuccess();
9879
9880 ASSERT_NO_FATAL_FAILURE(InitState());
9881 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9882
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009883 BeginCommandBuffer(); // framework implicitly begins the renderpass.
Chris Forbes2eeabe32016-06-21 20:52:34 +12009884 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit.
9885
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009886 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009887 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9888 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009889 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009890 m_errorMonitor->VerifyNotFound();
9891 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9892 m_errorMonitor->VerifyNotFound();
9893
9894 m_commandBuffer->EndCommandBuffer();
9895 m_errorMonitor->VerifyNotFound();
9896}
9897
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009898TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
9899 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
9900 "the number of renderPass attachments that use loadOp"
9901 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
9902
9903 ASSERT_NO_FATAL_FAILURE(InitState());
9904 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9905
9906 // Create a renderPass with a single attachment that uses loadOp CLEAR
9907 VkAttachmentReference attach = {};
9908 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9909 VkSubpassDescription subpass = {};
9910 subpass.inputAttachmentCount = 1;
9911 subpass.pInputAttachments = &attach;
9912 VkRenderPassCreateInfo rpci = {};
9913 rpci.subpassCount = 1;
9914 rpci.pSubpasses = &subpass;
9915 rpci.attachmentCount = 1;
9916 VkAttachmentDescription attach_desc = {};
9917 attach_desc.format = VK_FORMAT_UNDEFINED;
9918 // Set loadOp to CLEAR
9919 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9920 rpci.pAttachments = &attach_desc;
9921 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9922 VkRenderPass rp;
9923 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9924
9925 VkCommandBufferInheritanceInfo hinfo = {};
9926 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9927 hinfo.renderPass = VK_NULL_HANDLE;
9928 hinfo.subpass = 0;
9929 hinfo.framebuffer = VK_NULL_HANDLE;
9930 hinfo.occlusionQueryEnable = VK_FALSE;
9931 hinfo.queryFlags = 0;
9932 hinfo.pipelineStatistics = 0;
9933 VkCommandBufferBeginInfo info = {};
9934 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9935 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9936 info.pInheritanceInfo = &hinfo;
9937
9938 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9939 VkRenderPassBeginInfo rp_begin = {};
9940 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9941 rp_begin.pNext = NULL;
9942 rp_begin.renderPass = renderPass();
9943 rp_begin.framebuffer = framebuffer();
9944 rp_begin.clearValueCount = 0; // Should be 1
9945
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
9947 "there must be at least 1 entries in "
9948 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009949
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009950 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009951
9952 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06009953
9954 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009955}
9956
Cody Northrop3bb4d962016-05-09 16:15:57 -06009957TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
9958
9959 TEST_DESCRIPTION("End a command buffer with an active render pass");
9960
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9962 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06009963
9964 ASSERT_NO_FATAL_FAILURE(InitState());
9965 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9966
9967 // The framework's BeginCommandBuffer calls CreateRenderPass
9968 BeginCommandBuffer();
9969
9970 // Call directly into vkEndCommandBuffer instead of the
9971 // the framework's EndCommandBuffer, which inserts a
9972 // vkEndRenderPass
9973 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
9974
9975 m_errorMonitor->VerifyFound();
9976
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009977 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
9978 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06009979}
9980
Karl Schultz6addd812016-02-02 17:17:23 -07009981TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009982 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9984 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009985
9986 ASSERT_NO_FATAL_FAILURE(InitState());
9987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009988
9989 // Renderpass is started here
9990 BeginCommandBuffer();
9991
9992 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009993 vk_testing::Buffer dstBuffer;
9994 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009995
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009996 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009997
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009998 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009999}
10000
Karl Schultz6addd812016-02-02 17:17:23 -070010001TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010002 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10004 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010005
10006 ASSERT_NO_FATAL_FAILURE(InitState());
10007 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010008
10009 // Renderpass is started here
10010 BeginCommandBuffer();
10011
10012 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010013 vk_testing::Buffer dstBuffer;
10014 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010015
Karl Schultz6addd812016-02-02 17:17:23 -070010016 VkDeviceSize dstOffset = 0;
10017 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -060010018 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010020 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010021
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010022 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010023}
10024
Karl Schultz6addd812016-02-02 17:17:23 -070010025TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010026 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10028 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010029
10030 ASSERT_NO_FATAL_FAILURE(InitState());
10031 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010032
10033 // Renderpass is started here
10034 BeginCommandBuffer();
10035
Michael Lentine0a369f62016-02-03 16:51:46 -060010036 VkClearColorValue clear_color;
10037 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -070010038 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
10039 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10040 const int32_t tex_width = 32;
10041 const int32_t tex_height = 32;
10042 VkImageCreateInfo image_create_info = {};
10043 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10044 image_create_info.pNext = NULL;
10045 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10046 image_create_info.format = tex_format;
10047 image_create_info.extent.width = tex_width;
10048 image_create_info.extent.height = tex_height;
10049 image_create_info.extent.depth = 1;
10050 image_create_info.mipLevels = 1;
10051 image_create_info.arrayLayers = 1;
10052 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10053 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10054 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010055
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010056 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010057 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010058
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010059 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010060
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010061 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
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
Karl Schultz6addd812016-02-02 17:17:23 -070010066TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010067 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10069 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010070
10071 ASSERT_NO_FATAL_FAILURE(InitState());
10072 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010073
10074 // Renderpass is started here
10075 BeginCommandBuffer();
10076
10077 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -070010078 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010079 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
10080 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10081 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
10082 image_create_info.extent.width = 64;
10083 image_create_info.extent.height = 64;
10084 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10085 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010086
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010087 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010088 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010089
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010090 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010091
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010092 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
10093 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010094
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010095 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010096}
10097
Karl Schultz6addd812016-02-02 17:17:23 -070010098TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010099 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010100 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010101
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
10103 "must be issued inside an active "
10104 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010105
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010106 ASSERT_NO_FATAL_FAILURE(InitState());
10107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010108
10109 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010110 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010111 ASSERT_VK_SUCCESS(err);
10112
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010113 VkClearAttachment color_attachment;
10114 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10115 color_attachment.clearValue.color.float32[0] = 0;
10116 color_attachment.clearValue.color.float32[1] = 0;
10117 color_attachment.clearValue.color.float32[2] = 0;
10118 color_attachment.clearValue.color.float32[3] = 0;
10119 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010120 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010121 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010122
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010123 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010124}
10125
Chris Forbes3b97e932016-09-07 11:29:24 +120010126TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
10127 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
10128 "called too many times in a renderpass instance");
10129
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
10131 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +120010132
10133 ASSERT_NO_FATAL_FAILURE(InitState());
10134 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10135
10136 BeginCommandBuffer();
10137
10138 // error here.
10139 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
10140 m_errorMonitor->VerifyFound();
10141
10142 EndCommandBuffer();
10143}
10144
Chris Forbes6d624702016-09-07 13:57:05 +120010145TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
10146 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
10147 "called before the final subpass has been reached");
10148
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
10150 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +120010151
10152 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010153 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
10154 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +120010155
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010156 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +120010157
10158 VkRenderPass rp;
10159 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
10160 ASSERT_VK_SUCCESS(err);
10161
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010162 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +120010163
10164 VkFramebuffer fb;
10165 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
10166 ASSERT_VK_SUCCESS(err);
10167
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010168 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +120010169
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010170 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 +120010171
10172 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10173
10174 // Error here.
10175 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10176 m_errorMonitor->VerifyFound();
10177
10178 // Clean up.
10179 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
10180 vkDestroyRenderPass(m_device->device(), rp, nullptr);
10181}
10182
Karl Schultz9e66a292016-04-21 15:57:51 -060010183TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
10184 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10186 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -060010187
10188 ASSERT_NO_FATAL_FAILURE(InitState());
10189 BeginCommandBuffer();
10190
10191 VkBufferMemoryBarrier buf_barrier = {};
10192 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10193 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10194 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10195 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10196 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10197 buf_barrier.buffer = VK_NULL_HANDLE;
10198 buf_barrier.offset = 0;
10199 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010200 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10201 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -060010202
10203 m_errorMonitor->VerifyFound();
10204}
10205
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010206TEST_F(VkLayerTest, InvalidBarriers) {
10207 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
10208
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010210
10211 ASSERT_NO_FATAL_FAILURE(InitState());
10212 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10213
10214 VkMemoryBarrier mem_barrier = {};
10215 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
10216 mem_barrier.pNext = NULL;
10217 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10218 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10219 BeginCommandBuffer();
10220 // BeginCommandBuffer() starts 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, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010222 &mem_barrier, 0, nullptr, 0, nullptr);
10223 m_errorMonitor->VerifyFound();
10224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010226 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010227 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 -060010228 ASSERT_TRUE(image.initialized());
10229 VkImageMemoryBarrier img_barrier = {};
10230 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10231 img_barrier.pNext = NULL;
10232 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10233 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10234 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10235 // New layout can't be UNDEFINED
10236 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10237 img_barrier.image = image.handle();
10238 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10239 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10240 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10241 img_barrier.subresourceRange.baseArrayLayer = 0;
10242 img_barrier.subresourceRange.baseMipLevel = 0;
10243 img_barrier.subresourceRange.layerCount = 1;
10244 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010245 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10246 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010247 m_errorMonitor->VerifyFound();
10248 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10249
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
10251 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010252 // baseArrayLayer + layerCount must be <= image's arrayLayers
10253 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010254 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10255 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010256 m_errorMonitor->VerifyFound();
10257 img_barrier.subresourceRange.baseArrayLayer = 0;
10258
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010260 // baseMipLevel + levelCount must be <= image's mipLevels
10261 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010262 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10263 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010264 m_errorMonitor->VerifyFound();
10265 img_barrier.subresourceRange.baseMipLevel = 0;
10266
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010267 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 -060010268 vk_testing::Buffer buffer;
10269 buffer.init(*m_device, 256);
10270 VkBufferMemoryBarrier buf_barrier = {};
10271 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10272 buf_barrier.pNext = NULL;
10273 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10274 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10275 buf_barrier.buffer = buffer.handle();
10276 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10277 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10278 buf_barrier.offset = 0;
10279 buf_barrier.size = VK_WHOLE_SIZE;
10280 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010281 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10282 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010283 m_errorMonitor->VerifyFound();
10284 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10285
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010287 buf_barrier.offset = 257;
10288 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010289 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10290 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010291 m_errorMonitor->VerifyFound();
10292 buf_barrier.offset = 0;
10293
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010295 buf_barrier.size = 257;
10296 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010297 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10298 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010299 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010300
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010301 // Now exercise barrier aspect bit errors, first DS
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth and stencil format and thus must "
10303 "have either one or both of VK_IMAGE_ASPECT_DEPTH_BIT and "
10304 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010305 VkDepthStencilObj ds_image(m_device);
10306 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
10307 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -060010308 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
10309 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010310 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010311 // Use of COLOR aspect on DS image is error
10312 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010313 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10314 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010315 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010316 // Now test depth-only
10317 VkFormatProperties format_props;
10318
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010319 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
10320 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
10321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth-only format and thus must "
10322 "have VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010323 VkDepthStencilObj d_image(m_device);
10324 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
10325 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010326 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010327 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010328 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010329 // Use of COLOR aspect on depth image is error
10330 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010331 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10332 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010333 m_errorMonitor->VerifyFound();
10334 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010335 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
10336 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010337 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a stencil-only format and thus must "
10339 "have VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010340 VkDepthStencilObj s_image(m_device);
10341 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
10342 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010343 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010344 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010345 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010346 // Use of COLOR aspect on depth image is error
10347 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010348 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10349 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010350 m_errorMonitor->VerifyFound();
10351 }
10352 // Finally test color
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a color format and thus must "
10354 "have VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010355 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010356 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 -060010357 ASSERT_TRUE(c_image.initialized());
10358 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10359 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10360 img_barrier.image = c_image.handle();
10361 // Set aspect to depth (non-color)
10362 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010363 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10364 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010365 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010366}
10367
Karl Schultz6addd812016-02-02 17:17:23 -070010368TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010369 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010370 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010373
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010374 ASSERT_NO_FATAL_FAILURE(InitState());
10375 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010376 uint32_t qfi = 0;
10377 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010378 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10379 buffCI.size = 1024;
10380 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10381 buffCI.queueFamilyIndexCount = 1;
10382 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010383
10384 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010385 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010386 ASSERT_VK_SUCCESS(err);
10387
10388 BeginCommandBuffer();
10389 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -070010390 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10391 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010392 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010393 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010394
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010395 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010396
Chia-I Wuf7458c52015-10-26 21:10:41 +080010397 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010398}
10399
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010400TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10401 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10403 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
10404 "of the indices specified when the device was created, via the "
10405 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010406
10407 ASSERT_NO_FATAL_FAILURE(InitState());
10408 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10409 VkBufferCreateInfo buffCI = {};
10410 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10411 buffCI.size = 1024;
10412 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10413 buffCI.queueFamilyIndexCount = 1;
10414 // Introduce failure by specifying invalid queue_family_index
10415 uint32_t qfi = 777;
10416 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -060010417 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010418
10419 VkBuffer ib;
10420 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
10421
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010422 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060010423 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010424}
10425
Karl Schultz6addd812016-02-02 17:17:23 -070010426TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010427 TEST_DESCRIPTION("Attempt vkCmdExecuteCommands w/ a primary cmd buffer"
10428 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010429
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010431
10432 ASSERT_NO_FATAL_FAILURE(InitState());
10433 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010434
10435 BeginCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010436
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010437 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
10438 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010439
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010440 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010441}
10442
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010443TEST_F(VkLayerTest, DSUsageBitsErrors) {
10444 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
10445 "that do not have correct usage bits sets.");
10446 VkResult err;
10447
10448 ASSERT_NO_FATAL_FAILURE(InitState());
10449 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10450 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10451 ds_type_count[i].type = VkDescriptorType(i);
10452 ds_type_count[i].descriptorCount = 1;
10453 }
10454 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10455 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10456 ds_pool_ci.pNext = NULL;
10457 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10458 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10459 ds_pool_ci.pPoolSizes = ds_type_count;
10460
10461 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010462 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010463 ASSERT_VK_SUCCESS(err);
10464
10465 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010466 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010467 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10468 dsl_binding[i].binding = 0;
10469 dsl_binding[i].descriptorType = VkDescriptorType(i);
10470 dsl_binding[i].descriptorCount = 1;
10471 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10472 dsl_binding[i].pImmutableSamplers = NULL;
10473 }
10474
10475 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10476 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10477 ds_layout_ci.pNext = NULL;
10478 ds_layout_ci.bindingCount = 1;
10479 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10480 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10481 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010482 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010483 ASSERT_VK_SUCCESS(err);
10484 }
10485 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10486 VkDescriptorSetAllocateInfo alloc_info = {};
10487 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10488 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10489 alloc_info.descriptorPool = ds_pool;
10490 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010491 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010492 ASSERT_VK_SUCCESS(err);
10493
10494 // Create a buffer & bufferView to be used for invalid updates
10495 VkBufferCreateInfo buff_ci = {};
10496 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10497 // This usage is not valid for any descriptor type
10498 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
10499 buff_ci.size = 256;
10500 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10501 VkBuffer buffer;
10502 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10503 ASSERT_VK_SUCCESS(err);
10504
10505 VkBufferViewCreateInfo buff_view_ci = {};
10506 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10507 buff_view_ci.buffer = buffer;
10508 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10509 buff_view_ci.range = VK_WHOLE_SIZE;
10510 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010511 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010512 ASSERT_VK_SUCCESS(err);
10513
10514 // Create an image to be used for invalid updates
10515 VkImageCreateInfo image_ci = {};
10516 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10517 image_ci.imageType = VK_IMAGE_TYPE_2D;
10518 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10519 image_ci.extent.width = 64;
10520 image_ci.extent.height = 64;
10521 image_ci.extent.depth = 1;
10522 image_ci.mipLevels = 1;
10523 image_ci.arrayLayers = 1;
10524 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10525 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10526 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10527 // This usage is not valid for any descriptor type
10528 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10529 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10530 VkImage image;
10531 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10532 ASSERT_VK_SUCCESS(err);
10533 // Bind memory to image
10534 VkMemoryRequirements mem_reqs;
10535 VkDeviceMemory image_mem;
10536 bool pass;
10537 VkMemoryAllocateInfo mem_alloc = {};
10538 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10539 mem_alloc.pNext = NULL;
10540 mem_alloc.allocationSize = 0;
10541 mem_alloc.memoryTypeIndex = 0;
10542 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10543 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010544 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010545 ASSERT_TRUE(pass);
10546 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10547 ASSERT_VK_SUCCESS(err);
10548 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10549 ASSERT_VK_SUCCESS(err);
10550 // Now create view for image
10551 VkImageViewCreateInfo image_view_ci = {};
10552 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10553 image_view_ci.image = image;
10554 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10555 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10556 image_view_ci.subresourceRange.layerCount = 1;
10557 image_view_ci.subresourceRange.baseArrayLayer = 0;
10558 image_view_ci.subresourceRange.levelCount = 1;
10559 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10560 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010561 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010562 ASSERT_VK_SUCCESS(err);
10563
10564 VkDescriptorBufferInfo buff_info = {};
10565 buff_info.buffer = buffer;
10566 VkDescriptorImageInfo img_info = {};
10567 img_info.imageView = image_view;
10568 VkWriteDescriptorSet descriptor_write = {};
10569 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10570 descriptor_write.dstBinding = 0;
10571 descriptor_write.descriptorCount = 1;
10572 descriptor_write.pTexelBufferView = &buff_view;
10573 descriptor_write.pBufferInfo = &buff_info;
10574 descriptor_write.pImageInfo = &img_info;
10575
10576 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010577 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
10578 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10579 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10580 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
10581 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
10582 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
10583 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10584 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10585 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10586 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10587 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010588 // Start loop at 1 as SAMPLER desc type has no usage bit error
10589 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10590 descriptor_write.descriptorType = VkDescriptorType(i);
10591 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010593
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010594 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010595
10596 m_errorMonitor->VerifyFound();
10597 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
10598 }
10599 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10600 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010601 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010602 vkDestroyImageView(m_device->device(), image_view, NULL);
10603 vkDestroyBuffer(m_device->device(), buffer, NULL);
10604 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010605 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010606 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10607}
10608
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010609TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010610 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
10611 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
10612 "1. offset value greater than buffer size\n"
10613 "2. range value of 0\n"
10614 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010615 VkResult err;
10616
10617 ASSERT_NO_FATAL_FAILURE(InitState());
10618 VkDescriptorPoolSize ds_type_count = {};
10619 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10620 ds_type_count.descriptorCount = 1;
10621
10622 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10623 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10624 ds_pool_ci.pNext = NULL;
10625 ds_pool_ci.maxSets = 1;
10626 ds_pool_ci.poolSizeCount = 1;
10627 ds_pool_ci.pPoolSizes = &ds_type_count;
10628
10629 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010630 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010631 ASSERT_VK_SUCCESS(err);
10632
10633 // Create layout with single uniform buffer descriptor
10634 VkDescriptorSetLayoutBinding dsl_binding = {};
10635 dsl_binding.binding = 0;
10636 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10637 dsl_binding.descriptorCount = 1;
10638 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10639 dsl_binding.pImmutableSamplers = NULL;
10640
10641 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10642 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10643 ds_layout_ci.pNext = NULL;
10644 ds_layout_ci.bindingCount = 1;
10645 ds_layout_ci.pBindings = &dsl_binding;
10646 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010647 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010648 ASSERT_VK_SUCCESS(err);
10649
10650 VkDescriptorSet descriptor_set = {};
10651 VkDescriptorSetAllocateInfo alloc_info = {};
10652 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10653 alloc_info.descriptorSetCount = 1;
10654 alloc_info.descriptorPool = ds_pool;
10655 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010656 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010657 ASSERT_VK_SUCCESS(err);
10658
10659 // Create a buffer to be used for invalid updates
10660 VkBufferCreateInfo buff_ci = {};
10661 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10662 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10663 buff_ci.size = 256;
10664 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10665 VkBuffer buffer;
10666 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10667 ASSERT_VK_SUCCESS(err);
10668 // Have to bind memory to buffer before descriptor update
10669 VkMemoryAllocateInfo mem_alloc = {};
10670 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10671 mem_alloc.pNext = NULL;
10672 mem_alloc.allocationSize = 256;
10673 mem_alloc.memoryTypeIndex = 0;
10674
10675 VkMemoryRequirements mem_reqs;
10676 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010677 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010678 if (!pass) {
10679 vkDestroyBuffer(m_device->device(), buffer, NULL);
10680 return;
10681 }
10682
10683 VkDeviceMemory mem;
10684 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10685 ASSERT_VK_SUCCESS(err);
10686 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10687 ASSERT_VK_SUCCESS(err);
10688
10689 VkDescriptorBufferInfo buff_info = {};
10690 buff_info.buffer = buffer;
10691 // First make offset 1 larger than buffer size
10692 buff_info.offset = 257;
10693 buff_info.range = VK_WHOLE_SIZE;
10694 VkWriteDescriptorSet descriptor_write = {};
10695 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10696 descriptor_write.dstBinding = 0;
10697 descriptor_write.descriptorCount = 1;
10698 descriptor_write.pTexelBufferView = nullptr;
10699 descriptor_write.pBufferInfo = &buff_info;
10700 descriptor_write.pImageInfo = nullptr;
10701
10702 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10703 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010705
10706 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10707
10708 m_errorMonitor->VerifyFound();
10709 // Now cause error due to range of 0
10710 buff_info.offset = 0;
10711 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10713 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010714
10715 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10716
10717 m_errorMonitor->VerifyFound();
10718 // Now cause error due to range exceeding buffer size - offset
10719 buff_info.offset = 128;
10720 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010721 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 -060010722
10723 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10724
10725 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010726 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010727 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10728 vkDestroyBuffer(m_device->device(), buffer, NULL);
10729 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10730 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10731}
10732
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010733TEST_F(VkLayerTest, DSAspectBitsErrors) {
10734 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10735 // are set, but could expand this test to hit more cases.
10736 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
10737 "that do not have correct aspect bits sets.");
10738 VkResult err;
10739
10740 ASSERT_NO_FATAL_FAILURE(InitState());
10741 VkDescriptorPoolSize ds_type_count = {};
10742 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10743 ds_type_count.descriptorCount = 1;
10744
10745 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10746 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10747 ds_pool_ci.pNext = NULL;
10748 ds_pool_ci.maxSets = 5;
10749 ds_pool_ci.poolSizeCount = 1;
10750 ds_pool_ci.pPoolSizes = &ds_type_count;
10751
10752 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010753 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010754 ASSERT_VK_SUCCESS(err);
10755
10756 VkDescriptorSetLayoutBinding dsl_binding = {};
10757 dsl_binding.binding = 0;
10758 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10759 dsl_binding.descriptorCount = 1;
10760 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10761 dsl_binding.pImmutableSamplers = NULL;
10762
10763 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10764 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10765 ds_layout_ci.pNext = NULL;
10766 ds_layout_ci.bindingCount = 1;
10767 ds_layout_ci.pBindings = &dsl_binding;
10768 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010769 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010770 ASSERT_VK_SUCCESS(err);
10771
10772 VkDescriptorSet descriptor_set = {};
10773 VkDescriptorSetAllocateInfo alloc_info = {};
10774 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10775 alloc_info.descriptorSetCount = 1;
10776 alloc_info.descriptorPool = ds_pool;
10777 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010778 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010779 ASSERT_VK_SUCCESS(err);
10780
10781 // Create an image to be used for invalid updates
10782 VkImageCreateInfo image_ci = {};
10783 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10784 image_ci.imageType = VK_IMAGE_TYPE_2D;
10785 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10786 image_ci.extent.width = 64;
10787 image_ci.extent.height = 64;
10788 image_ci.extent.depth = 1;
10789 image_ci.mipLevels = 1;
10790 image_ci.arrayLayers = 1;
10791 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10792 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10793 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10794 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10795 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10796 VkImage image;
10797 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10798 ASSERT_VK_SUCCESS(err);
10799 // Bind memory to image
10800 VkMemoryRequirements mem_reqs;
10801 VkDeviceMemory image_mem;
10802 bool pass;
10803 VkMemoryAllocateInfo mem_alloc = {};
10804 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10805 mem_alloc.pNext = NULL;
10806 mem_alloc.allocationSize = 0;
10807 mem_alloc.memoryTypeIndex = 0;
10808 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10809 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010810 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010811 ASSERT_TRUE(pass);
10812 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10813 ASSERT_VK_SUCCESS(err);
10814 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10815 ASSERT_VK_SUCCESS(err);
10816 // Now create view for image
10817 VkImageViewCreateInfo image_view_ci = {};
10818 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10819 image_view_ci.image = image;
10820 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10821 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10822 image_view_ci.subresourceRange.layerCount = 1;
10823 image_view_ci.subresourceRange.baseArrayLayer = 0;
10824 image_view_ci.subresourceRange.levelCount = 1;
10825 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010826 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010827
10828 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010829 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010830 ASSERT_VK_SUCCESS(err);
10831
10832 VkDescriptorImageInfo img_info = {};
10833 img_info.imageView = image_view;
10834 VkWriteDescriptorSet descriptor_write = {};
10835 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10836 descriptor_write.dstBinding = 0;
10837 descriptor_write.descriptorCount = 1;
10838 descriptor_write.pTexelBufferView = NULL;
10839 descriptor_write.pBufferInfo = NULL;
10840 descriptor_write.pImageInfo = &img_info;
10841 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10842 descriptor_write.dstSet = descriptor_set;
10843 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10844 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010846
10847 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10848
10849 m_errorMonitor->VerifyFound();
10850 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10851 vkDestroyImage(m_device->device(), image, NULL);
10852 vkFreeMemory(m_device->device(), image_mem, NULL);
10853 vkDestroyImageView(m_device->device(), image_view, NULL);
10854 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10855 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10856}
10857
Karl Schultz6addd812016-02-02 17:17:23 -070010858TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010859 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010860 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010861
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10863 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10864 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010865
Tobin Ehlis3b780662015-05-28 12:11:26 -060010866 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010867 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010868 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010869 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10870 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010871
10872 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010873 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10874 ds_pool_ci.pNext = NULL;
10875 ds_pool_ci.maxSets = 1;
10876 ds_pool_ci.poolSizeCount = 1;
10877 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010878
Tobin Ehlis3b780662015-05-28 12:11:26 -060010879 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010880 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010881 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010882 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010883 dsl_binding.binding = 0;
10884 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10885 dsl_binding.descriptorCount = 1;
10886 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10887 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010888
Tony Barboureb254902015-07-15 12:50:33 -060010889 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010890 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10891 ds_layout_ci.pNext = NULL;
10892 ds_layout_ci.bindingCount = 1;
10893 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010894
Tobin Ehlis3b780662015-05-28 12:11:26 -060010895 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010896 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010897 ASSERT_VK_SUCCESS(err);
10898
10899 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010900 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010901 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010902 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010903 alloc_info.descriptorPool = ds_pool;
10904 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010905 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010906 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010907
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010908 VkSamplerCreateInfo sampler_ci = {};
10909 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10910 sampler_ci.pNext = NULL;
10911 sampler_ci.magFilter = VK_FILTER_NEAREST;
10912 sampler_ci.minFilter = VK_FILTER_NEAREST;
10913 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10914 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10915 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10916 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10917 sampler_ci.mipLodBias = 1.0;
10918 sampler_ci.anisotropyEnable = VK_FALSE;
10919 sampler_ci.maxAnisotropy = 1;
10920 sampler_ci.compareEnable = VK_FALSE;
10921 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10922 sampler_ci.minLod = 1.0;
10923 sampler_ci.maxLod = 1.0;
10924 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10925 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10926 VkSampler sampler;
10927 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10928 ASSERT_VK_SUCCESS(err);
10929
10930 VkDescriptorImageInfo info = {};
10931 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010932
10933 VkWriteDescriptorSet descriptor_write;
10934 memset(&descriptor_write, 0, sizeof(descriptor_write));
10935 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010936 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010937 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010938 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010939 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010940 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010941
10942 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10943
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010944 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010945
Chia-I Wuf7458c52015-10-26 21:10:41 +080010946 vkDestroySampler(m_device->device(), sampler, NULL);
10947 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10948 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010949}
10950
Karl Schultz6addd812016-02-02 17:17:23 -070010951TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010952 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010953 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010954
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10956 " binding #0 with 1 total descriptors but update of 1 descriptors "
10957 "starting at binding offset of 0 combined with update array element "
10958 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010959
Tobin Ehlis3b780662015-05-28 12:11:26 -060010960 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010961 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010962 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010963 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10964 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010965
10966 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010967 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10968 ds_pool_ci.pNext = NULL;
10969 ds_pool_ci.maxSets = 1;
10970 ds_pool_ci.poolSizeCount = 1;
10971 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010972
Tobin Ehlis3b780662015-05-28 12:11:26 -060010973 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010974 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010975 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010976
Tony Barboureb254902015-07-15 12:50:33 -060010977 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010978 dsl_binding.binding = 0;
10979 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10980 dsl_binding.descriptorCount = 1;
10981 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10982 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010983
10984 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010985 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10986 ds_layout_ci.pNext = NULL;
10987 ds_layout_ci.bindingCount = 1;
10988 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010989
Tobin Ehlis3b780662015-05-28 12:11:26 -060010990 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010991 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010992 ASSERT_VK_SUCCESS(err);
10993
10994 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010995 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010996 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010997 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010998 alloc_info.descriptorPool = ds_pool;
10999 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011000 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011001 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011002
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011003 // Correctly update descriptor to avoid "NOT_UPDATED" error
11004 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011005 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011006 buff_info.offset = 0;
11007 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011008
11009 VkWriteDescriptorSet descriptor_write;
11010 memset(&descriptor_write, 0, sizeof(descriptor_write));
11011 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011012 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011013 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080011014 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060011015 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11016 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011017
11018 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11019
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011020 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011021
Chia-I Wuf7458c52015-10-26 21:10:41 +080011022 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11023 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011024}
11025
Karl Schultz6addd812016-02-02 17:17:23 -070011026TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
11027 // Create layout w/ count of 1 and attempt update to that layout w/ binding
11028 // index 2
11029 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011030
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011032
Tobin Ehlis3b780662015-05-28 12:11:26 -060011033 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011034 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011035 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011036 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11037 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011038
11039 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011040 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11041 ds_pool_ci.pNext = NULL;
11042 ds_pool_ci.maxSets = 1;
11043 ds_pool_ci.poolSizeCount = 1;
11044 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011045
Tobin Ehlis3b780662015-05-28 12:11:26 -060011046 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011047 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011048 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011049
Tony Barboureb254902015-07-15 12:50:33 -060011050 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011051 dsl_binding.binding = 0;
11052 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11053 dsl_binding.descriptorCount = 1;
11054 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11055 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011056
11057 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011058 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11059 ds_layout_ci.pNext = NULL;
11060 ds_layout_ci.bindingCount = 1;
11061 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011062 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011063 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011064 ASSERT_VK_SUCCESS(err);
11065
11066 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011067 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011068 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011069 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011070 alloc_info.descriptorPool = ds_pool;
11071 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011072 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011073 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011074
Tony Barboureb254902015-07-15 12:50:33 -060011075 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011076 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11077 sampler_ci.pNext = NULL;
11078 sampler_ci.magFilter = VK_FILTER_NEAREST;
11079 sampler_ci.minFilter = VK_FILTER_NEAREST;
11080 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11081 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11082 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11083 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11084 sampler_ci.mipLodBias = 1.0;
11085 sampler_ci.anisotropyEnable = VK_FALSE;
11086 sampler_ci.maxAnisotropy = 1;
11087 sampler_ci.compareEnable = VK_FALSE;
11088 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11089 sampler_ci.minLod = 1.0;
11090 sampler_ci.maxLod = 1.0;
11091 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11092 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011093
Tobin Ehlis3b780662015-05-28 12:11:26 -060011094 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011095 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011096 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011097
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011098 VkDescriptorImageInfo info = {};
11099 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011100
11101 VkWriteDescriptorSet descriptor_write;
11102 memset(&descriptor_write, 0, sizeof(descriptor_write));
11103 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011104 descriptor_write.dstSet = descriptorSet;
11105 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011106 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011107 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011108 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011109 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011110
11111 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11112
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011113 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011114
Chia-I Wuf7458c52015-10-26 21:10:41 +080011115 vkDestroySampler(m_device->device(), sampler, NULL);
11116 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11117 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011118}
11119
Karl Schultz6addd812016-02-02 17:17:23 -070011120TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11121 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11122 // types
11123 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011124
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011125 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 -060011126
Tobin Ehlis3b780662015-05-28 12:11:26 -060011127 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011128
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011129 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011130 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11131 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011132
11133 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011134 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11135 ds_pool_ci.pNext = NULL;
11136 ds_pool_ci.maxSets = 1;
11137 ds_pool_ci.poolSizeCount = 1;
11138 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011139
Tobin Ehlis3b780662015-05-28 12:11:26 -060011140 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011141 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011142 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011143 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011144 dsl_binding.binding = 0;
11145 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11146 dsl_binding.descriptorCount = 1;
11147 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11148 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011149
Tony Barboureb254902015-07-15 12:50:33 -060011150 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011151 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11152 ds_layout_ci.pNext = NULL;
11153 ds_layout_ci.bindingCount = 1;
11154 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011155
Tobin Ehlis3b780662015-05-28 12:11:26 -060011156 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011157 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011158 ASSERT_VK_SUCCESS(err);
11159
11160 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011161 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011162 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011163 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011164 alloc_info.descriptorPool = ds_pool;
11165 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011166 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011167 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011168
Tony Barboureb254902015-07-15 12:50:33 -060011169 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011170 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11171 sampler_ci.pNext = NULL;
11172 sampler_ci.magFilter = VK_FILTER_NEAREST;
11173 sampler_ci.minFilter = VK_FILTER_NEAREST;
11174 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11175 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11176 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11177 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11178 sampler_ci.mipLodBias = 1.0;
11179 sampler_ci.anisotropyEnable = VK_FALSE;
11180 sampler_ci.maxAnisotropy = 1;
11181 sampler_ci.compareEnable = VK_FALSE;
11182 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11183 sampler_ci.minLod = 1.0;
11184 sampler_ci.maxLod = 1.0;
11185 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11186 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011187 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011188 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011189 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011190
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011191 VkDescriptorImageInfo info = {};
11192 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011193
11194 VkWriteDescriptorSet descriptor_write;
11195 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011196 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011197 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011198 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011199 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011200 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011201 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011202
11203 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11204
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011205 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011206
Chia-I Wuf7458c52015-10-26 21:10:41 +080011207 vkDestroySampler(m_device->device(), sampler, NULL);
11208 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11209 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011210}
11211
Karl Schultz6addd812016-02-02 17:17:23 -070011212TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011213 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011214 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011215
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11217 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011218
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011219 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011220 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11221 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011222 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011223 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11224 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011225
11226 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011227 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11228 ds_pool_ci.pNext = NULL;
11229 ds_pool_ci.maxSets = 1;
11230 ds_pool_ci.poolSizeCount = 1;
11231 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011232
11233 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011234 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011235 ASSERT_VK_SUCCESS(err);
11236
11237 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011238 dsl_binding.binding = 0;
11239 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11240 dsl_binding.descriptorCount = 1;
11241 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11242 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011243
11244 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011245 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11246 ds_layout_ci.pNext = NULL;
11247 ds_layout_ci.bindingCount = 1;
11248 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011249 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011250 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011251 ASSERT_VK_SUCCESS(err);
11252
11253 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011254 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011255 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011256 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011257 alloc_info.descriptorPool = ds_pool;
11258 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011259 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011260 ASSERT_VK_SUCCESS(err);
11261
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011262 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011263
11264 VkDescriptorImageInfo descriptor_info;
11265 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11266 descriptor_info.sampler = sampler;
11267
11268 VkWriteDescriptorSet descriptor_write;
11269 memset(&descriptor_write, 0, sizeof(descriptor_write));
11270 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011271 descriptor_write.dstSet = descriptorSet;
11272 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011273 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011274 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11275 descriptor_write.pImageInfo = &descriptor_info;
11276
11277 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11278
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011279 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011280
Chia-I Wuf7458c52015-10-26 21:10:41 +080011281 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11282 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011283}
11284
Karl Schultz6addd812016-02-02 17:17:23 -070011285TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11286 // Create a single combined Image/Sampler descriptor and send it an invalid
11287 // imageView
11288 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011289
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
11291 "image sampler descriptor failed due "
11292 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011293
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011294 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011295 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011296 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11297 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011298
11299 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011300 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11301 ds_pool_ci.pNext = NULL;
11302 ds_pool_ci.maxSets = 1;
11303 ds_pool_ci.poolSizeCount = 1;
11304 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011305
11306 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011307 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011308 ASSERT_VK_SUCCESS(err);
11309
11310 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011311 dsl_binding.binding = 0;
11312 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11313 dsl_binding.descriptorCount = 1;
11314 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11315 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011316
11317 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011318 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11319 ds_layout_ci.pNext = NULL;
11320 ds_layout_ci.bindingCount = 1;
11321 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011322 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011323 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011324 ASSERT_VK_SUCCESS(err);
11325
11326 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011327 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011328 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011329 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011330 alloc_info.descriptorPool = ds_pool;
11331 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011332 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011333 ASSERT_VK_SUCCESS(err);
11334
11335 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011336 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11337 sampler_ci.pNext = NULL;
11338 sampler_ci.magFilter = VK_FILTER_NEAREST;
11339 sampler_ci.minFilter = VK_FILTER_NEAREST;
11340 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11341 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11342 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11343 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11344 sampler_ci.mipLodBias = 1.0;
11345 sampler_ci.anisotropyEnable = VK_FALSE;
11346 sampler_ci.maxAnisotropy = 1;
11347 sampler_ci.compareEnable = VK_FALSE;
11348 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11349 sampler_ci.minLod = 1.0;
11350 sampler_ci.maxLod = 1.0;
11351 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11352 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011353
11354 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011355 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011356 ASSERT_VK_SUCCESS(err);
11357
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011358 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011359
11360 VkDescriptorImageInfo descriptor_info;
11361 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11362 descriptor_info.sampler = sampler;
11363 descriptor_info.imageView = view;
11364
11365 VkWriteDescriptorSet descriptor_write;
11366 memset(&descriptor_write, 0, sizeof(descriptor_write));
11367 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011368 descriptor_write.dstSet = descriptorSet;
11369 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011370 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011371 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11372 descriptor_write.pImageInfo = &descriptor_info;
11373
11374 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11375
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011376 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011377
Chia-I Wuf7458c52015-10-26 21:10:41 +080011378 vkDestroySampler(m_device->device(), sampler, NULL);
11379 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11380 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011381}
11382
Karl Schultz6addd812016-02-02 17:17:23 -070011383TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11384 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11385 // into the other
11386 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011387
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
11389 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11390 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011391
Tobin Ehlis04356f92015-10-27 16:35:27 -060011392 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011393 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011394 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011395 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11396 ds_type_count[0].descriptorCount = 1;
11397 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11398 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011399
11400 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011401 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11402 ds_pool_ci.pNext = NULL;
11403 ds_pool_ci.maxSets = 1;
11404 ds_pool_ci.poolSizeCount = 2;
11405 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011406
11407 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011408 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011409 ASSERT_VK_SUCCESS(err);
11410 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011411 dsl_binding[0].binding = 0;
11412 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11413 dsl_binding[0].descriptorCount = 1;
11414 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11415 dsl_binding[0].pImmutableSamplers = NULL;
11416 dsl_binding[1].binding = 1;
11417 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11418 dsl_binding[1].descriptorCount = 1;
11419 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11420 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011421
11422 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011423 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11424 ds_layout_ci.pNext = NULL;
11425 ds_layout_ci.bindingCount = 2;
11426 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011427
11428 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011429 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011430 ASSERT_VK_SUCCESS(err);
11431
11432 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011433 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011434 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011435 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011436 alloc_info.descriptorPool = ds_pool;
11437 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011438 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011439 ASSERT_VK_SUCCESS(err);
11440
11441 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011442 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11443 sampler_ci.pNext = NULL;
11444 sampler_ci.magFilter = VK_FILTER_NEAREST;
11445 sampler_ci.minFilter = VK_FILTER_NEAREST;
11446 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11447 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11448 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11449 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11450 sampler_ci.mipLodBias = 1.0;
11451 sampler_ci.anisotropyEnable = VK_FALSE;
11452 sampler_ci.maxAnisotropy = 1;
11453 sampler_ci.compareEnable = VK_FALSE;
11454 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11455 sampler_ci.minLod = 1.0;
11456 sampler_ci.maxLod = 1.0;
11457 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11458 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011459
11460 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011461 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011462 ASSERT_VK_SUCCESS(err);
11463
11464 VkDescriptorImageInfo info = {};
11465 info.sampler = sampler;
11466
11467 VkWriteDescriptorSet descriptor_write;
11468 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11469 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011470 descriptor_write.dstSet = descriptorSet;
11471 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011472 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011473 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11474 descriptor_write.pImageInfo = &info;
11475 // This write update should succeed
11476 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11477 // Now perform a copy update that fails due to type mismatch
11478 VkCopyDescriptorSet copy_ds_update;
11479 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11480 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11481 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -060011482 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011483 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -070011484 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +080011485 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011486 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11487
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011488 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011489 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011490 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 -060011491 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11492 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11493 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011494 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011495 copy_ds_update.dstSet = descriptorSet;
11496 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -060011497 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011498 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11499
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011500 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011501
Tobin Ehlis04356f92015-10-27 16:35:27 -060011502 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
11504 "update array offset of 0 and update of "
11505 "5 descriptors oversteps total number "
11506 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011507
Tobin Ehlis04356f92015-10-27 16:35:27 -060011508 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11509 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11510 copy_ds_update.srcSet = descriptorSet;
11511 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011512 copy_ds_update.dstSet = descriptorSet;
11513 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011514 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011515 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11516
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011517 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011518
Chia-I Wuf7458c52015-10-26 21:10:41 +080011519 vkDestroySampler(m_device->device(), sampler, NULL);
11520 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11521 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011522}
11523
Karl Schultz6addd812016-02-02 17:17:23 -070011524TEST_F(VkLayerTest, NumSamplesMismatch) {
11525 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11526 // sampleCount
11527 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011528
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011530
Tobin Ehlis3b780662015-05-28 12:11:26 -060011531 ASSERT_NO_FATAL_FAILURE(InitState());
11532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011533 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011534 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011535 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011536
11537 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011538 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11539 ds_pool_ci.pNext = NULL;
11540 ds_pool_ci.maxSets = 1;
11541 ds_pool_ci.poolSizeCount = 1;
11542 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011543
Tobin Ehlis3b780662015-05-28 12:11:26 -060011544 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011545 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011546 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011547
Tony Barboureb254902015-07-15 12:50:33 -060011548 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011549 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011550 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011551 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011552 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11553 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011554
Tony Barboureb254902015-07-15 12:50:33 -060011555 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11556 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11557 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011558 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011559 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011560
Tobin Ehlis3b780662015-05-28 12:11:26 -060011561 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011562 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011563 ASSERT_VK_SUCCESS(err);
11564
11565 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011566 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011567 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011568 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011569 alloc_info.descriptorPool = ds_pool;
11570 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011571 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011572 ASSERT_VK_SUCCESS(err);
11573
Tony Barboureb254902015-07-15 12:50:33 -060011574 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011575 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011576 pipe_ms_state_ci.pNext = NULL;
11577 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11578 pipe_ms_state_ci.sampleShadingEnable = 0;
11579 pipe_ms_state_ci.minSampleShading = 1.0;
11580 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011581
Tony Barboureb254902015-07-15 12:50:33 -060011582 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011583 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11584 pipeline_layout_ci.pNext = NULL;
11585 pipeline_layout_ci.setLayoutCount = 1;
11586 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011587
11588 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011589 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011590 ASSERT_VK_SUCCESS(err);
11591
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011592 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11593 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11594 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011595 VkPipelineObj pipe(m_device);
11596 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011597 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011598 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011599 pipe.SetMSAA(&pipe_ms_state_ci);
11600 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011601
Tony Barbourfe3351b2015-07-28 10:17:20 -060011602 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011603 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011604
Mark Young29927482016-05-04 14:38:51 -060011605 // Render triangle (the error should trigger on the attempt to draw).
11606 Draw(3, 1, 0, 0);
11607
11608 // Finalize recording of the command buffer
11609 EndCommandBuffer();
11610
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011611 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011612
Chia-I Wuf7458c52015-10-26 21:10:41 +080011613 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11614 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11615 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011616}
Mark Young29927482016-05-04 14:38:51 -060011617
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011618TEST_F(VkLayerTest, RenderPassIncompatible) {
11619 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
11620 "Initial case is drawing with an active renderpass that's "
11621 "not compatible with the bound PSO's creation renderpass");
11622 VkResult err;
11623
11624 ASSERT_NO_FATAL_FAILURE(InitState());
11625 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11626
11627 VkDescriptorSetLayoutBinding dsl_binding = {};
11628 dsl_binding.binding = 0;
11629 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11630 dsl_binding.descriptorCount = 1;
11631 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11632 dsl_binding.pImmutableSamplers = NULL;
11633
11634 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11635 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11636 ds_layout_ci.pNext = NULL;
11637 ds_layout_ci.bindingCount = 1;
11638 ds_layout_ci.pBindings = &dsl_binding;
11639
11640 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011641 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011642 ASSERT_VK_SUCCESS(err);
11643
11644 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11645 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11646 pipeline_layout_ci.pNext = NULL;
11647 pipeline_layout_ci.setLayoutCount = 1;
11648 pipeline_layout_ci.pSetLayouts = &ds_layout;
11649
11650 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011651 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011652 ASSERT_VK_SUCCESS(err);
11653
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011654 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11655 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11656 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011657 // Create a renderpass that will be incompatible with default renderpass
11658 VkAttachmentReference attach = {};
11659 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11660 VkAttachmentReference color_att = {};
11661 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11662 VkSubpassDescription subpass = {};
11663 subpass.inputAttachmentCount = 1;
11664 subpass.pInputAttachments = &attach;
11665 subpass.colorAttachmentCount = 1;
11666 subpass.pColorAttachments = &color_att;
11667 VkRenderPassCreateInfo rpci = {};
11668 rpci.subpassCount = 1;
11669 rpci.pSubpasses = &subpass;
11670 rpci.attachmentCount = 1;
11671 VkAttachmentDescription attach_desc = {};
11672 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011673 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11674 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011675 rpci.pAttachments = &attach_desc;
11676 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11677 VkRenderPass rp;
11678 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11679 VkPipelineObj pipe(m_device);
11680 pipe.AddShader(&vs);
11681 pipe.AddShader(&fs);
11682 pipe.AddColorAttachment();
11683 VkViewport view_port = {};
11684 m_viewports.push_back(view_port);
11685 pipe.SetViewport(m_viewports);
11686 VkRect2D rect = {};
11687 m_scissors.push_back(rect);
11688 pipe.SetScissor(m_scissors);
11689 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11690
11691 VkCommandBufferInheritanceInfo cbii = {};
11692 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11693 cbii.renderPass = rp;
11694 cbii.subpass = 0;
11695 VkCommandBufferBeginInfo cbbi = {};
11696 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11697 cbbi.pInheritanceInfo = &cbii;
11698 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11699 VkRenderPassBeginInfo rpbi = {};
11700 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11701 rpbi.framebuffer = m_framebuffer;
11702 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011703 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11704 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011705
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011707 // Render triangle (the error should trigger on the attempt to draw).
11708 Draw(3, 1, 0, 0);
11709
11710 // Finalize recording of the command buffer
11711 EndCommandBuffer();
11712
11713 m_errorMonitor->VerifyFound();
11714
11715 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11716 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11717 vkDestroyRenderPass(m_device->device(), rp, NULL);
11718}
11719
Mark Youngc89c6312016-03-31 16:03:20 -060011720TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11721 // Create Pipeline where the number of blend attachments doesn't match the
11722 // number of color attachments. In this case, we don't add any color
11723 // blend attachments even though we have a color attachment.
11724 VkResult err;
11725
11726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011727 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060011728
11729 ASSERT_NO_FATAL_FAILURE(InitState());
11730 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11731 VkDescriptorPoolSize ds_type_count = {};
11732 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11733 ds_type_count.descriptorCount = 1;
11734
11735 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11736 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11737 ds_pool_ci.pNext = NULL;
11738 ds_pool_ci.maxSets = 1;
11739 ds_pool_ci.poolSizeCount = 1;
11740 ds_pool_ci.pPoolSizes = &ds_type_count;
11741
11742 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011743 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011744 ASSERT_VK_SUCCESS(err);
11745
11746 VkDescriptorSetLayoutBinding dsl_binding = {};
11747 dsl_binding.binding = 0;
11748 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11749 dsl_binding.descriptorCount = 1;
11750 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11751 dsl_binding.pImmutableSamplers = NULL;
11752
11753 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11754 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11755 ds_layout_ci.pNext = NULL;
11756 ds_layout_ci.bindingCount = 1;
11757 ds_layout_ci.pBindings = &dsl_binding;
11758
11759 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011760 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011761 ASSERT_VK_SUCCESS(err);
11762
11763 VkDescriptorSet descriptorSet;
11764 VkDescriptorSetAllocateInfo alloc_info = {};
11765 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11766 alloc_info.descriptorSetCount = 1;
11767 alloc_info.descriptorPool = ds_pool;
11768 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011769 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011770 ASSERT_VK_SUCCESS(err);
11771
11772 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011773 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011774 pipe_ms_state_ci.pNext = NULL;
11775 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11776 pipe_ms_state_ci.sampleShadingEnable = 0;
11777 pipe_ms_state_ci.minSampleShading = 1.0;
11778 pipe_ms_state_ci.pSampleMask = NULL;
11779
11780 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11781 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11782 pipeline_layout_ci.pNext = NULL;
11783 pipeline_layout_ci.setLayoutCount = 1;
11784 pipeline_layout_ci.pSetLayouts = &ds_layout;
11785
11786 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011787 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011788 ASSERT_VK_SUCCESS(err);
11789
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011790 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11791 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11792 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011793 VkPipelineObj pipe(m_device);
11794 pipe.AddShader(&vs);
11795 pipe.AddShader(&fs);
11796 pipe.SetMSAA(&pipe_ms_state_ci);
11797 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11798
11799 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011800 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060011801
Mark Young29927482016-05-04 14:38:51 -060011802 // Render triangle (the error should trigger on the attempt to draw).
11803 Draw(3, 1, 0, 0);
11804
11805 // Finalize recording of the command buffer
11806 EndCommandBuffer();
11807
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011808 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011809
11810 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11811 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11812 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11813}
Mark Young29927482016-05-04 14:38:51 -060011814
Mark Muellerd4914412016-06-13 17:52:06 -060011815TEST_F(VkLayerTest, MissingClearAttachment) {
11816 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
11817 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011818 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120011819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesef5e2842016-09-08 15:25:24 +120011820 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0; ignored");
Mark Muellerd4914412016-06-13 17:52:06 -060011821
11822 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11823 m_errorMonitor->VerifyFound();
11824}
11825
Karl Schultz6addd812016-02-02 17:17:23 -070011826TEST_F(VkLayerTest, ClearCmdNoDraw) {
11827 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
11828 // to issuing a Draw
11829 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011830
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11832 "vkCmdClearAttachments() issued on CB object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011833
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011834 ASSERT_NO_FATAL_FAILURE(InitState());
11835 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011836
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011837 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011838 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11839 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011840
11841 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011842 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11843 ds_pool_ci.pNext = NULL;
11844 ds_pool_ci.maxSets = 1;
11845 ds_pool_ci.poolSizeCount = 1;
11846 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011847
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011848 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011849 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011850 ASSERT_VK_SUCCESS(err);
11851
Tony Barboureb254902015-07-15 12:50:33 -060011852 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011853 dsl_binding.binding = 0;
11854 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11855 dsl_binding.descriptorCount = 1;
11856 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11857 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011858
Tony Barboureb254902015-07-15 12:50:33 -060011859 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011860 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11861 ds_layout_ci.pNext = NULL;
11862 ds_layout_ci.bindingCount = 1;
11863 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011864
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011865 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011866 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011867 ASSERT_VK_SUCCESS(err);
11868
11869 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011870 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011871 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011872 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011873 alloc_info.descriptorPool = ds_pool;
11874 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011875 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011876 ASSERT_VK_SUCCESS(err);
11877
Tony Barboureb254902015-07-15 12:50:33 -060011878 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011879 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011880 pipe_ms_state_ci.pNext = NULL;
11881 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11882 pipe_ms_state_ci.sampleShadingEnable = 0;
11883 pipe_ms_state_ci.minSampleShading = 1.0;
11884 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011885
Tony Barboureb254902015-07-15 12:50:33 -060011886 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011887 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11888 pipeline_layout_ci.pNext = NULL;
11889 pipeline_layout_ci.setLayoutCount = 1;
11890 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011891
11892 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011893 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011894 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011895
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011896 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011897 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011898 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011899 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011900
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011901 VkPipelineObj pipe(m_device);
11902 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011903 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011904 pipe.SetMSAA(&pipe_ms_state_ci);
11905 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011906
11907 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011908
Karl Schultz6addd812016-02-02 17:17:23 -070011909 // Main thing we care about for this test is that the VkImage obj we're
11910 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011911 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011912 VkClearAttachment color_attachment;
11913 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11914 color_attachment.clearValue.color.float32[0] = 1.0;
11915 color_attachment.clearValue.color.float32[1] = 1.0;
11916 color_attachment.clearValue.color.float32[2] = 1.0;
11917 color_attachment.clearValue.color.float32[3] = 1.0;
11918 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011919 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011920
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011921 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011922
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011923 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011924
Chia-I Wuf7458c52015-10-26 21:10:41 +080011925 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11926 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11927 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011928}
11929
Karl Schultz6addd812016-02-02 17:17:23 -070011930TEST_F(VkLayerTest, VtxBufferBadIndex) {
11931 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011932
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11934 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011935
Tobin Ehlis502480b2015-06-24 15:53:07 -060011936 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011937 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011938 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011939
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011940 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011941 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11942 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011943
11944 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011945 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11946 ds_pool_ci.pNext = NULL;
11947 ds_pool_ci.maxSets = 1;
11948 ds_pool_ci.poolSizeCount = 1;
11949 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011950
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011951 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011952 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011953 ASSERT_VK_SUCCESS(err);
11954
Tony Barboureb254902015-07-15 12:50:33 -060011955 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011956 dsl_binding.binding = 0;
11957 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11958 dsl_binding.descriptorCount = 1;
11959 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11960 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011961
Tony Barboureb254902015-07-15 12:50:33 -060011962 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011963 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11964 ds_layout_ci.pNext = NULL;
11965 ds_layout_ci.bindingCount = 1;
11966 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011967
Tobin Ehlis502480b2015-06-24 15:53:07 -060011968 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011969 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011970 ASSERT_VK_SUCCESS(err);
11971
11972 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011973 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011974 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011975 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011976 alloc_info.descriptorPool = ds_pool;
11977 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011978 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011979 ASSERT_VK_SUCCESS(err);
11980
Tony Barboureb254902015-07-15 12:50:33 -060011981 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011982 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011983 pipe_ms_state_ci.pNext = NULL;
11984 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11985 pipe_ms_state_ci.sampleShadingEnable = 0;
11986 pipe_ms_state_ci.minSampleShading = 1.0;
11987 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011988
Tony Barboureb254902015-07-15 12:50:33 -060011989 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011990 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11991 pipeline_layout_ci.pNext = NULL;
11992 pipeline_layout_ci.setLayoutCount = 1;
11993 pipeline_layout_ci.pSetLayouts = &ds_layout;
11994 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011995
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011996 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011997 ASSERT_VK_SUCCESS(err);
11998
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011999 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12000 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
12001 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012002 VkPipelineObj pipe(m_device);
12003 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012004 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060012005 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012006 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060012007 pipe.SetViewport(m_viewports);
12008 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012009 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012010
12011 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012012 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012013 // Don't care about actual data, just need to get to draw to flag error
12014 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012015 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012016 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060012017 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012018
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012019 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012020
Chia-I Wuf7458c52015-10-26 21:10:41 +080012021 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12022 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12023 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012024}
Mark Muellerdfe37552016-07-07 14:47:42 -060012025
Mark Mueller2ee294f2016-08-04 12:59:48 -060012026TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
12027 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
12028 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060012029 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012030
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012031 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
12032 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012033
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012034 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
12035 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012036
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012037 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012038
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060012040 // The following test fails with recent NVidia drivers.
12041 // By the time core_validation is reached, the NVidia
12042 // driver has sanitized the invalid condition and core_validation
12043 // is not introduced to the failure condition. This is not the case
12044 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012045 // uint32_t count = static_cast<uint32_t>(~0);
12046 // VkPhysicalDevice physical_device;
12047 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
12048 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012049
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012051 float queue_priority = 0.0;
12052
12053 VkDeviceQueueCreateInfo queue_create_info = {};
12054 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12055 queue_create_info.queueCount = 1;
12056 queue_create_info.pQueuePriorities = &queue_priority;
12057 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
12058
12059 VkPhysicalDeviceFeatures features = m_device->phy().features();
12060 VkDevice testDevice;
12061 VkDeviceCreateInfo device_create_info = {};
12062 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12063 device_create_info.queueCreateInfoCount = 1;
12064 device_create_info.pQueueCreateInfos = &queue_create_info;
12065 device_create_info.pEnabledFeatures = &features;
12066 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12067 m_errorMonitor->VerifyFound();
12068
12069 queue_create_info.queueFamilyIndex = 1;
12070
12071 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12072 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12073 for (unsigned i = 0; i < feature_count; i++) {
12074 if (VK_FALSE == feature_array[i]) {
12075 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012077 device_create_info.pEnabledFeatures = &features;
12078 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12079 m_errorMonitor->VerifyFound();
12080 break;
12081 }
12082 }
12083}
12084
12085TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
12086 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
12087 "End a command buffer with a query still in progress.");
12088
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012089 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12090 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12091 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012092
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012093 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012094
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012096
12097 ASSERT_NO_FATAL_FAILURE(InitState());
12098
12099 VkEvent event;
12100 VkEventCreateInfo event_create_info{};
12101 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12102 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12103
Mark Mueller2ee294f2016-08-04 12:59:48 -060012104 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012105 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012106
12107 BeginCommandBuffer();
12108
12109 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012110 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 -060012111 ASSERT_TRUE(image.initialized());
12112 VkImageMemoryBarrier img_barrier = {};
12113 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12114 img_barrier.pNext = NULL;
12115 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12116 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12117 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12118 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12119 img_barrier.image = image.handle();
12120 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012121
12122 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12123 // that layer validation catches the case when it is not.
12124 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012125 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12126 img_barrier.subresourceRange.baseArrayLayer = 0;
12127 img_barrier.subresourceRange.baseMipLevel = 0;
12128 img_barrier.subresourceRange.layerCount = 1;
12129 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012130 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12131 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012132 m_errorMonitor->VerifyFound();
12133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012135
12136 VkQueryPool query_pool;
12137 VkQueryPoolCreateInfo query_pool_create_info = {};
12138 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12139 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12140 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012141 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012142
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012143 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012144 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12145
12146 vkEndCommandBuffer(m_commandBuffer->handle());
12147 m_errorMonitor->VerifyFound();
12148
12149 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12150 vkDestroyEvent(m_device->device(), event, nullptr);
12151}
12152
Mark Muellerdfe37552016-07-07 14:47:42 -060012153TEST_F(VkLayerTest, VertexBufferInvalid) {
12154 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
12155 "delete a buffer twice, use an invalid offset for each "
12156 "buffer type, and attempt to bind a null buffer");
12157
12158 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
12159 "using deleted buffer ";
12160 const char *double_destroy_message = "Cannot free buffer 0x";
12161 const char *invalid_offset_message = "vkBindBufferMemory(): "
12162 "memoryOffset is 0x";
12163 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
12164 "storage memoryOffset "
12165 "is 0x";
12166 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
12167 "texel memoryOffset "
12168 "is 0x";
12169 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
12170 "uniform memoryOffset "
12171 "is 0x";
12172 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
12173 " to Bind Obj(0x";
12174 const char *free_invalid_buffer_message = "Request to delete memory "
12175 "object 0x";
12176
12177 ASSERT_NO_FATAL_FAILURE(InitState());
12178 ASSERT_NO_FATAL_FAILURE(InitViewport());
12179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12180
12181 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012182 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012183 pipe_ms_state_ci.pNext = NULL;
12184 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12185 pipe_ms_state_ci.sampleShadingEnable = 0;
12186 pipe_ms_state_ci.minSampleShading = 1.0;
12187 pipe_ms_state_ci.pSampleMask = nullptr;
12188
12189 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12190 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12191 VkPipelineLayout pipeline_layout;
12192
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012193 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012194 ASSERT_VK_SUCCESS(err);
12195
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012196 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12197 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012198 VkPipelineObj pipe(m_device);
12199 pipe.AddShader(&vs);
12200 pipe.AddShader(&fs);
12201 pipe.AddColorAttachment();
12202 pipe.SetMSAA(&pipe_ms_state_ci);
12203 pipe.SetViewport(m_viewports);
12204 pipe.SetScissor(m_scissors);
12205 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12206
12207 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012208 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012209
12210 {
12211 // Create and bind a vertex buffer in a reduced scope, which will cause
12212 // it to be deleted upon leaving this scope
12213 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012214 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012215 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12216 draw_verticies.AddVertexInputToPipe(pipe);
12217 }
12218
12219 Draw(1, 0, 0, 0);
12220
12221 EndCommandBuffer();
12222
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012224 QueueCommandBuffer(false);
12225 m_errorMonitor->VerifyFound();
12226
12227 {
12228 // Create and bind a vertex buffer in a reduced scope, and delete it
12229 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012230 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
12231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060012232 buffer_test.TestDoubleDestroy();
12233 }
12234 m_errorMonitor->VerifyFound();
12235
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012236 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012237 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
12239 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12240 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012241 m_errorMonitor->VerifyFound();
12242 }
12243
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012244 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12245 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012246 // Create and bind a memory buffer with an invalid offset again,
12247 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
12249 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12250 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012251 m_errorMonitor->VerifyFound();
12252 }
12253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012254 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012255 // Create and bind a memory buffer with an invalid offset again, but
12256 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
12258 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12259 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012260 m_errorMonitor->VerifyFound();
12261 }
12262
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012263 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012264 // Create and bind a memory buffer with an invalid offset again, but
12265 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
12267 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12268 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012269 m_errorMonitor->VerifyFound();
12270 }
12271
12272 {
12273 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
12275 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12276 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012277 m_errorMonitor->VerifyFound();
12278 }
12279
12280 {
12281 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
12283 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12284 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012285 }
12286 m_errorMonitor->VerifyFound();
12287
12288 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12289}
12290
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012291// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12292TEST_F(VkLayerTest, InvalidImageLayout) {
12293 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012294 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12295 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012296 // 3 in ValidateCmdBufImageLayouts
12297 // * -1 Attempt to submit cmd buf w/ deleted image
12298 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12299 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12301 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012302
12303 ASSERT_NO_FATAL_FAILURE(InitState());
12304 // Create src & dst images to use for copy operations
12305 VkImage src_image;
12306 VkImage dst_image;
12307
12308 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12309 const int32_t tex_width = 32;
12310 const int32_t tex_height = 32;
12311
12312 VkImageCreateInfo image_create_info = {};
12313 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12314 image_create_info.pNext = NULL;
12315 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12316 image_create_info.format = tex_format;
12317 image_create_info.extent.width = tex_width;
12318 image_create_info.extent.height = tex_height;
12319 image_create_info.extent.depth = 1;
12320 image_create_info.mipLevels = 1;
12321 image_create_info.arrayLayers = 4;
12322 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12323 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12324 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
12325 image_create_info.flags = 0;
12326
12327 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12328 ASSERT_VK_SUCCESS(err);
12329 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12330 ASSERT_VK_SUCCESS(err);
12331
12332 BeginCommandBuffer();
12333 VkImageCopy copyRegion;
12334 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12335 copyRegion.srcSubresource.mipLevel = 0;
12336 copyRegion.srcSubresource.baseArrayLayer = 0;
12337 copyRegion.srcSubresource.layerCount = 1;
12338 copyRegion.srcOffset.x = 0;
12339 copyRegion.srcOffset.y = 0;
12340 copyRegion.srcOffset.z = 0;
12341 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12342 copyRegion.dstSubresource.mipLevel = 0;
12343 copyRegion.dstSubresource.baseArrayLayer = 0;
12344 copyRegion.dstSubresource.layerCount = 1;
12345 copyRegion.dstOffset.x = 0;
12346 copyRegion.dstOffset.y = 0;
12347 copyRegion.dstOffset.z = 0;
12348 copyRegion.extent.width = 1;
12349 copyRegion.extent.height = 1;
12350 copyRegion.extent.depth = 1;
12351 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12352 m_errorMonitor->VerifyFound();
12353 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
12355 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12356 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012357 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12358 m_errorMonitor->VerifyFound();
12359 // Final src error is due to bad layout type
12360 m_errorMonitor->SetDesiredFailureMsg(
12361 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12362 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
12363 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12364 m_errorMonitor->VerifyFound();
12365 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12367 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012368 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12369 m_errorMonitor->VerifyFound();
12370 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
12372 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12373 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012374 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12375 m_errorMonitor->VerifyFound();
12376 m_errorMonitor->SetDesiredFailureMsg(
12377 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12378 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
12379 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12380 m_errorMonitor->VerifyFound();
12381 // Now cause error due to bad image layout transition in PipelineBarrier
12382 VkImageMemoryBarrier image_barrier[1] = {};
12383 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12384 image_barrier[0].image = src_image;
12385 image_barrier[0].subresourceRange.layerCount = 2;
12386 image_barrier[0].subresourceRange.levelCount = 2;
12387 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
12389 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
12390 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
12391 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12392 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012393 m_errorMonitor->VerifyFound();
12394
12395 // Finally some layout errors at RenderPass create time
12396 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12397 VkAttachmentReference attach = {};
12398 // perf warning for GENERAL layout w/ non-DS input attachment
12399 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12400 VkSubpassDescription subpass = {};
12401 subpass.inputAttachmentCount = 1;
12402 subpass.pInputAttachments = &attach;
12403 VkRenderPassCreateInfo rpci = {};
12404 rpci.subpassCount = 1;
12405 rpci.pSubpasses = &subpass;
12406 rpci.attachmentCount = 1;
12407 VkAttachmentDescription attach_desc = {};
12408 attach_desc.format = VK_FORMAT_UNDEFINED;
12409 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012410 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012411 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12413 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012414 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12415 m_errorMonitor->VerifyFound();
12416 // error w/ non-general layout
12417 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12418
12419 m_errorMonitor->SetDesiredFailureMsg(
12420 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12421 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12422 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12423 m_errorMonitor->VerifyFound();
12424 subpass.inputAttachmentCount = 0;
12425 subpass.colorAttachmentCount = 1;
12426 subpass.pColorAttachments = &attach;
12427 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12428 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12430 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012431 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12432 m_errorMonitor->VerifyFound();
12433 // error w/ non-color opt or GENERAL layout for color attachment
12434 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12435 m_errorMonitor->SetDesiredFailureMsg(
12436 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12437 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12438 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12439 m_errorMonitor->VerifyFound();
12440 subpass.colorAttachmentCount = 0;
12441 subpass.pDepthStencilAttachment = &attach;
12442 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12443 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12445 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012446 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12447 m_errorMonitor->VerifyFound();
12448 // error w/ non-ds opt or GENERAL layout for color attachment
12449 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12451 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12452 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012453 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12454 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012455 // For this error we need a valid renderpass so create default one
12456 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12457 attach.attachment = 0;
12458 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12459 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12460 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12461 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12462 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12463 // Can't do a CLEAR load on READ_ONLY initialLayout
12464 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12465 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12466 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
12468 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
12469 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012470 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12471 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012472
12473 vkDestroyImage(m_device->device(), src_image, NULL);
12474 vkDestroyImage(m_device->device(), dst_image, NULL);
12475}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012476
12477TEST_F(VkLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
12478 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
12479 "attachment that uses LOAD_OP_CLEAR, the first subpass "
12480 "has a valid layout, and a second subpass then uses a "
12481 "valid *READ_ONLY* layout.");
12482 m_errorMonitor->ExpectSuccess();
12483 ASSERT_NO_FATAL_FAILURE(InitState());
12484
12485 VkAttachmentReference attach[2] = {};
12486 attach[0].attachment = 0;
12487 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
12488 attach[1].attachment = 0;
12489 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12490 VkSubpassDescription subpasses[2] = {};
12491 // First subpass clears DS attach on load
12492 subpasses[0].pDepthStencilAttachment = &attach[0];
12493 // 2nd subpass reads in DS as input attachment
12494 subpasses[1].inputAttachmentCount = 1;
12495 subpasses[1].pInputAttachments = &attach[1];
12496 VkAttachmentDescription attach_desc = {};
12497 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12498 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12499 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12500 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12501 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12502 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012503 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012504 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12505 VkRenderPassCreateInfo rpci = {};
12506 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
12507 rpci.attachmentCount = 1;
12508 rpci.pAttachments = &attach_desc;
12509 rpci.subpassCount = 2;
12510 rpci.pSubpasses = subpasses;
12511
12512 // Now create RenderPass and verify no errors
12513 VkRenderPass rp;
12514 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12515 m_errorMonitor->VerifyNotFound();
12516
12517 vkDestroyRenderPass(m_device->device(), rp, NULL);
12518}
Tobin Ehlis4af23302016-07-19 10:50:30 -060012519
Mark Mueller93b938f2016-08-18 10:27:40 -060012520TEST_F(VkLayerTest, SimultaneousUse) {
12521 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12522 "in primary and secondary command buffers.");
12523
12524 ASSERT_NO_FATAL_FAILURE(InitState());
12525 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12526
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012527 const char *simultaneous_use_message1 = "w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
12528 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12529 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012530
12531 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012532 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012533 command_buffer_allocate_info.commandPool = m_commandPool;
12534 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12535 command_buffer_allocate_info.commandBufferCount = 1;
12536
12537 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012538 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012539 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12540 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012541 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012542 command_buffer_inheritance_info.renderPass = m_renderPass;
12543 command_buffer_inheritance_info.framebuffer = m_framebuffer;
12544 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012545 command_buffer_begin_info.flags =
12546 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012547 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12548
12549 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012550 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12551 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060012552 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012553 vkEndCommandBuffer(secondary_command_buffer);
12554
Mark Mueller93b938f2016-08-18 10:27:40 -060012555 VkSubmitInfo submit_info = {};
12556 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12557 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012558 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060012559 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060012560
Mark Mueller4042b652016-09-05 22:52:21 -060012561 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012562 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12564 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012565 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012566 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12567 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012568
12569 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060012570 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12571
Mark Mueller4042b652016-09-05 22:52:21 -060012572 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012573 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012574 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012575
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12577 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012578 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012579 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12580 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012581}
12582
Mark Mueller917f6bc2016-08-30 10:57:19 -060012583TEST_F(VkLayerTest, InUseDestroyedSignaled) {
12584 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12585 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060012586 "Delete objects that are inuse. Call VkQueueSubmit "
12587 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012588
12589 ASSERT_NO_FATAL_FAILURE(InitState());
12590 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12591
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012592 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
12593 const char *cannot_delete_event_message = "Cannot delete event 0x";
12594 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
12595 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060012596
12597 BeginCommandBuffer();
12598
12599 VkEvent event;
12600 VkEventCreateInfo event_create_info = {};
12601 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12602 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012603 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012604
Mark Muellerc8d441e2016-08-23 17:36:00 -060012605 EndCommandBuffer();
12606 vkDestroyEvent(m_device->device(), event, nullptr);
12607
12608 VkSubmitInfo submit_info = {};
12609 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12610 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012611 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012613 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12614 m_errorMonitor->VerifyFound();
12615
12616 m_errorMonitor->SetDesiredFailureMsg(0, "");
12617 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12618
12619 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12620
Mark Mueller917f6bc2016-08-30 10:57:19 -060012621 VkSemaphoreCreateInfo semaphore_create_info = {};
12622 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12623 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012624 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012625 VkFenceCreateInfo fence_create_info = {};
12626 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12627 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012628 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012629
12630 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012631 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012632 descriptor_pool_type_count.descriptorCount = 1;
12633
12634 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12635 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12636 descriptor_pool_create_info.maxSets = 1;
12637 descriptor_pool_create_info.poolSizeCount = 1;
12638 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012639 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012640
12641 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012642 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012643
12644 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012645 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012646 descriptorset_layout_binding.descriptorCount = 1;
12647 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12648
12649 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012650 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012651 descriptorset_layout_create_info.bindingCount = 1;
12652 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12653
12654 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012655 ASSERT_VK_SUCCESS(
12656 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012657
12658 VkDescriptorSet descriptorset;
12659 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012660 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012661 descriptorset_allocate_info.descriptorSetCount = 1;
12662 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12663 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012664 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012665
Mark Mueller4042b652016-09-05 22:52:21 -060012666 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12667
12668 VkDescriptorBufferInfo buffer_info = {};
12669 buffer_info.buffer = buffer_test.GetBuffer();
12670 buffer_info.offset = 0;
12671 buffer_info.range = 1024;
12672
12673 VkWriteDescriptorSet write_descriptor_set = {};
12674 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12675 write_descriptor_set.dstSet = descriptorset;
12676 write_descriptor_set.descriptorCount = 1;
12677 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12678 write_descriptor_set.pBufferInfo = &buffer_info;
12679
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012680 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012681
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012682 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12683 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012684
12685 VkPipelineObj pipe(m_device);
12686 pipe.AddColorAttachment();
12687 pipe.AddShader(&vs);
12688 pipe.AddShader(&fs);
12689
12690 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012691 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012692 pipeline_layout_create_info.setLayoutCount = 1;
12693 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12694
12695 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012696 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012697
12698 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12699
Mark Muellerc8d441e2016-08-23 17:36:00 -060012700 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012701 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012702
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012703 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12704 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12705 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012706
Mark Muellerc8d441e2016-08-23 17:36:00 -060012707 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012708
Mark Mueller917f6bc2016-08-30 10:57:19 -060012709 submit_info.signalSemaphoreCount = 1;
12710 submit_info.pSignalSemaphores = &semaphore;
12711 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012712
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012714 vkDestroyEvent(m_device->device(), event, nullptr);
12715 m_errorMonitor->VerifyFound();
12716
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012718 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12719 m_errorMonitor->VerifyFound();
12720
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012722 vkDestroyFence(m_device->device(), fence, nullptr);
12723 m_errorMonitor->VerifyFound();
12724
Tobin Ehlis122207b2016-09-01 08:50:06 -070012725 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012726 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12727 vkDestroyFence(m_device->device(), fence, nullptr);
12728 vkDestroyEvent(m_device->device(), event, nullptr);
12729 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012730 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012731 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12732}
12733
Tobin Ehlis2adda372016-09-01 08:51:06 -070012734TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12735 TEST_DESCRIPTION("Delete in-use query pool.");
12736
12737 ASSERT_NO_FATAL_FAILURE(InitState());
12738 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12739
12740 VkQueryPool query_pool;
12741 VkQueryPoolCreateInfo query_pool_ci{};
12742 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12743 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12744 query_pool_ci.queryCount = 1;
12745 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
12746 BeginCommandBuffer();
12747 // Reset query pool to create binding with cmd buffer
12748 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12749
12750 EndCommandBuffer();
12751
12752 VkSubmitInfo submit_info = {};
12753 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12754 submit_info.commandBufferCount = 1;
12755 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12756 // Submit cmd buffer and then destroy query pool while in-flight
12757 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12758
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012760 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12761 m_errorMonitor->VerifyFound();
12762
12763 vkQueueWaitIdle(m_device->m_queue);
12764 // Now that cmd buffer done we can safely destroy query_pool
12765 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12766}
12767
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012768TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12769 TEST_DESCRIPTION("Delete in-use pipeline.");
12770
12771 ASSERT_NO_FATAL_FAILURE(InitState());
12772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12773
12774 // Empty pipeline layout used for binding PSO
12775 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12776 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12777 pipeline_layout_ci.setLayoutCount = 0;
12778 pipeline_layout_ci.pSetLayouts = NULL;
12779
12780 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012781 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012782 ASSERT_VK_SUCCESS(err);
12783
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012785 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012786 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12787 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012788 // Store pipeline handle so we can actually delete it before test finishes
12789 VkPipeline delete_this_pipeline;
12790 { // Scope pipeline so it will be auto-deleted
12791 VkPipelineObj pipe(m_device);
12792 pipe.AddShader(&vs);
12793 pipe.AddShader(&fs);
12794 pipe.AddColorAttachment();
12795 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12796 delete_this_pipeline = pipe.handle();
12797
12798 BeginCommandBuffer();
12799 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012800 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012801
12802 EndCommandBuffer();
12803
12804 VkSubmitInfo submit_info = {};
12805 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12806 submit_info.commandBufferCount = 1;
12807 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12808 // Submit cmd buffer and then pipeline destroyed while in-flight
12809 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12810 } // Pipeline deletion triggered here
12811 m_errorMonitor->VerifyFound();
12812 // Make sure queue finished and then actually delete pipeline
12813 vkQueueWaitIdle(m_device->m_queue);
12814 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12815 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12816}
12817
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012818TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12819 TEST_DESCRIPTION("Delete in-use imageView.");
12820
12821 ASSERT_NO_FATAL_FAILURE(InitState());
12822 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12823
12824 VkDescriptorPoolSize ds_type_count;
12825 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12826 ds_type_count.descriptorCount = 1;
12827
12828 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12829 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12830 ds_pool_ci.maxSets = 1;
12831 ds_pool_ci.poolSizeCount = 1;
12832 ds_pool_ci.pPoolSizes = &ds_type_count;
12833
12834 VkDescriptorPool ds_pool;
12835 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12836 ASSERT_VK_SUCCESS(err);
12837
12838 VkSamplerCreateInfo sampler_ci = {};
12839 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12840 sampler_ci.pNext = NULL;
12841 sampler_ci.magFilter = VK_FILTER_NEAREST;
12842 sampler_ci.minFilter = VK_FILTER_NEAREST;
12843 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12844 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12845 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12846 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12847 sampler_ci.mipLodBias = 1.0;
12848 sampler_ci.anisotropyEnable = VK_FALSE;
12849 sampler_ci.maxAnisotropy = 1;
12850 sampler_ci.compareEnable = VK_FALSE;
12851 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12852 sampler_ci.minLod = 1.0;
12853 sampler_ci.maxLod = 1.0;
12854 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12855 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12856 VkSampler sampler;
12857
12858 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12859 ASSERT_VK_SUCCESS(err);
12860
12861 VkDescriptorSetLayoutBinding layout_binding;
12862 layout_binding.binding = 0;
12863 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12864 layout_binding.descriptorCount = 1;
12865 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12866 layout_binding.pImmutableSamplers = NULL;
12867
12868 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12869 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12870 ds_layout_ci.bindingCount = 1;
12871 ds_layout_ci.pBindings = &layout_binding;
12872 VkDescriptorSetLayout ds_layout;
12873 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12874 ASSERT_VK_SUCCESS(err);
12875
12876 VkDescriptorSetAllocateInfo alloc_info = {};
12877 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12878 alloc_info.descriptorSetCount = 1;
12879 alloc_info.descriptorPool = ds_pool;
12880 alloc_info.pSetLayouts = &ds_layout;
12881 VkDescriptorSet descriptor_set;
12882 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12883 ASSERT_VK_SUCCESS(err);
12884
12885 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12886 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12887 pipeline_layout_ci.pNext = NULL;
12888 pipeline_layout_ci.setLayoutCount = 1;
12889 pipeline_layout_ci.pSetLayouts = &ds_layout;
12890
12891 VkPipelineLayout pipeline_layout;
12892 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12893 ASSERT_VK_SUCCESS(err);
12894
12895 VkImageObj image(m_device);
12896 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12897 ASSERT_TRUE(image.initialized());
12898
12899 VkImageView view;
12900 VkImageViewCreateInfo ivci = {};
12901 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12902 ivci.image = image.handle();
12903 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12904 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12905 ivci.subresourceRange.layerCount = 1;
12906 ivci.subresourceRange.baseMipLevel = 0;
12907 ivci.subresourceRange.levelCount = 1;
12908 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12909
12910 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12911 ASSERT_VK_SUCCESS(err);
12912
12913 VkDescriptorImageInfo image_info{};
12914 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12915 image_info.imageView = view;
12916 image_info.sampler = sampler;
12917
12918 VkWriteDescriptorSet descriptor_write = {};
12919 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12920 descriptor_write.dstSet = descriptor_set;
12921 descriptor_write.dstBinding = 0;
12922 descriptor_write.descriptorCount = 1;
12923 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12924 descriptor_write.pImageInfo = &image_info;
12925
12926 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12927
12928 // Create PSO to use the sampler
12929 char const *vsSource = "#version 450\n"
12930 "\n"
12931 "out gl_PerVertex { \n"
12932 " vec4 gl_Position;\n"
12933 "};\n"
12934 "void main(){\n"
12935 " gl_Position = vec4(1);\n"
12936 "}\n";
12937 char const *fsSource = "#version 450\n"
12938 "\n"
12939 "layout(set=0, binding=0) uniform sampler2D s;\n"
12940 "layout(location=0) out vec4 x;\n"
12941 "void main(){\n"
12942 " x = texture(s, vec2(1));\n"
12943 "}\n";
12944 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12945 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12946 VkPipelineObj pipe(m_device);
12947 pipe.AddShader(&vs);
12948 pipe.AddShader(&fs);
12949 pipe.AddColorAttachment();
12950 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12951
12952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
12953
12954 BeginCommandBuffer();
12955 // Bind pipeline to cmd buffer
12956 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12957 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12958 &descriptor_set, 0, nullptr);
12959 Draw(1, 0, 0, 0);
12960 EndCommandBuffer();
12961 // Submit cmd buffer then destroy sampler
12962 VkSubmitInfo submit_info = {};
12963 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12964 submit_info.commandBufferCount = 1;
12965 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12966 // Submit cmd buffer and then destroy imageView while in-flight
12967 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12968
12969 vkDestroyImageView(m_device->device(), view, nullptr);
12970 m_errorMonitor->VerifyFound();
12971 vkQueueWaitIdle(m_device->m_queue);
12972 // Now we can actually destroy imageView
12973 vkDestroyImageView(m_device->device(), view, NULL);
12974 vkDestroySampler(m_device->device(), sampler, nullptr);
12975 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12976 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12977 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12978}
12979
Tobin Ehlis209532e2016-09-07 13:52:18 -060012980TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12981 TEST_DESCRIPTION("Delete in-use sampler.");
12982
12983 ASSERT_NO_FATAL_FAILURE(InitState());
12984 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12985
12986 VkDescriptorPoolSize ds_type_count;
12987 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12988 ds_type_count.descriptorCount = 1;
12989
12990 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12991 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12992 ds_pool_ci.maxSets = 1;
12993 ds_pool_ci.poolSizeCount = 1;
12994 ds_pool_ci.pPoolSizes = &ds_type_count;
12995
12996 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012997 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012998 ASSERT_VK_SUCCESS(err);
12999
13000 VkSamplerCreateInfo sampler_ci = {};
13001 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13002 sampler_ci.pNext = NULL;
13003 sampler_ci.magFilter = VK_FILTER_NEAREST;
13004 sampler_ci.minFilter = VK_FILTER_NEAREST;
13005 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13006 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13007 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13008 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13009 sampler_ci.mipLodBias = 1.0;
13010 sampler_ci.anisotropyEnable = VK_FALSE;
13011 sampler_ci.maxAnisotropy = 1;
13012 sampler_ci.compareEnable = VK_FALSE;
13013 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13014 sampler_ci.minLod = 1.0;
13015 sampler_ci.maxLod = 1.0;
13016 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13017 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13018 VkSampler sampler;
13019
13020 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13021 ASSERT_VK_SUCCESS(err);
13022
13023 VkDescriptorSetLayoutBinding layout_binding;
13024 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060013025 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060013026 layout_binding.descriptorCount = 1;
13027 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13028 layout_binding.pImmutableSamplers = NULL;
13029
13030 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13031 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13032 ds_layout_ci.bindingCount = 1;
13033 ds_layout_ci.pBindings = &layout_binding;
13034 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013035 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013036 ASSERT_VK_SUCCESS(err);
13037
13038 VkDescriptorSetAllocateInfo alloc_info = {};
13039 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13040 alloc_info.descriptorSetCount = 1;
13041 alloc_info.descriptorPool = ds_pool;
13042 alloc_info.pSetLayouts = &ds_layout;
13043 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013044 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013045 ASSERT_VK_SUCCESS(err);
13046
13047 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13048 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13049 pipeline_layout_ci.pNext = NULL;
13050 pipeline_layout_ci.setLayoutCount = 1;
13051 pipeline_layout_ci.pSetLayouts = &ds_layout;
13052
13053 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013054 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013055 ASSERT_VK_SUCCESS(err);
13056
13057 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013058 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 -060013059 ASSERT_TRUE(image.initialized());
13060
13061 VkImageView view;
13062 VkImageViewCreateInfo ivci = {};
13063 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13064 ivci.image = image.handle();
13065 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13066 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13067 ivci.subresourceRange.layerCount = 1;
13068 ivci.subresourceRange.baseMipLevel = 0;
13069 ivci.subresourceRange.levelCount = 1;
13070 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13071
13072 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13073 ASSERT_VK_SUCCESS(err);
13074
13075 VkDescriptorImageInfo image_info{};
13076 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13077 image_info.imageView = view;
13078 image_info.sampler = sampler;
13079
13080 VkWriteDescriptorSet descriptor_write = {};
13081 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13082 descriptor_write.dstSet = descriptor_set;
13083 descriptor_write.dstBinding = 0;
13084 descriptor_write.descriptorCount = 1;
13085 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13086 descriptor_write.pImageInfo = &image_info;
13087
13088 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13089
13090 // Create PSO to use the sampler
13091 char const *vsSource = "#version 450\n"
13092 "\n"
13093 "out gl_PerVertex { \n"
13094 " vec4 gl_Position;\n"
13095 "};\n"
13096 "void main(){\n"
13097 " gl_Position = vec4(1);\n"
13098 "}\n";
13099 char const *fsSource = "#version 450\n"
13100 "\n"
13101 "layout(set=0, binding=0) uniform sampler2D s;\n"
13102 "layout(location=0) out vec4 x;\n"
13103 "void main(){\n"
13104 " x = texture(s, vec2(1));\n"
13105 "}\n";
13106 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13107 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13108 VkPipelineObj pipe(m_device);
13109 pipe.AddShader(&vs);
13110 pipe.AddShader(&fs);
13111 pipe.AddColorAttachment();
13112 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13113
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060013115
13116 BeginCommandBuffer();
13117 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013118 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13119 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13120 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013121 Draw(1, 0, 0, 0);
13122 EndCommandBuffer();
13123 // Submit cmd buffer then destroy sampler
13124 VkSubmitInfo submit_info = {};
13125 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13126 submit_info.commandBufferCount = 1;
13127 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13128 // Submit cmd buffer and then destroy sampler while in-flight
13129 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13130
13131 vkDestroySampler(m_device->device(), sampler, nullptr);
13132 m_errorMonitor->VerifyFound();
13133 vkQueueWaitIdle(m_device->m_queue);
13134 // Now we can actually destroy sampler
13135 vkDestroySampler(m_device->device(), sampler, nullptr);
13136 vkDestroyImageView(m_device->device(), view, NULL);
13137 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13138 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13139 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13140}
13141
Mark Mueller1cd9f412016-08-25 13:23:52 -060013142TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060013143 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060013144 "signaled but not waited on by the queue. Wait on a "
13145 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060013146
13147 ASSERT_NO_FATAL_FAILURE(InitState());
13148 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013150 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
13151 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
13152 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060013153
13154 BeginCommandBuffer();
13155 EndCommandBuffer();
13156
13157 VkSemaphoreCreateInfo semaphore_create_info = {};
13158 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13159 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013160 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060013161 VkSubmitInfo submit_info = {};
13162 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13163 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013164 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060013165 submit_info.signalSemaphoreCount = 1;
13166 submit_info.pSignalSemaphores = &semaphore;
13167 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13168 m_errorMonitor->SetDesiredFailureMsg(0, "");
13169 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
13170 BeginCommandBuffer();
13171 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060013173 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13174 m_errorMonitor->VerifyFound();
13175
Mark Mueller1cd9f412016-08-25 13:23:52 -060013176 VkFenceCreateInfo fence_create_info = {};
13177 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13178 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013179 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013180
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013182 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13183 m_errorMonitor->VerifyFound();
13184
Mark Mueller4042b652016-09-05 22:52:21 -060013185 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013186 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013187 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13188}
13189
Tobin Ehlis4af23302016-07-19 10:50:30 -060013190TEST_F(VkLayerTest, FramebufferIncompatible) {
13191 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
13192 "that does not match the framebuffer for the active "
13193 "renderpass.");
13194 ASSERT_NO_FATAL_FAILURE(InitState());
13195 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13196
13197 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013198 VkAttachmentDescription attachment = {0,
13199 VK_FORMAT_B8G8R8A8_UNORM,
13200 VK_SAMPLE_COUNT_1_BIT,
13201 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13202 VK_ATTACHMENT_STORE_OP_STORE,
13203 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13204 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13205 VK_IMAGE_LAYOUT_UNDEFINED,
13206 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013207
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013208 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013209
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013210 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013211
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013212 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013213
13214 VkRenderPass rp;
13215 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13216 ASSERT_VK_SUCCESS(err);
13217
13218 // A compatible framebuffer.
13219 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013220 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 -060013221 ASSERT_TRUE(image.initialized());
13222
13223 VkImageViewCreateInfo ivci = {
13224 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13225 nullptr,
13226 0,
13227 image.handle(),
13228 VK_IMAGE_VIEW_TYPE_2D,
13229 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013230 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13231 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013232 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13233 };
13234 VkImageView view;
13235 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13236 ASSERT_VK_SUCCESS(err);
13237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013238 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013239 VkFramebuffer fb;
13240 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13241 ASSERT_VK_SUCCESS(err);
13242
13243 VkCommandBufferAllocateInfo cbai = {};
13244 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13245 cbai.commandPool = m_commandPool;
13246 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13247 cbai.commandBufferCount = 1;
13248
13249 VkCommandBuffer sec_cb;
13250 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13251 ASSERT_VK_SUCCESS(err);
13252 VkCommandBufferBeginInfo cbbi = {};
13253 VkCommandBufferInheritanceInfo cbii = {};
13254 cbii.renderPass = renderPass();
13255 cbii.framebuffer = fb;
13256 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13257 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013258 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 -060013259 cbbi.pInheritanceInfo = &cbii;
13260 vkBeginCommandBuffer(sec_cb, &cbbi);
13261 vkEndCommandBuffer(sec_cb);
13262
Chris Forbes3400bc52016-09-13 18:10:34 +120013263 VkCommandBufferBeginInfo cbbi2 = {
13264 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13265 0, nullptr
13266 };
13267 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13268 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013269
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13271 " that is not the same as the primaryCB's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013272 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13273 m_errorMonitor->VerifyFound();
13274 // Cleanup
13275 vkDestroyImageView(m_device->device(), view, NULL);
13276 vkDestroyRenderPass(m_device->device(), rp, NULL);
13277 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13278}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013279
13280TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
13281 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
13282 "invalid value. If logicOp is not available, attempt to "
13283 "use it and verify that we see the correct error.");
13284 ASSERT_NO_FATAL_FAILURE(InitState());
13285 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13286
13287 auto features = m_device->phy().features();
13288 // Set the expected error depending on whether or not logicOp available
13289 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
13291 "enabled, logicOpEnable must be "
13292 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013293 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ", logicOp must be a valid VkLogicOp value");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013295 }
13296 // Create a pipeline using logicOp
13297 VkResult err;
13298
13299 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13300 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13301
13302 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013303 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013304 ASSERT_VK_SUCCESS(err);
13305
13306 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13307 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13308 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013309 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013310 vp_state_ci.pViewports = &vp;
13311 vp_state_ci.scissorCount = 1;
13312 VkRect2D scissors = {}; // Dummy scissors to point to
13313 vp_state_ci.pScissors = &scissors;
13314 // No dynamic state
13315 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
13316 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13317
13318 VkPipelineShaderStageCreateInfo shaderStages[2];
13319 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13320
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013321 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13322 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013323 shaderStages[0] = vs.GetStageCreateInfo();
13324 shaderStages[1] = fs.GetStageCreateInfo();
13325
13326 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13327 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13328
13329 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13330 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13331 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13332
13333 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13334 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13335
13336 VkPipelineColorBlendAttachmentState att = {};
13337 att.blendEnable = VK_FALSE;
13338 att.colorWriteMask = 0xf;
13339
13340 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13341 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13342 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13343 cb_ci.logicOpEnable = VK_TRUE;
13344 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
13345 cb_ci.attachmentCount = 1;
13346 cb_ci.pAttachments = &att;
13347
13348 VkGraphicsPipelineCreateInfo gp_ci = {};
13349 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13350 gp_ci.stageCount = 2;
13351 gp_ci.pStages = shaderStages;
13352 gp_ci.pVertexInputState = &vi_ci;
13353 gp_ci.pInputAssemblyState = &ia_ci;
13354 gp_ci.pViewportState = &vp_state_ci;
13355 gp_ci.pRasterizationState = &rs_ci;
13356 gp_ci.pColorBlendState = &cb_ci;
13357 gp_ci.pDynamicState = &dyn_state_ci;
13358 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13359 gp_ci.layout = pipeline_layout;
13360 gp_ci.renderPass = renderPass();
13361
13362 VkPipelineCacheCreateInfo pc_ci = {};
13363 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13364
13365 VkPipeline pipeline;
13366 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013367 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013368 ASSERT_VK_SUCCESS(err);
13369
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013370 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013371 m_errorMonitor->VerifyFound();
13372 if (VK_SUCCESS == err) {
13373 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13374 }
13375 m_errorMonitor->VerifyFound();
13376 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13377 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13378}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013379#endif // DRAW_STATE_TESTS
13380
Tobin Ehlis0788f522015-05-26 16:11:58 -060013381#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060013382#if GTEST_IS_THREADSAFE
13383struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013384 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013385 VkEvent event;
13386 bool bailout;
13387};
13388
Karl Schultz6addd812016-02-02 17:17:23 -070013389extern "C" void *AddToCommandBuffer(void *arg) {
13390 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013391
Mike Stroyana6d14942016-07-13 15:10:05 -060013392 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013393 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013394 if (data->bailout) {
13395 break;
13396 }
13397 }
13398 return NULL;
13399}
13400
Karl Schultz6addd812016-02-02 17:17:23 -070013401TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013402 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013403
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013405
Mike Stroyanaccf7692015-05-12 16:00:45 -060013406 ASSERT_NO_FATAL_FAILURE(InitState());
13407 ASSERT_NO_FATAL_FAILURE(InitViewport());
13408 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13409
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013410 // Calls AllocateCommandBuffers
13411 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013412
13413 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013414 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013415
13416 VkEventCreateInfo event_info;
13417 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013418 VkResult err;
13419
13420 memset(&event_info, 0, sizeof(event_info));
13421 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13422
Chia-I Wuf7458c52015-10-26 21:10:41 +080013423 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013424 ASSERT_VK_SUCCESS(err);
13425
Mike Stroyanaccf7692015-05-12 16:00:45 -060013426 err = vkResetEvent(device(), event);
13427 ASSERT_VK_SUCCESS(err);
13428
13429 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013430 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013431 data.event = event;
13432 data.bailout = false;
13433 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013434
13435 // First do some correct operations using multiple threads.
13436 // Add many entries to command buffer from another thread.
13437 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13438 // Make non-conflicting calls from this thread at the same time.
13439 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013440 uint32_t count;
13441 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013442 }
13443 test_platform_thread_join(thread, NULL);
13444
13445 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013446 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013447 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013448 // Add many entries to command buffer from this thread at the same time.
13449 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013450
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013451 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013452 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013453
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013454 m_errorMonitor->SetBailout(NULL);
13455
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013456 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013457
Chia-I Wuf7458c52015-10-26 21:10:41 +080013458 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013459}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013460#endif // GTEST_IS_THREADSAFE
13461#endif // THREADING_TESTS
13462
Chris Forbes9f7ff632015-05-25 11:13:08 +120013463#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070013464TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013465 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13466 "with an impossible code size");
13467
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013469
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013470 ASSERT_NO_FATAL_FAILURE(InitState());
13471 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13472
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013473 VkShaderModule module;
13474 VkShaderModuleCreateInfo moduleCreateInfo;
13475 struct icd_spv_header spv;
13476
13477 spv.magic = ICD_SPV_MAGIC;
13478 spv.version = ICD_SPV_VERSION;
13479 spv.gen_magic = 0;
13480
13481 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13482 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013483 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013484 moduleCreateInfo.codeSize = 4;
13485 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013486 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013487
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013488 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013489}
13490
Karl Schultz6addd812016-02-02 17:17:23 -070013491TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013492 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13493 "with a bad magic number");
13494
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013496
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013497 ASSERT_NO_FATAL_FAILURE(InitState());
13498 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13499
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013500 VkShaderModule module;
13501 VkShaderModuleCreateInfo moduleCreateInfo;
13502 struct icd_spv_header spv;
13503
13504 spv.magic = ~ICD_SPV_MAGIC;
13505 spv.version = ICD_SPV_VERSION;
13506 spv.gen_magic = 0;
13507
13508 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13509 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013510 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013511 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13512 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013513 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013514
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013515 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013516}
13517
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013518#if 0
13519// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013520TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013522 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013523
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013524 ASSERT_NO_FATAL_FAILURE(InitState());
13525 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13526
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013527 VkShaderModule module;
13528 VkShaderModuleCreateInfo moduleCreateInfo;
13529 struct icd_spv_header spv;
13530
13531 spv.magic = ICD_SPV_MAGIC;
13532 spv.version = ~ICD_SPV_VERSION;
13533 spv.gen_magic = 0;
13534
13535 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13536 moduleCreateInfo.pNext = NULL;
13537
Karl Schultz6addd812016-02-02 17:17:23 -070013538 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013539 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13540 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013541 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013542
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013543 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013544}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013545#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013546
Karl Schultz6addd812016-02-02 17:17:23 -070013547TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013548 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
13549 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013551
Chris Forbes9f7ff632015-05-25 11:13:08 +120013552 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013553 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013554
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013555 char const *vsSource = "#version 450\n"
13556 "\n"
13557 "layout(location=0) out float x;\n"
13558 "out gl_PerVertex {\n"
13559 " vec4 gl_Position;\n"
13560 "};\n"
13561 "void main(){\n"
13562 " gl_Position = vec4(1);\n"
13563 " x = 0;\n"
13564 "}\n";
13565 char const *fsSource = "#version 450\n"
13566 "\n"
13567 "layout(location=0) out vec4 color;\n"
13568 "void main(){\n"
13569 " color = vec4(1);\n"
13570 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013571
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013572 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13573 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013574
13575 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013576 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013577 pipe.AddShader(&vs);
13578 pipe.AddShader(&fs);
13579
Chris Forbes9f7ff632015-05-25 11:13:08 +120013580 VkDescriptorSetObj descriptorSet(m_device);
13581 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013582 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013583
Tony Barbour5781e8f2015-08-04 16:23:11 -060013584 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013585
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013586 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013587}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013588
Karl Schultz6addd812016-02-02 17:17:23 -070013589TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013590 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13591 "which is not present in the outputs of the previous stage");
13592
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013594
Chris Forbes59cb88d2015-05-25 11:13:13 +120013595 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013596 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013597
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013598 char const *vsSource = "#version 450\n"
13599 "\n"
13600 "out gl_PerVertex {\n"
13601 " vec4 gl_Position;\n"
13602 "};\n"
13603 "void main(){\n"
13604 " gl_Position = vec4(1);\n"
13605 "}\n";
13606 char const *fsSource = "#version 450\n"
13607 "\n"
13608 "layout(location=0) in float x;\n"
13609 "layout(location=0) out vec4 color;\n"
13610 "void main(){\n"
13611 " color = vec4(x);\n"
13612 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013613
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013614 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13615 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013616
13617 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013618 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013619 pipe.AddShader(&vs);
13620 pipe.AddShader(&fs);
13621
Chris Forbes59cb88d2015-05-25 11:13:13 +120013622 VkDescriptorSetObj descriptorSet(m_device);
13623 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013624 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013625
Tony Barbour5781e8f2015-08-04 16:23:11 -060013626 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013627
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013628 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013629}
13630
Karl Schultz6addd812016-02-02 17:17:23 -070013631TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013632 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13633 "within an interace block, which is not present in the outputs "
13634 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013636
13637 ASSERT_NO_FATAL_FAILURE(InitState());
13638 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13639
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013640 char const *vsSource = "#version 450\n"
13641 "\n"
13642 "out gl_PerVertex {\n"
13643 " vec4 gl_Position;\n"
13644 "};\n"
13645 "void main(){\n"
13646 " gl_Position = vec4(1);\n"
13647 "}\n";
13648 char const *fsSource = "#version 450\n"
13649 "\n"
13650 "in block { layout(location=0) float x; } ins;\n"
13651 "layout(location=0) out vec4 color;\n"
13652 "void main(){\n"
13653 " color = vec4(ins.x);\n"
13654 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013655
13656 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13657 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13658
13659 VkPipelineObj pipe(m_device);
13660 pipe.AddColorAttachment();
13661 pipe.AddShader(&vs);
13662 pipe.AddShader(&fs);
13663
13664 VkDescriptorSetObj descriptorSet(m_device);
13665 descriptorSet.AppendDummy();
13666 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13667
13668 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13669
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013670 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013671}
13672
Karl Schultz6addd812016-02-02 17:17:23 -070013673TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013674 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
13675 "across the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
13677 "output arr[2] of float32' vs 'ptr to "
13678 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013679
13680 ASSERT_NO_FATAL_FAILURE(InitState());
13681 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13682
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013683 char const *vsSource = "#version 450\n"
13684 "\n"
13685 "layout(location=0) out float x[2];\n"
13686 "out gl_PerVertex {\n"
13687 " vec4 gl_Position;\n"
13688 "};\n"
13689 "void main(){\n"
13690 " x[0] = 0; x[1] = 0;\n"
13691 " gl_Position = vec4(1);\n"
13692 "}\n";
13693 char const *fsSource = "#version 450\n"
13694 "\n"
13695 "layout(location=0) in float x[3];\n"
13696 "layout(location=0) out vec4 color;\n"
13697 "void main(){\n"
13698 " color = vec4(x[0] + x[1] + x[2]);\n"
13699 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013700
13701 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13702 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13703
13704 VkPipelineObj pipe(m_device);
13705 pipe.AddColorAttachment();
13706 pipe.AddShader(&vs);
13707 pipe.AddShader(&fs);
13708
13709 VkDescriptorSetObj descriptorSet(m_device);
13710 descriptorSet.AppendDummy();
13711 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13712
13713 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13714
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013715 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013716}
13717
Karl Schultz6addd812016-02-02 17:17:23 -070013718TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013719 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13720 "the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013722
Chris Forbesb56af562015-05-25 11:13:17 +120013723 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013724 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013725
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013726 char const *vsSource = "#version 450\n"
13727 "\n"
13728 "layout(location=0) out int x;\n"
13729 "out gl_PerVertex {\n"
13730 " vec4 gl_Position;\n"
13731 "};\n"
13732 "void main(){\n"
13733 " x = 0;\n"
13734 " gl_Position = vec4(1);\n"
13735 "}\n";
13736 char const *fsSource = "#version 450\n"
13737 "\n"
13738 "layout(location=0) in float x;\n" /* VS writes int */
13739 "layout(location=0) out vec4 color;\n"
13740 "void main(){\n"
13741 " color = vec4(x);\n"
13742 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013743
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013744 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13745 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013746
13747 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013748 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013749 pipe.AddShader(&vs);
13750 pipe.AddShader(&fs);
13751
Chris Forbesb56af562015-05-25 11:13:17 +120013752 VkDescriptorSetObj descriptorSet(m_device);
13753 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013754 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013755
Tony Barbour5781e8f2015-08-04 16:23:11 -060013756 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013757
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013758 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013759}
13760
Karl Schultz6addd812016-02-02 17:17:23 -070013761TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013762 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13763 "the VS->FS interface, when the variable is contained within "
13764 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013766
13767 ASSERT_NO_FATAL_FAILURE(InitState());
13768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13769
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013770 char const *vsSource = "#version 450\n"
13771 "\n"
13772 "out block { layout(location=0) int x; } outs;\n"
13773 "out gl_PerVertex {\n"
13774 " vec4 gl_Position;\n"
13775 "};\n"
13776 "void main(){\n"
13777 " outs.x = 0;\n"
13778 " gl_Position = vec4(1);\n"
13779 "}\n";
13780 char const *fsSource = "#version 450\n"
13781 "\n"
13782 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13783 "layout(location=0) out vec4 color;\n"
13784 "void main(){\n"
13785 " color = vec4(ins.x);\n"
13786 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013787
13788 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13789 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13790
13791 VkPipelineObj pipe(m_device);
13792 pipe.AddColorAttachment();
13793 pipe.AddShader(&vs);
13794 pipe.AddShader(&fs);
13795
13796 VkDescriptorSetObj descriptorSet(m_device);
13797 descriptorSet.AppendDummy();
13798 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13799
13800 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13801
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013802 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013803}
13804
13805TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013806 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
13807 "the VS->FS interface; This should manifest as a not-written/not-consumed "
13808 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013809 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 +130013810
13811 ASSERT_NO_FATAL_FAILURE(InitState());
13812 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13813
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013814 char const *vsSource = "#version 450\n"
13815 "\n"
13816 "out block { layout(location=1) float x; } outs;\n"
13817 "out gl_PerVertex {\n"
13818 " vec4 gl_Position;\n"
13819 "};\n"
13820 "void main(){\n"
13821 " outs.x = 0;\n"
13822 " gl_Position = vec4(1);\n"
13823 "}\n";
13824 char const *fsSource = "#version 450\n"
13825 "\n"
13826 "in block { layout(location=0) float x; } ins;\n"
13827 "layout(location=0) out vec4 color;\n"
13828 "void main(){\n"
13829 " color = vec4(ins.x);\n"
13830 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013831
13832 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13833 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13834
13835 VkPipelineObj pipe(m_device);
13836 pipe.AddColorAttachment();
13837 pipe.AddShader(&vs);
13838 pipe.AddShader(&fs);
13839
13840 VkDescriptorSetObj descriptorSet(m_device);
13841 descriptorSet.AppendDummy();
13842 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13843
13844 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13845
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013846 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013847}
13848
13849TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013850 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
13851 "VS->FS interface. It's not enough to have the same set of locations in "
13852 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013853 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 +130013854
13855 ASSERT_NO_FATAL_FAILURE(InitState());
13856 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13857
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013858 char const *vsSource = "#version 450\n"
13859 "\n"
13860 "out block { layout(location=0, component=0) float x; } outs;\n"
13861 "out gl_PerVertex {\n"
13862 " vec4 gl_Position;\n"
13863 "};\n"
13864 "void main(){\n"
13865 " outs.x = 0;\n"
13866 " gl_Position = vec4(1);\n"
13867 "}\n";
13868 char const *fsSource = "#version 450\n"
13869 "\n"
13870 "in block { layout(location=0, component=1) float x; } ins;\n"
13871 "layout(location=0) out vec4 color;\n"
13872 "void main(){\n"
13873 " color = vec4(ins.x);\n"
13874 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013875
13876 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13877 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13878
13879 VkPipelineObj pipe(m_device);
13880 pipe.AddColorAttachment();
13881 pipe.AddShader(&vs);
13882 pipe.AddShader(&fs);
13883
13884 VkDescriptorSetObj descriptorSet(m_device);
13885 descriptorSet.AppendDummy();
13886 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13887
13888 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13889
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013890 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013891}
13892
Karl Schultz6addd812016-02-02 17:17:23 -070013893TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013894 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13895 "not consumed by the vertex shader");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013897
Chris Forbesde136e02015-05-25 11:13:28 +120013898 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013899 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013900
13901 VkVertexInputBindingDescription input_binding;
13902 memset(&input_binding, 0, sizeof(input_binding));
13903
13904 VkVertexInputAttributeDescription input_attrib;
13905 memset(&input_attrib, 0, sizeof(input_attrib));
13906 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13907
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013908 char const *vsSource = "#version 450\n"
13909 "\n"
13910 "out gl_PerVertex {\n"
13911 " vec4 gl_Position;\n"
13912 "};\n"
13913 "void main(){\n"
13914 " gl_Position = vec4(1);\n"
13915 "}\n";
13916 char const *fsSource = "#version 450\n"
13917 "\n"
13918 "layout(location=0) out vec4 color;\n"
13919 "void main(){\n"
13920 " color = vec4(1);\n"
13921 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013922
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013923 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13924 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013925
13926 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013927 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013928 pipe.AddShader(&vs);
13929 pipe.AddShader(&fs);
13930
13931 pipe.AddVertexInputBindings(&input_binding, 1);
13932 pipe.AddVertexInputAttribs(&input_attrib, 1);
13933
Chris Forbesde136e02015-05-25 11:13:28 +120013934 VkDescriptorSetObj descriptorSet(m_device);
13935 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013936 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013937
Tony Barbour5781e8f2015-08-04 16:23:11 -060013938 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013939
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013940 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013941}
13942
Karl Schultz6addd812016-02-02 17:17:23 -070013943TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013944 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13945 "vertex attributes. This flushes out bad behavior in the interface walker");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013947
13948 ASSERT_NO_FATAL_FAILURE(InitState());
13949 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13950
13951 VkVertexInputBindingDescription input_binding;
13952 memset(&input_binding, 0, sizeof(input_binding));
13953
13954 VkVertexInputAttributeDescription input_attrib;
13955 memset(&input_attrib, 0, sizeof(input_attrib));
13956 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13957
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013958 char const *vsSource = "#version 450\n"
13959 "\n"
13960 "layout(location=1) in float x;\n"
13961 "out gl_PerVertex {\n"
13962 " vec4 gl_Position;\n"
13963 "};\n"
13964 "void main(){\n"
13965 " gl_Position = vec4(x);\n"
13966 "}\n";
13967 char const *fsSource = "#version 450\n"
13968 "\n"
13969 "layout(location=0) out vec4 color;\n"
13970 "void main(){\n"
13971 " color = vec4(1);\n"
13972 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013973
13974 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13975 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13976
13977 VkPipelineObj pipe(m_device);
13978 pipe.AddColorAttachment();
13979 pipe.AddShader(&vs);
13980 pipe.AddShader(&fs);
13981
13982 pipe.AddVertexInputBindings(&input_binding, 1);
13983 pipe.AddVertexInputAttribs(&input_attrib, 1);
13984
13985 VkDescriptorSetObj descriptorSet(m_device);
13986 descriptorSet.AppendDummy();
13987 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13988
13989 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13990
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013991 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013992}
13993
Karl Schultz6addd812016-02-02 17:17:23 -070013994TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013995 TEST_DESCRIPTION("Test that an error is produced for a VS input which is not "
13996 "provided by a vertex attribute");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013997 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 -060013998
Chris Forbes62e8e502015-05-25 11:13:29 +120013999 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014001
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014002 char const *vsSource = "#version 450\n"
14003 "\n"
14004 "layout(location=0) in vec4 x;\n" /* not provided */
14005 "out gl_PerVertex {\n"
14006 " vec4 gl_Position;\n"
14007 "};\n"
14008 "void main(){\n"
14009 " gl_Position = x;\n"
14010 "}\n";
14011 char const *fsSource = "#version 450\n"
14012 "\n"
14013 "layout(location=0) out vec4 color;\n"
14014 "void main(){\n"
14015 " color = vec4(1);\n"
14016 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014017
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014018 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14019 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014020
14021 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014022 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014023 pipe.AddShader(&vs);
14024 pipe.AddShader(&fs);
14025
Chris Forbes62e8e502015-05-25 11:13:29 +120014026 VkDescriptorSetObj descriptorSet(m_device);
14027 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014028 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014029
Tony Barbour5781e8f2015-08-04 16:23:11 -060014030 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014031
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014032 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014033}
14034
Karl Schultz6addd812016-02-02 17:17:23 -070014035TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014036 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
14037 "fundamental type (float/int/uint) of an attribute and the "
14038 "VS input that consumes it");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0 does not match VS input type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014040
Chris Forbesc97d98e2015-05-25 11:13:31 +120014041 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014042 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014043
14044 VkVertexInputBindingDescription input_binding;
14045 memset(&input_binding, 0, sizeof(input_binding));
14046
14047 VkVertexInputAttributeDescription input_attrib;
14048 memset(&input_attrib, 0, sizeof(input_attrib));
14049 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14050
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014051 char const *vsSource = "#version 450\n"
14052 "\n"
14053 "layout(location=0) in int x;\n" /* attrib provided float */
14054 "out gl_PerVertex {\n"
14055 " vec4 gl_Position;\n"
14056 "};\n"
14057 "void main(){\n"
14058 " gl_Position = vec4(x);\n"
14059 "}\n";
14060 char const *fsSource = "#version 450\n"
14061 "\n"
14062 "layout(location=0) out vec4 color;\n"
14063 "void main(){\n"
14064 " color = vec4(1);\n"
14065 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014066
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014067 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14068 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014069
14070 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014071 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014072 pipe.AddShader(&vs);
14073 pipe.AddShader(&fs);
14074
14075 pipe.AddVertexInputBindings(&input_binding, 1);
14076 pipe.AddVertexInputAttribs(&input_attrib, 1);
14077
Chris Forbesc97d98e2015-05-25 11:13:31 +120014078 VkDescriptorSetObj descriptorSet(m_device);
14079 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014080 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014081
Tony Barbour5781e8f2015-08-04 16:23:11 -060014082 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014083
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014084 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014085}
14086
Chris Forbesc68b43c2016-04-06 11:18:47 +120014087TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014088 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
14089 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14091 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014092
14093 ASSERT_NO_FATAL_FAILURE(InitState());
14094 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014096 char const *vsSource = "#version 450\n"
14097 "\n"
14098 "out gl_PerVertex {\n"
14099 " vec4 gl_Position;\n"
14100 "};\n"
14101 "void main(){\n"
14102 " gl_Position = vec4(1);\n"
14103 "}\n";
14104 char const *fsSource = "#version 450\n"
14105 "\n"
14106 "layout(location=0) out vec4 color;\n"
14107 "void main(){\n"
14108 " color = vec4(1);\n"
14109 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014110
14111 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14112 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14113
14114 VkPipelineObj pipe(m_device);
14115 pipe.AddColorAttachment();
14116 pipe.AddShader(&vs);
14117 pipe.AddShader(&vs);
14118 pipe.AddShader(&fs);
14119
14120 VkDescriptorSetObj descriptorSet(m_device);
14121 descriptorSet.AppendDummy();
14122 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14123
14124 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14125
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014126 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014127}
14128
Karl Schultz6addd812016-02-02 17:17:23 -070014129TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014130 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
14131 "as vertex attributes");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014132 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130014133
14134 ASSERT_NO_FATAL_FAILURE(InitState());
14135 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14136
14137 VkVertexInputBindingDescription input_binding;
14138 memset(&input_binding, 0, sizeof(input_binding));
14139
14140 VkVertexInputAttributeDescription input_attribs[2];
14141 memset(input_attribs, 0, sizeof(input_attribs));
14142
14143 for (int i = 0; i < 2; i++) {
14144 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14145 input_attribs[i].location = i;
14146 }
14147
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014148 char const *vsSource = "#version 450\n"
14149 "\n"
14150 "layout(location=0) in mat2x4 x;\n"
14151 "out gl_PerVertex {\n"
14152 " vec4 gl_Position;\n"
14153 "};\n"
14154 "void main(){\n"
14155 " gl_Position = x[0] + x[1];\n"
14156 "}\n";
14157 char const *fsSource = "#version 450\n"
14158 "\n"
14159 "layout(location=0) out vec4 color;\n"
14160 "void main(){\n"
14161 " color = vec4(1);\n"
14162 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130014163
14164 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14165 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14166
14167 VkPipelineObj pipe(m_device);
14168 pipe.AddColorAttachment();
14169 pipe.AddShader(&vs);
14170 pipe.AddShader(&fs);
14171
14172 pipe.AddVertexInputBindings(&input_binding, 1);
14173 pipe.AddVertexInputAttribs(input_attribs, 2);
14174
14175 VkDescriptorSetObj descriptorSet(m_device);
14176 descriptorSet.AppendDummy();
14177 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14178
14179 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14180
14181 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014182 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130014183}
14184
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014185TEST_F(VkLayerTest, CreatePipelineAttribArrayType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014186 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130014187
14188 ASSERT_NO_FATAL_FAILURE(InitState());
14189 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14190
14191 VkVertexInputBindingDescription input_binding;
14192 memset(&input_binding, 0, sizeof(input_binding));
14193
14194 VkVertexInputAttributeDescription input_attribs[2];
14195 memset(input_attribs, 0, sizeof(input_attribs));
14196
14197 for (int i = 0; i < 2; i++) {
14198 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14199 input_attribs[i].location = i;
14200 }
14201
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014202 char const *vsSource = "#version 450\n"
14203 "\n"
14204 "layout(location=0) in vec4 x[2];\n"
14205 "out gl_PerVertex {\n"
14206 " vec4 gl_Position;\n"
14207 "};\n"
14208 "void main(){\n"
14209 " gl_Position = x[0] + x[1];\n"
14210 "}\n";
14211 char const *fsSource = "#version 450\n"
14212 "\n"
14213 "layout(location=0) out vec4 color;\n"
14214 "void main(){\n"
14215 " color = vec4(1);\n"
14216 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130014217
14218 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14219 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14220
14221 VkPipelineObj pipe(m_device);
14222 pipe.AddColorAttachment();
14223 pipe.AddShader(&vs);
14224 pipe.AddShader(&fs);
14225
14226 pipe.AddVertexInputBindings(&input_binding, 1);
14227 pipe.AddVertexInputAttribs(input_attribs, 2);
14228
14229 VkDescriptorSetObj descriptorSet(m_device);
14230 descriptorSet.AppendDummy();
14231 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14232
14233 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14234
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014235 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130014236}
Chris Forbes2682b242015-11-24 11:13:14 +130014237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014238TEST_F(VkLayerTest, CreatePipelineAttribComponents) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014239 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
14240 "through multiple VS inputs, each consuming a different subset of the "
14241 "components.");
Chris Forbesbc290ce2016-07-06 12:01:49 +120014242 m_errorMonitor->ExpectSuccess();
14243
14244 ASSERT_NO_FATAL_FAILURE(InitState());
14245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14246
14247 VkVertexInputBindingDescription input_binding;
14248 memset(&input_binding, 0, sizeof(input_binding));
14249
14250 VkVertexInputAttributeDescription input_attribs[3];
14251 memset(input_attribs, 0, sizeof(input_attribs));
14252
14253 for (int i = 0; i < 3; i++) {
14254 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14255 input_attribs[i].location = i;
14256 }
14257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014258 char const *vsSource = "#version 450\n"
14259 "\n"
14260 "layout(location=0) in vec4 x;\n"
14261 "layout(location=1) in vec3 y1;\n"
14262 "layout(location=1, component=3) in float y2;\n"
14263 "layout(location=2) in vec4 z;\n"
14264 "out gl_PerVertex {\n"
14265 " vec4 gl_Position;\n"
14266 "};\n"
14267 "void main(){\n"
14268 " gl_Position = x + vec4(y1, y2) + z;\n"
14269 "}\n";
14270 char const *fsSource = "#version 450\n"
14271 "\n"
14272 "layout(location=0) out vec4 color;\n"
14273 "void main(){\n"
14274 " color = vec4(1);\n"
14275 "}\n";
Chris Forbesbc290ce2016-07-06 12:01:49 +120014276
14277 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14278 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14279
14280 VkPipelineObj pipe(m_device);
14281 pipe.AddColorAttachment();
14282 pipe.AddShader(&vs);
14283 pipe.AddShader(&fs);
14284
14285 pipe.AddVertexInputBindings(&input_binding, 1);
14286 pipe.AddVertexInputAttribs(input_attribs, 3);
14287
14288 VkDescriptorSetObj descriptorSet(m_device);
14289 descriptorSet.AppendDummy();
14290 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14291
14292 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14293
14294 m_errorMonitor->VerifyNotFound();
14295}
14296
Chris Forbes82ff92a2016-09-09 10:50:24 +120014297TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
14298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14299 "No entrypoint found named `foo`");
14300
14301 ASSERT_NO_FATAL_FAILURE(InitState());
14302 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14303
14304 char const *vsSource = "#version 450\n"
14305 "out gl_PerVertex {\n"
14306 " vec4 gl_Position;\n"
14307 "};\n"
14308 "void main(){\n"
14309 " gl_Position = vec4(0);\n"
14310 "}\n";
14311 char const *fsSource = "#version 450\n"
14312 "\n"
14313 "layout(location=0) out vec4 color;\n"
14314 "void main(){\n"
14315 " color = vec4(1);\n"
14316 "}\n";
14317
14318 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14319 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14320
14321 VkPipelineObj pipe(m_device);
14322 pipe.AddColorAttachment();
14323 pipe.AddShader(&vs);
14324 pipe.AddShader(&fs);
14325
14326 VkDescriptorSetObj descriptorSet(m_device);
14327 descriptorSet.AppendDummy();
14328 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14329
14330 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14331
14332 m_errorMonitor->VerifyFound();
14333}
14334
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014335TEST_F(VkLayerTest, CreatePipelineSimplePositive) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014336 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014337
14338 ASSERT_NO_FATAL_FAILURE(InitState());
14339 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14340
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014341 char const *vsSource = "#version 450\n"
14342 "out gl_PerVertex {\n"
14343 " vec4 gl_Position;\n"
14344 "};\n"
14345 "void main(){\n"
14346 " gl_Position = vec4(0);\n"
14347 "}\n";
14348 char const *fsSource = "#version 450\n"
14349 "\n"
14350 "layout(location=0) out vec4 color;\n"
14351 "void main(){\n"
14352 " color = vec4(1);\n"
14353 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014354
14355 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14356 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14357
14358 VkPipelineObj pipe(m_device);
14359 pipe.AddColorAttachment();
14360 pipe.AddShader(&vs);
14361 pipe.AddShader(&fs);
14362
14363 VkDescriptorSetObj descriptorSet(m_device);
14364 descriptorSet.AppendDummy();
14365 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14366
14367 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14368
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014369 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014370}
14371
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014372TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
14373 m_errorMonitor->SetDesiredFailureMsg(
14374 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14375 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14376 "uses a depth/stencil attachment");
14377
14378 ASSERT_NO_FATAL_FAILURE(InitState());
14379 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14380
14381 char const *vsSource = "#version 450\n"
14382 "void main(){ gl_Position = vec4(0); }\n";
14383 char const *fsSource = "#version 450\n"
14384 "\n"
14385 "layout(location=0) out vec4 color;\n"
14386 "void main(){\n"
14387 " color = vec4(1);\n"
14388 "}\n";
14389
14390 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14391 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14392
14393 VkPipelineObj pipe(m_device);
14394 pipe.AddColorAttachment();
14395 pipe.AddShader(&vs);
14396 pipe.AddShader(&fs);
14397
14398 VkDescriptorSetObj descriptorSet(m_device);
14399 descriptorSet.AppendDummy();
14400 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14401
14402 VkAttachmentDescription attachments[] = {
14403 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
14404 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14405 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14406 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14407 },
14408 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
14409 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14410 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14411 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
14412 },
14413 };
14414 VkAttachmentReference refs[] = {
14415 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
14416 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
14417 };
14418 VkSubpassDescription subpass = {
14419 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
14420 1, &refs[0], nullptr, &refs[1],
14421 0, nullptr
14422 };
14423 VkRenderPassCreateInfo rpci = {
14424 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
14425 0, 2, attachments, 1, &subpass, 0, nullptr
14426 };
14427 VkRenderPass rp;
14428 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14429 ASSERT_VK_SUCCESS(err);
14430
14431 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14432
14433 m_errorMonitor->VerifyFound();
14434
14435 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14436}
14437
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014438TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014439 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
14440 "set out in 14.1.3: fundamental type must match, and producer side must "
14441 "have at least as many components");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014442 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120014443
14444 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
14445
14446 ASSERT_NO_FATAL_FAILURE(InitState());
14447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14448
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014449 char const *vsSource = "#version 450\n"
14450 "out gl_PerVertex {\n"
14451 " vec4 gl_Position;\n"
14452 "};\n"
14453 "layout(location=0) out vec3 x;\n"
14454 "layout(location=1) out ivec3 y;\n"
14455 "layout(location=2) out vec3 z;\n"
14456 "void main(){\n"
14457 " gl_Position = vec4(0);\n"
14458 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
14459 "}\n";
14460 char const *fsSource = "#version 450\n"
14461 "\n"
14462 "layout(location=0) out vec4 color;\n"
14463 "layout(location=0) in float x;\n"
14464 "layout(location=1) flat in int y;\n"
14465 "layout(location=2) in vec2 z;\n"
14466 "void main(){\n"
14467 " color = vec4(1 + x + y + z.x);\n"
14468 "}\n";
Chris Forbes912c9192016-04-05 17:50:35 +120014469
14470 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14471 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14472
14473 VkPipelineObj pipe(m_device);
14474 pipe.AddColorAttachment();
14475 pipe.AddShader(&vs);
14476 pipe.AddShader(&fs);
14477
14478 VkDescriptorSetObj descriptorSet(m_device);
14479 descriptorSet.AppendDummy();
14480 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14481
Mike Stroyan255e9582016-06-24 09:49:32 -060014482 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014483 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Mike Stroyan255e9582016-06-24 09:49:32 -060014484 ASSERT_VK_SUCCESS(err);
14485
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014486 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120014487}
14488
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014489TEST_F(VkLayerTest, CreatePipelineTessPerVertex) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014490 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
14491 "passed between the TCS and TES stages");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014492 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014493
14494 ASSERT_NO_FATAL_FAILURE(InitState());
14495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14496
Chris Forbesc1e852d2016-04-04 19:26:42 +120014497 if (!m_device->phy().features().tessellationShader) {
14498 printf("Device does not support tessellation shaders; skipped.\n");
14499 return;
14500 }
14501
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014502 char const *vsSource = "#version 450\n"
14503 "void main(){}\n";
14504 char const *tcsSource = "#version 450\n"
14505 "layout(location=0) out int x[];\n"
14506 "layout(vertices=3) out;\n"
14507 "void main(){\n"
14508 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14509 " gl_TessLevelInner[0] = 1;\n"
14510 " x[gl_InvocationID] = gl_InvocationID;\n"
14511 "}\n";
14512 char const *tesSource = "#version 450\n"
14513 "layout(triangles, equal_spacing, cw) in;\n"
14514 "layout(location=0) in int x[];\n"
14515 "out gl_PerVertex { vec4 gl_Position; };\n"
14516 "void main(){\n"
14517 " gl_Position.xyz = gl_TessCoord;\n"
14518 " gl_Position.w = x[0] + x[1] + x[2];\n"
14519 "}\n";
14520 char const *fsSource = "#version 450\n"
14521 "layout(location=0) out vec4 color;\n"
14522 "void main(){\n"
14523 " color = vec4(1);\n"
14524 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014525
14526 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14527 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14528 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14529 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14530
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014531 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14532 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014533
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014534 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesb4cacb62016-04-04 19:15:00 +120014535
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014536 VkPipelineObj pipe(m_device);
14537 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120014538 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014539 pipe.AddColorAttachment();
14540 pipe.AddShader(&vs);
14541 pipe.AddShader(&tcs);
14542 pipe.AddShader(&tes);
14543 pipe.AddShader(&fs);
14544
14545 VkDescriptorSetObj descriptorSet(m_device);
14546 descriptorSet.AppendDummy();
14547 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14548
14549 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14550
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014551 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014552}
14553
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014554TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014555 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
14556 "interface block passed into the geometry shader. This "
14557 "is interesting because the 'extra' array level is not "
14558 "present on the member type, but on the block instance.");
Chris Forbesa0ab8152016-04-20 13:34:27 +120014559 m_errorMonitor->ExpectSuccess();
14560
14561 ASSERT_NO_FATAL_FAILURE(InitState());
14562 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14563
14564 if (!m_device->phy().features().geometryShader) {
14565 printf("Device does not support geometry shaders; skipped.\n");
14566 return;
14567 }
14568
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014569 char const *vsSource = "#version 450\n"
14570 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
14571 "void main(){\n"
14572 " vs_out.x = vec4(1);\n"
14573 "}\n";
14574 char const *gsSource = "#version 450\n"
14575 "layout(triangles) in;\n"
14576 "layout(triangle_strip, max_vertices=3) out;\n"
14577 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
14578 "out gl_PerVertex { vec4 gl_Position; };\n"
14579 "void main() {\n"
14580 " gl_Position = gs_in[0].x;\n"
14581 " EmitVertex();\n"
14582 "}\n";
14583 char const *fsSource = "#version 450\n"
14584 "layout(location=0) out vec4 color;\n"
14585 "void main(){\n"
14586 " color = vec4(1);\n"
14587 "}\n";
Chris Forbesa0ab8152016-04-20 13:34:27 +120014588
14589 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14590 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
14591 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14592
14593 VkPipelineObj pipe(m_device);
14594 pipe.AddColorAttachment();
14595 pipe.AddShader(&vs);
14596 pipe.AddShader(&gs);
14597 pipe.AddShader(&fs);
14598
14599 VkDescriptorSetObj descriptorSet(m_device);
14600 descriptorSet.AppendDummy();
14601 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14602
14603 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14604
14605 m_errorMonitor->VerifyNotFound();
14606}
14607
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014608TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014609 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
14610 "the TCS without the patch decoration, but consumed in the TES "
14611 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
14613 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014614
14615 ASSERT_NO_FATAL_FAILURE(InitState());
14616 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14617
Chris Forbesc1e852d2016-04-04 19:26:42 +120014618 if (!m_device->phy().features().tessellationShader) {
14619 printf("Device does not support tessellation shaders; skipped.\n");
14620 return;
14621 }
14622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014623 char const *vsSource = "#version 450\n"
14624 "void main(){}\n";
14625 char const *tcsSource = "#version 450\n"
14626 "layout(location=0) out int x[];\n"
14627 "layout(vertices=3) out;\n"
14628 "void main(){\n"
14629 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14630 " gl_TessLevelInner[0] = 1;\n"
14631 " x[gl_InvocationID] = gl_InvocationID;\n"
14632 "}\n";
14633 char const *tesSource = "#version 450\n"
14634 "layout(triangles, equal_spacing, cw) in;\n"
14635 "layout(location=0) patch in int x;\n"
14636 "out gl_PerVertex { vec4 gl_Position; };\n"
14637 "void main(){\n"
14638 " gl_Position.xyz = gl_TessCoord;\n"
14639 " gl_Position.w = x;\n"
14640 "}\n";
14641 char const *fsSource = "#version 450\n"
14642 "layout(location=0) out vec4 color;\n"
14643 "void main(){\n"
14644 " color = vec4(1);\n"
14645 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014646
14647 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14648 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14649 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14650 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14651
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014652 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14653 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014654
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014655 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014656
14657 VkPipelineObj pipe(m_device);
14658 pipe.SetInputAssembly(&iasci);
14659 pipe.SetTessellation(&tsci);
14660 pipe.AddColorAttachment();
14661 pipe.AddShader(&vs);
14662 pipe.AddShader(&tcs);
14663 pipe.AddShader(&tes);
14664 pipe.AddShader(&fs);
14665
14666 VkDescriptorSetObj descriptorSet(m_device);
14667 descriptorSet.AppendDummy();
14668 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14669
14670 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14671
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014672 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014673}
14674
Karl Schultz6addd812016-02-02 17:17:23 -070014675TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014676 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
14677 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14679 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014680
Chris Forbes280ba2c2015-06-12 11:16:41 +120014681 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014683
14684 /* Two binding descriptions for binding 0 */
14685 VkVertexInputBindingDescription input_bindings[2];
14686 memset(input_bindings, 0, sizeof(input_bindings));
14687
14688 VkVertexInputAttributeDescription input_attrib;
14689 memset(&input_attrib, 0, sizeof(input_attrib));
14690 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14691
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014692 char const *vsSource = "#version 450\n"
14693 "\n"
14694 "layout(location=0) in float x;\n" /* attrib provided float */
14695 "out gl_PerVertex {\n"
14696 " vec4 gl_Position;\n"
14697 "};\n"
14698 "void main(){\n"
14699 " gl_Position = vec4(x);\n"
14700 "}\n";
14701 char const *fsSource = "#version 450\n"
14702 "\n"
14703 "layout(location=0) out vec4 color;\n"
14704 "void main(){\n"
14705 " color = vec4(1);\n"
14706 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014707
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014708 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14709 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014710
14711 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014712 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014713 pipe.AddShader(&vs);
14714 pipe.AddShader(&fs);
14715
14716 pipe.AddVertexInputBindings(input_bindings, 2);
14717 pipe.AddVertexInputAttribs(&input_attrib, 1);
14718
Chris Forbes280ba2c2015-06-12 11:16:41 +120014719 VkDescriptorSetObj descriptorSet(m_device);
14720 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014721 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014722
Tony Barbour5781e8f2015-08-04 16:23:11 -060014723 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014724
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014725 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014726}
Chris Forbes8f68b562015-05-25 11:13:32 +120014727
Chris Forbes35efec72016-04-21 14:32:08 +120014728TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014729 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
14730 "attributes. This is interesting because they consume multiple "
14731 "locations.");
Chris Forbes35efec72016-04-21 14:32:08 +120014732 m_errorMonitor->ExpectSuccess();
14733
14734 ASSERT_NO_FATAL_FAILURE(InitState());
14735 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14736
Chris Forbes91cf3a82016-06-28 17:51:35 +120014737 if (!m_device->phy().features().shaderFloat64) {
Chris Forbes35efec72016-04-21 14:32:08 +120014738 printf("Device does not support 64bit vertex attributes; skipped.\n");
14739 return;
14740 }
14741
14742 VkVertexInputBindingDescription input_bindings[1];
14743 memset(input_bindings, 0, sizeof(input_bindings));
14744
14745 VkVertexInputAttributeDescription input_attribs[4];
14746 memset(input_attribs, 0, sizeof(input_attribs));
14747 input_attribs[0].location = 0;
14748 input_attribs[0].offset = 0;
14749 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14750 input_attribs[1].location = 2;
14751 input_attribs[1].offset = 32;
14752 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14753 input_attribs[2].location = 4;
14754 input_attribs[2].offset = 64;
14755 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14756 input_attribs[3].location = 6;
14757 input_attribs[3].offset = 96;
14758 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14759
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014760 char const *vsSource = "#version 450\n"
14761 "\n"
14762 "layout(location=0) in dmat4 x;\n"
14763 "out gl_PerVertex {\n"
14764 " vec4 gl_Position;\n"
14765 "};\n"
14766 "void main(){\n"
14767 " gl_Position = vec4(x[0][0]);\n"
14768 "}\n";
14769 char const *fsSource = "#version 450\n"
14770 "\n"
14771 "layout(location=0) out vec4 color;\n"
14772 "void main(){\n"
14773 " color = vec4(1);\n"
14774 "}\n";
Chris Forbes35efec72016-04-21 14:32:08 +120014775
14776 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14777 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14778
14779 VkPipelineObj pipe(m_device);
14780 pipe.AddColorAttachment();
14781 pipe.AddShader(&vs);
14782 pipe.AddShader(&fs);
14783
14784 pipe.AddVertexInputBindings(input_bindings, 1);
14785 pipe.AddVertexInputAttribs(input_attribs, 4);
14786
14787 VkDescriptorSetObj descriptorSet(m_device);
14788 descriptorSet.AppendDummy();
14789 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14790
14791 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14792
14793 m_errorMonitor->VerifyNotFound();
14794}
14795
Karl Schultz6addd812016-02-02 17:17:23 -070014796TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014797 TEST_DESCRIPTION("Test that an error is produced for a FS which does not "
14798 "provide an output for one of the pipeline's color attachments");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014800
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014801 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014802
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014803 char const *vsSource = "#version 450\n"
14804 "\n"
14805 "out gl_PerVertex {\n"
14806 " vec4 gl_Position;\n"
14807 "};\n"
14808 "void main(){\n"
14809 " gl_Position = vec4(1);\n"
14810 "}\n";
14811 char const *fsSource = "#version 450\n"
14812 "\n"
14813 "void main(){\n"
14814 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014815
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014816 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14817 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014818
14819 VkPipelineObj pipe(m_device);
14820 pipe.AddShader(&vs);
14821 pipe.AddShader(&fs);
14822
Chia-I Wu08accc62015-07-07 11:50:03 +080014823 /* set up CB 0, not written */
14824 pipe.AddColorAttachment();
14825 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014826
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014827 VkDescriptorSetObj descriptorSet(m_device);
14828 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014829 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014830
Tony Barbour5781e8f2015-08-04 16:23:11 -060014831 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014832
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014833 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014834}
14835
Karl Schultz6addd812016-02-02 17:17:23 -070014836TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014837 TEST_DESCRIPTION("Test that a warning is produced for a FS which provides a spurious "
14838 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
14840 "FS writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014841
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014842 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014843
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014844 char const *vsSource = "#version 450\n"
14845 "\n"
14846 "out gl_PerVertex {\n"
14847 " vec4 gl_Position;\n"
14848 "};\n"
14849 "void main(){\n"
14850 " gl_Position = vec4(1);\n"
14851 "}\n";
14852 char const *fsSource = "#version 450\n"
14853 "\n"
14854 "layout(location=0) out vec4 x;\n"
14855 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14856 "void main(){\n"
14857 " x = vec4(1);\n"
14858 " y = vec4(1);\n"
14859 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014860
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014861 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14862 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014863
14864 VkPipelineObj pipe(m_device);
14865 pipe.AddShader(&vs);
14866 pipe.AddShader(&fs);
14867
Chia-I Wu08accc62015-07-07 11:50:03 +080014868 /* set up CB 0, not written */
14869 pipe.AddColorAttachment();
14870 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014871 /* FS writes CB 1, but we don't configure it */
14872
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014873 VkDescriptorSetObj descriptorSet(m_device);
14874 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014875 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014876
Tony Barbour5781e8f2015-08-04 16:23:11 -060014877 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014878
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014879 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014880}
14881
Karl Schultz6addd812016-02-02 17:17:23 -070014882TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014883 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
14884 "type of an FS output variable, and the format of the corresponding attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014886
Chris Forbesa36d69e2015-05-25 11:13:44 +120014887 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014888
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014889 char const *vsSource = "#version 450\n"
14890 "\n"
14891 "out gl_PerVertex {\n"
14892 " vec4 gl_Position;\n"
14893 "};\n"
14894 "void main(){\n"
14895 " gl_Position = vec4(1);\n"
14896 "}\n";
14897 char const *fsSource = "#version 450\n"
14898 "\n"
14899 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14900 "void main(){\n"
14901 " x = ivec4(1);\n"
14902 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014903
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014904 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14905 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014906
14907 VkPipelineObj pipe(m_device);
14908 pipe.AddShader(&vs);
14909 pipe.AddShader(&fs);
14910
Chia-I Wu08accc62015-07-07 11:50:03 +080014911 /* set up CB 0; type is UNORM by default */
14912 pipe.AddColorAttachment();
14913 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014914
Chris Forbesa36d69e2015-05-25 11:13:44 +120014915 VkDescriptorSetObj descriptorSet(m_device);
14916 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014917 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014918
Tony Barbour5781e8f2015-08-04 16:23:11 -060014919 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014920
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014921 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014922}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014923
Karl Schultz6addd812016-02-02 17:17:23 -070014924TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014925 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
14926 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014928
Chris Forbes556c76c2015-08-14 12:04:59 +120014929 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014930
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014931 char const *vsSource = "#version 450\n"
14932 "\n"
14933 "out gl_PerVertex {\n"
14934 " vec4 gl_Position;\n"
14935 "};\n"
14936 "void main(){\n"
14937 " gl_Position = vec4(1);\n"
14938 "}\n";
14939 char const *fsSource = "#version 450\n"
14940 "\n"
14941 "layout(location=0) out vec4 x;\n"
14942 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14943 "void main(){\n"
14944 " x = vec4(bar.y);\n"
14945 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014946
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014947 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14948 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014949
Chris Forbes556c76c2015-08-14 12:04:59 +120014950 VkPipelineObj pipe(m_device);
14951 pipe.AddShader(&vs);
14952 pipe.AddShader(&fs);
14953
14954 /* set up CB 0; type is UNORM by default */
14955 pipe.AddColorAttachment();
14956 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14957
14958 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014959 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014960
14961 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14962
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014963 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014964}
14965
Chris Forbes5c59e902016-02-26 16:56:09 +130014966TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014967 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
14968 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014970
14971 ASSERT_NO_FATAL_FAILURE(InitState());
14972
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014973 char const *vsSource = "#version 450\n"
14974 "\n"
14975 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14976 "out gl_PerVertex {\n"
14977 " vec4 gl_Position;\n"
14978 "};\n"
14979 "void main(){\n"
14980 " gl_Position = vec4(consts.x);\n"
14981 "}\n";
14982 char const *fsSource = "#version 450\n"
14983 "\n"
14984 "layout(location=0) out vec4 x;\n"
14985 "void main(){\n"
14986 " x = vec4(1);\n"
14987 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014988
14989 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14990 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14991
14992 VkPipelineObj pipe(m_device);
14993 pipe.AddShader(&vs);
14994 pipe.AddShader(&fs);
14995
14996 /* set up CB 0; type is UNORM by default */
14997 pipe.AddColorAttachment();
14998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14999
15000 VkDescriptorSetObj descriptorSet(m_device);
15001 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15002
15003 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15004
15005 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015006 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130015007}
15008
Chris Forbes3fb17902016-08-22 14:57:55 +120015009TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
15010 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
15011 "which is not included in the subpass description");
15012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15013 "consumes input attachment index 0 but not provided in subpass");
15014
15015 ASSERT_NO_FATAL_FAILURE(InitState());
15016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015017 char const *vsSource = "#version 450\n"
15018 "\n"
15019 "out gl_PerVertex {\n"
15020 " vec4 gl_Position;\n"
15021 "};\n"
15022 "void main(){\n"
15023 " gl_Position = vec4(1);\n"
15024 "}\n";
15025 char const *fsSource = "#version 450\n"
15026 "\n"
15027 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15028 "layout(location=0) out vec4 color;\n"
15029 "void main() {\n"
15030 " color = subpassLoad(x);\n"
15031 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015032
15033 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15034 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15035
15036 VkPipelineObj pipe(m_device);
15037 pipe.AddShader(&vs);
15038 pipe.AddShader(&fs);
15039 pipe.AddColorAttachment();
15040 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15041
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015042 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15043 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015044 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015045 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015046 ASSERT_VK_SUCCESS(err);
15047
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015048 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015049 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015050 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015051 ASSERT_VK_SUCCESS(err);
15052
15053 // error here.
15054 pipe.CreateVKPipeline(pl, renderPass());
15055
15056 m_errorMonitor->VerifyFound();
15057
15058 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15059 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15060}
15061
Chris Forbes663b5a82016-08-22 16:14:06 +120015062TEST_F(VkLayerTest, CreatePipelineInputAttachmentPositive) {
15063 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
15064 m_errorMonitor->ExpectSuccess();
15065
15066 ASSERT_NO_FATAL_FAILURE(InitState());
15067
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015068 char const *vsSource = "#version 450\n"
15069 "\n"
15070 "out gl_PerVertex {\n"
15071 " vec4 gl_Position;\n"
15072 "};\n"
15073 "void main(){\n"
15074 " gl_Position = vec4(1);\n"
15075 "}\n";
15076 char const *fsSource = "#version 450\n"
15077 "\n"
15078 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15079 "layout(location=0) out vec4 color;\n"
15080 "void main() {\n"
15081 " color = subpassLoad(x);\n"
15082 "}\n";
Chris Forbes663b5a82016-08-22 16:14:06 +120015083
15084 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15085 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15086
15087 VkPipelineObj pipe(m_device);
15088 pipe.AddShader(&vs);
15089 pipe.AddShader(&fs);
15090 pipe.AddColorAttachment();
15091 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15092
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015093 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15094 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes663b5a82016-08-22 16:14:06 +120015095 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015096 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes663b5a82016-08-22 16:14:06 +120015097 ASSERT_VK_SUCCESS(err);
15098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015099 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120015100 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015101 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes663b5a82016-08-22 16:14:06 +120015102 ASSERT_VK_SUCCESS(err);
15103
15104 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015105 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15106 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15107 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15108 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15109 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 +120015110 };
15111 VkAttachmentReference color = {
15112 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15113 };
15114 VkAttachmentReference input = {
15115 1, VK_IMAGE_LAYOUT_GENERAL,
15116 };
15117
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015118 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120015119
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015120 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120015121 VkRenderPass rp;
15122 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15123 ASSERT_VK_SUCCESS(err);
15124
15125 // should be OK. would go wrong here if it's going to...
15126 pipe.CreateVKPipeline(pl, rp);
15127
15128 m_errorMonitor->VerifyNotFound();
15129
15130 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15131 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15132 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15133}
15134
Chris Forbes5a9a0472016-08-22 16:02:09 +120015135TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
15136 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
15137 "with a format having a different fundamental type");
15138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15139 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15140
15141 ASSERT_NO_FATAL_FAILURE(InitState());
15142
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015143 char const *vsSource = "#version 450\n"
15144 "\n"
15145 "out gl_PerVertex {\n"
15146 " vec4 gl_Position;\n"
15147 "};\n"
15148 "void main(){\n"
15149 " gl_Position = vec4(1);\n"
15150 "}\n";
15151 char const *fsSource = "#version 450\n"
15152 "\n"
15153 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15154 "layout(location=0) out vec4 color;\n"
15155 "void main() {\n"
15156 " color = subpassLoad(x);\n"
15157 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015158
15159 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15160 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15161
15162 VkPipelineObj pipe(m_device);
15163 pipe.AddShader(&vs);
15164 pipe.AddShader(&fs);
15165 pipe.AddColorAttachment();
15166 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15167
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015168 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15169 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015170 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015171 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015172 ASSERT_VK_SUCCESS(err);
15173
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015174 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015175 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015176 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015177 ASSERT_VK_SUCCESS(err);
15178
15179 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015180 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15181 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15182 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15183 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15184 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 +120015185 };
15186 VkAttachmentReference color = {
15187 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15188 };
15189 VkAttachmentReference input = {
15190 1, VK_IMAGE_LAYOUT_GENERAL,
15191 };
15192
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015193 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015194
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015195 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015196 VkRenderPass rp;
15197 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15198 ASSERT_VK_SUCCESS(err);
15199
15200 // error here.
15201 pipe.CreateVKPipeline(pl, rp);
15202
15203 m_errorMonitor->VerifyFound();
15204
15205 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15206 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15207 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15208}
15209
Chris Forbes541f7b02016-08-22 15:30:27 +120015210TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
15211 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
15212 "which is not included in the subpass description -- array case");
15213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15214 "consumes input attachment index 1 but not provided in subpass");
15215
15216 ASSERT_NO_FATAL_FAILURE(InitState());
15217
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015218 char const *vsSource = "#version 450\n"
15219 "\n"
15220 "out gl_PerVertex {\n"
15221 " vec4 gl_Position;\n"
15222 "};\n"
15223 "void main(){\n"
15224 " gl_Position = vec4(1);\n"
15225 "}\n";
15226 char const *fsSource = "#version 450\n"
15227 "\n"
15228 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
15229 "layout(location=0) out vec4 color;\n"
15230 "void main() {\n"
15231 " color = subpassLoad(xs[1]);\n"
15232 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015233
15234 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15235 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15236
15237 VkPipelineObj pipe(m_device);
15238 pipe.AddShader(&vs);
15239 pipe.AddShader(&fs);
15240 pipe.AddColorAttachment();
15241 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15242
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015243 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15244 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015245 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015246 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015247 ASSERT_VK_SUCCESS(err);
15248
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015249 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015250 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015251 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015252 ASSERT_VK_SUCCESS(err);
15253
15254 // error here.
15255 pipe.CreateVKPipeline(pl, renderPass());
15256
15257 m_errorMonitor->VerifyFound();
15258
15259 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15260 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15261}
15262
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015263TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015264 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
15265 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015267
15268 ASSERT_NO_FATAL_FAILURE(InitState());
15269
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015270 char const *csSource = "#version 450\n"
15271 "\n"
15272 "layout(local_size_x=1) in;\n"
15273 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15274 "void main(){\n"
15275 " x = vec4(1);\n"
15276 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015277
15278 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15279
15280 VkDescriptorSetObj descriptorSet(m_device);
15281 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15282
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015283 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15284 nullptr,
15285 0,
15286 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15287 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15288 descriptorSet.GetPipelineLayout(),
15289 VK_NULL_HANDLE,
15290 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015291
15292 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015293 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015294
15295 m_errorMonitor->VerifyFound();
15296
15297 if (err == VK_SUCCESS) {
15298 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15299 }
15300}
15301
15302TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015303 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
15304 "descriptor-backed resource which is not provided, but the shader does not "
15305 "statically use it. This is interesting because it requires compute pipelines "
15306 "to have a proper descriptor use walk, which they didn't for some time.");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015307 m_errorMonitor->ExpectSuccess();
15308
15309 ASSERT_NO_FATAL_FAILURE(InitState());
15310
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015311 char const *csSource = "#version 450\n"
15312 "\n"
15313 "layout(local_size_x=1) in;\n"
15314 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15315 "void main(){\n"
15316 " // x is not used.\n"
15317 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015318
15319 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15320
15321 VkDescriptorSetObj descriptorSet(m_device);
15322 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15323
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015324 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15325 nullptr,
15326 0,
15327 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15328 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15329 descriptorSet.GetPipelineLayout(),
15330 VK_NULL_HANDLE,
15331 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015332
15333 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015334 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015335
15336 m_errorMonitor->VerifyNotFound();
15337
15338 if (err == VK_SUCCESS) {
15339 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15340 }
15341}
15342
Chris Forbes22a9b092016-07-19 14:34:05 +120015343TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015344 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
15345 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15347 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015348
15349 ASSERT_NO_FATAL_FAILURE(InitState());
15350
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015351 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15352 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015353 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015354 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015355 ASSERT_VK_SUCCESS(err);
15356
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015357 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015358 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015359 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015360 ASSERT_VK_SUCCESS(err);
15361
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015362 char const *csSource = "#version 450\n"
15363 "\n"
15364 "layout(local_size_x=1) in;\n"
15365 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15366 "void main() {\n"
15367 " x.x = 1.0f;\n"
15368 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015369 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15370
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015371 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15372 nullptr,
15373 0,
15374 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15375 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15376 pl,
15377 VK_NULL_HANDLE,
15378 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015379
15380 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015381 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015382
15383 m_errorMonitor->VerifyFound();
15384
15385 if (err == VK_SUCCESS) {
15386 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15387 }
15388
15389 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15390 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15391}
15392
Chris Forbese10a51f2016-07-19 14:42:51 +120015393TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015394 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15395 "sampler portion of a combined image + sampler");
Chris Forbese10a51f2016-07-19 14:42:51 +120015396 m_errorMonitor->ExpectSuccess();
15397
15398 ASSERT_NO_FATAL_FAILURE(InitState());
15399
15400 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015401 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15402 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15403 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbese10a51f2016-07-19 14:42:51 +120015404 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015405 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbese10a51f2016-07-19 14:42:51 +120015406 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015407 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015408 ASSERT_VK_SUCCESS(err);
15409
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015410 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbese10a51f2016-07-19 14:42:51 +120015411 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015412 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015413 ASSERT_VK_SUCCESS(err);
15414
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015415 char const *csSource = "#version 450\n"
15416 "\n"
15417 "layout(local_size_x=1) in;\n"
15418 "layout(set=0, binding=0) uniform sampler s;\n"
15419 "layout(set=0, binding=1) uniform texture2D t;\n"
15420 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15421 "void main() {\n"
15422 " x = texture(sampler2D(t, s), vec2(0));\n"
15423 "}\n";
Chris Forbese10a51f2016-07-19 14:42:51 +120015424 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15425
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015426 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15427 nullptr,
15428 0,
15429 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15430 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15431 pl,
15432 VK_NULL_HANDLE,
15433 -1};
Chris Forbese10a51f2016-07-19 14:42:51 +120015434
15435 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015436 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbese10a51f2016-07-19 14:42:51 +120015437
15438 m_errorMonitor->VerifyNotFound();
15439
15440 if (err == VK_SUCCESS) {
15441 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15442 }
15443
15444 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15445 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15446}
15447
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015448TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015449 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15450 "image portion of a combined image + sampler");
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015451 m_errorMonitor->ExpectSuccess();
15452
15453 ASSERT_NO_FATAL_FAILURE(InitState());
15454
15455 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015456 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15457 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15458 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015459 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015460 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015461 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015462 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015463 ASSERT_VK_SUCCESS(err);
15464
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015465 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015466 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015467 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015468 ASSERT_VK_SUCCESS(err);
15469
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015470 char const *csSource = "#version 450\n"
15471 "\n"
15472 "layout(local_size_x=1) in;\n"
15473 "layout(set=0, binding=0) uniform texture2D t;\n"
15474 "layout(set=0, binding=1) uniform sampler s;\n"
15475 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15476 "void main() {\n"
15477 " x = texture(sampler2D(t, s), vec2(0));\n"
15478 "}\n";
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015479 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15480
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015481 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15482 nullptr,
15483 0,
15484 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15485 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15486 pl,
15487 VK_NULL_HANDLE,
15488 -1};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015489
15490 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015491 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015492
15493 m_errorMonitor->VerifyNotFound();
15494
15495 if (err == VK_SUCCESS) {
15496 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15497 }
15498
15499 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15500 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15501}
15502
Chris Forbes6a4991a2016-07-19 15:07:32 +120015503TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015504 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
15505 "both the sampler and the image of a combined image+sampler "
15506 "but via separate variables");
Chris Forbes6a4991a2016-07-19 15:07:32 +120015507 m_errorMonitor->ExpectSuccess();
15508
15509 ASSERT_NO_FATAL_FAILURE(InitState());
15510
15511 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015512 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15513 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes6a4991a2016-07-19 15:07:32 +120015514 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015515 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015516 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015517 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015518 ASSERT_VK_SUCCESS(err);
15519
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015520 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015521 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015522 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015523 ASSERT_VK_SUCCESS(err);
15524
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015525 char const *csSource = "#version 450\n"
15526 "\n"
15527 "layout(local_size_x=1) in;\n"
15528 "layout(set=0, binding=0) uniform texture2D t;\n"
15529 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
15530 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
15531 "void main() {\n"
15532 " x = texture(sampler2D(t, s), vec2(0));\n"
15533 "}\n";
Chris Forbes6a4991a2016-07-19 15:07:32 +120015534 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15535
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015536 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15537 nullptr,
15538 0,
15539 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15540 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15541 pl,
15542 VK_NULL_HANDLE,
15543 -1};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015544
15545 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015546 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015547
15548 m_errorMonitor->VerifyNotFound();
15549
15550 if (err == VK_SUCCESS) {
15551 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15552 }
15553
15554 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15555 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15556}
15557
Chris Forbes50020592016-07-27 13:52:41 +120015558TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
15559 TEST_DESCRIPTION("Test that an error is produced when an image view type "
15560 "does not match the dimensionality declared in the shader");
15561
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015562 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 +120015563
15564 ASSERT_NO_FATAL_FAILURE(InitState());
15565 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15566
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015567 char const *vsSource = "#version 450\n"
15568 "\n"
15569 "out gl_PerVertex { vec4 gl_Position; };\n"
15570 "void main() { gl_Position = vec4(0); }\n";
15571 char const *fsSource = "#version 450\n"
15572 "\n"
15573 "layout(set=0, binding=0) uniform sampler3D s;\n"
15574 "layout(location=0) out vec4 color;\n"
15575 "void main() {\n"
15576 " color = texture(s, vec3(0));\n"
15577 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015578 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15579 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15580
15581 VkPipelineObj pipe(m_device);
15582 pipe.AddShader(&vs);
15583 pipe.AddShader(&fs);
15584 pipe.AddColorAttachment();
15585
15586 VkTextureObj texture(m_device, nullptr);
15587 VkSamplerObj sampler(m_device);
15588
15589 VkDescriptorSetObj descriptorSet(m_device);
15590 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15591 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15592
15593 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15594 ASSERT_VK_SUCCESS(err);
15595
15596 BeginCommandBuffer();
15597
15598 m_commandBuffer->BindPipeline(pipe);
15599 m_commandBuffer->BindDescriptorSet(descriptorSet);
15600
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015601 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015602 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015603 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015604 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15605
15606 // error produced here.
15607 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15608
15609 m_errorMonitor->VerifyFound();
15610
15611 EndCommandBuffer();
15612}
15613
Chris Forbes5533bfc2016-07-27 14:12:34 +120015614TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
15615 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
15616 "are consumed via singlesample images types in the shader, or vice versa.");
15617
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015619
15620 ASSERT_NO_FATAL_FAILURE(InitState());
15621 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015623 char const *vsSource = "#version 450\n"
15624 "\n"
15625 "out gl_PerVertex { vec4 gl_Position; };\n"
15626 "void main() { gl_Position = vec4(0); }\n";
15627 char const *fsSource = "#version 450\n"
15628 "\n"
15629 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15630 "layout(location=0) out vec4 color;\n"
15631 "void main() {\n"
15632 " color = texelFetch(s, ivec2(0), 0);\n"
15633 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015634 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15635 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15636
15637 VkPipelineObj pipe(m_device);
15638 pipe.AddShader(&vs);
15639 pipe.AddShader(&fs);
15640 pipe.AddColorAttachment();
15641
15642 VkTextureObj texture(m_device, nullptr);
15643 VkSamplerObj sampler(m_device);
15644
15645 VkDescriptorSetObj descriptorSet(m_device);
15646 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15647 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15648
15649 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15650 ASSERT_VK_SUCCESS(err);
15651
15652 BeginCommandBuffer();
15653
15654 m_commandBuffer->BindPipeline(pipe);
15655 m_commandBuffer->BindDescriptorSet(descriptorSet);
15656
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015657 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015658 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015659 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015660 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15661
15662 // error produced here.
15663 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15664
15665 m_errorMonitor->VerifyFound();
15666
15667 EndCommandBuffer();
15668}
15669
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015670#endif // SHADER_CHECKER_TESTS
15671
15672#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060015673TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015675
15676 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015677
15678 // Create an image
15679 VkImage image;
15680
Karl Schultz6addd812016-02-02 17:17:23 -070015681 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15682 const int32_t tex_width = 32;
15683 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015684
15685 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015686 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 = tex_format;
15690 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015691 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015692 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_LINEAR;
15697 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15698 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015699
15700 // Introduce error by sending down a bogus width extent
15701 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015702 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015703
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015704 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015705}
15706
Mark Youngc48c4c12016-04-11 14:26:49 -060015707TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15709 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060015710
15711 ASSERT_NO_FATAL_FAILURE(InitState());
15712
15713 // Create an image
15714 VkImage image;
15715
15716 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15717 const int32_t tex_width = 32;
15718 const int32_t tex_height = 32;
15719
15720 VkImageCreateInfo image_create_info = {};
15721 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15722 image_create_info.pNext = NULL;
15723 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15724 image_create_info.format = tex_format;
15725 image_create_info.extent.width = tex_width;
15726 image_create_info.extent.height = tex_height;
15727 image_create_info.extent.depth = 1;
15728 image_create_info.mipLevels = 1;
15729 image_create_info.arrayLayers = 1;
15730 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15731 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15732 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15733 image_create_info.flags = 0;
15734
15735 // Introduce error by sending down a bogus width extent
15736 image_create_info.extent.width = 0;
15737 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15738
15739 m_errorMonitor->VerifyFound();
15740}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015741#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120015742
Tobin Ehliscde08892015-09-22 10:11:37 -060015743#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015744TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
15745 TEST_DESCRIPTION("Create a render pass with an attachment description "
15746 "format set to VK_FORMAT_UNDEFINED");
15747
15748 ASSERT_NO_FATAL_FAILURE(InitState());
15749 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15750
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015752
15753 VkAttachmentReference color_attach = {};
15754 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15755 color_attach.attachment = 0;
15756 VkSubpassDescription subpass = {};
15757 subpass.colorAttachmentCount = 1;
15758 subpass.pColorAttachments = &color_attach;
15759
15760 VkRenderPassCreateInfo rpci = {};
15761 rpci.subpassCount = 1;
15762 rpci.pSubpasses = &subpass;
15763 rpci.attachmentCount = 1;
15764 VkAttachmentDescription attach_desc = {};
15765 attach_desc.format = VK_FORMAT_UNDEFINED;
15766 rpci.pAttachments = &attach_desc;
15767 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15768 VkRenderPass rp;
15769 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15770
15771 m_errorMonitor->VerifyFound();
15772
15773 if (result == VK_SUCCESS) {
15774 vkDestroyRenderPass(m_device->device(), rp, NULL);
15775 }
15776}
15777
Karl Schultz6addd812016-02-02 17:17:23 -070015778TEST_F(VkLayerTest, InvalidImageView) {
15779 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015780
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015782
Tobin Ehliscde08892015-09-22 10:11:37 -060015783 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015784
Mike Stroyana3082432015-09-25 13:39:21 -060015785 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015786 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015787
Karl Schultz6addd812016-02-02 17:17:23 -070015788 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15789 const int32_t tex_width = 32;
15790 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015791
15792 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015793 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15794 image_create_info.pNext = NULL;
15795 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15796 image_create_info.format = tex_format;
15797 image_create_info.extent.width = tex_width;
15798 image_create_info.extent.height = tex_height;
15799 image_create_info.extent.depth = 1;
15800 image_create_info.mipLevels = 1;
15801 image_create_info.arrayLayers = 1;
15802 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15803 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15804 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15805 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015806
Chia-I Wuf7458c52015-10-26 21:10:41 +080015807 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015808 ASSERT_VK_SUCCESS(err);
15809
15810 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015811 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15812 image_view_create_info.image = image;
15813 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15814 image_view_create_info.format = tex_format;
15815 image_view_create_info.subresourceRange.layerCount = 1;
15816 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
15817 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015818 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015819
15820 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015821 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015822
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015823 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015824 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015825}
Mike Stroyana3082432015-09-25 13:39:21 -060015826
Mark Youngd339ba32016-05-30 13:28:35 -060015827TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15828 VkResult err;
15829
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindImageMemory");
Mark Youngd339ba32016-05-30 13:28:35 -060015831
15832 ASSERT_NO_FATAL_FAILURE(InitState());
15833
15834 // Create an image and try to create a view with no memory backing the image
15835 VkImage image;
15836
15837 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15838 const int32_t tex_width = 32;
15839 const int32_t tex_height = 32;
15840
15841 VkImageCreateInfo image_create_info = {};
15842 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15843 image_create_info.pNext = NULL;
15844 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15845 image_create_info.format = tex_format;
15846 image_create_info.extent.width = tex_width;
15847 image_create_info.extent.height = tex_height;
15848 image_create_info.extent.depth = 1;
15849 image_create_info.mipLevels = 1;
15850 image_create_info.arrayLayers = 1;
15851 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15852 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15853 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15854 image_create_info.flags = 0;
15855
15856 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15857 ASSERT_VK_SUCCESS(err);
15858
15859 VkImageViewCreateInfo image_view_create_info = {};
15860 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15861 image_view_create_info.image = image;
15862 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15863 image_view_create_info.format = tex_format;
15864 image_view_create_info.subresourceRange.layerCount = 1;
15865 image_view_create_info.subresourceRange.baseMipLevel = 0;
15866 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015867 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015868
15869 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015870 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015871
15872 m_errorMonitor->VerifyFound();
15873 vkDestroyImage(m_device->device(), image, NULL);
15874 // If last error is success, it still created the view, so delete it.
15875 if (err == VK_SUCCESS) {
15876 vkDestroyImageView(m_device->device(), view, NULL);
15877 }
Mark Youngd339ba32016-05-30 13:28:35 -060015878}
15879
Karl Schultz6addd812016-02-02 17:17:23 -070015880TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015881 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
15882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView: Color image "
15883 "formats must have ONLY the "
15884 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015885
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015886 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015887
Karl Schultz6addd812016-02-02 17:17:23 -070015888 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015889 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015890 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015891 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015892
15893 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015894 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015895 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015896 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15897 image_view_create_info.format = tex_format;
15898 image_view_create_info.subresourceRange.baseMipLevel = 0;
15899 image_view_create_info.subresourceRange.levelCount = 1;
15900 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015901 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015902
15903 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015904 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015905
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015906 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015907}
15908
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015909TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015910 VkResult err;
15911 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015912
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15914 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015915
Mike Stroyana3082432015-09-25 13:39:21 -060015916 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015917
15918 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015919 VkImage srcImage;
15920 VkImage dstImage;
15921 VkDeviceMemory srcMem;
15922 VkDeviceMemory destMem;
15923 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015924
15925 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015926 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15927 image_create_info.pNext = NULL;
15928 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15929 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15930 image_create_info.extent.width = 32;
15931 image_create_info.extent.height = 32;
15932 image_create_info.extent.depth = 1;
15933 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015934 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015935 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15936 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15937 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15938 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015939
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015940 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015941 ASSERT_VK_SUCCESS(err);
15942
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015943 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015944 ASSERT_VK_SUCCESS(err);
15945
15946 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015947 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015948 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15949 memAlloc.pNext = NULL;
15950 memAlloc.allocationSize = 0;
15951 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015952
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015953 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015954 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015955 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015956 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015957 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015958 ASSERT_VK_SUCCESS(err);
15959
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015960 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015961 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015962 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015963 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015964 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015965 ASSERT_VK_SUCCESS(err);
15966
15967 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15968 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015969 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015970 ASSERT_VK_SUCCESS(err);
15971
15972 BeginCommandBuffer();
15973 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015974 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015975 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015976 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015977 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015978 copyRegion.srcOffset.x = 0;
15979 copyRegion.srcOffset.y = 0;
15980 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015981 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015982 copyRegion.dstSubresource.mipLevel = 0;
15983 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015984 // Introduce failure by forcing the dst layerCount to differ from src
15985 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015986 copyRegion.dstOffset.x = 0;
15987 copyRegion.dstOffset.y = 0;
15988 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015989 copyRegion.extent.width = 1;
15990 copyRegion.extent.height = 1;
15991 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015992 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015993 EndCommandBuffer();
15994
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015995 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015996
Chia-I Wuf7458c52015-10-26 21:10:41 +080015997 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015998 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015999 vkFreeMemory(m_device->device(), srcMem, NULL);
16000 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016001}
16002
Tony Barbourd6673642016-05-05 14:46:39 -060016003TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
16004
16005 TEST_DESCRIPTION("Creating images with unsuported formats ");
16006
16007 ASSERT_NO_FATAL_FAILURE(InitState());
16008 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16009 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016010 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 -060016011 VK_IMAGE_TILING_OPTIMAL, 0);
16012 ASSERT_TRUE(image.initialized());
16013
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016014 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
16015 VkImageCreateInfo image_create_info;
16016 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16017 image_create_info.pNext = NULL;
16018 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16019 image_create_info.format = VK_FORMAT_UNDEFINED;
16020 image_create_info.extent.width = 32;
16021 image_create_info.extent.height = 32;
16022 image_create_info.extent.depth = 1;
16023 image_create_info.mipLevels = 1;
16024 image_create_info.arrayLayers = 1;
16025 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16026 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16027 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16028 image_create_info.flags = 0;
16029
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16031 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016032
16033 VkImage localImage;
16034 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
16035 m_errorMonitor->VerifyFound();
16036
Tony Barbourd6673642016-05-05 14:46:39 -060016037 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016038 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060016039 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
16040 VkFormat format = static_cast<VkFormat>(f);
16041 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016042 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060016043 unsupported = format;
16044 break;
16045 }
16046 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016047
Tony Barbourd6673642016-05-05 14:46:39 -060016048 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060016049 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060016051
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016052 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060016053 m_errorMonitor->VerifyFound();
16054 }
16055}
16056
16057TEST_F(VkLayerTest, ImageLayerViewTests) {
16058 VkResult ret;
16059 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
16060
16061 ASSERT_NO_FATAL_FAILURE(InitState());
16062
16063 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016064 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 -060016065 VK_IMAGE_TILING_OPTIMAL, 0);
16066 ASSERT_TRUE(image.initialized());
16067
16068 VkImageView imgView;
16069 VkImageViewCreateInfo imgViewInfo = {};
16070 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16071 imgViewInfo.image = image.handle();
16072 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
16073 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16074 imgViewInfo.subresourceRange.layerCount = 1;
16075 imgViewInfo.subresourceRange.baseMipLevel = 0;
16076 imgViewInfo.subresourceRange.levelCount = 1;
16077 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16078
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060016080 // View can't have baseMipLevel >= image's mipLevels - Expect
16081 // VIEW_CREATE_ERROR
16082 imgViewInfo.subresourceRange.baseMipLevel = 1;
16083 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16084 m_errorMonitor->VerifyFound();
16085 imgViewInfo.subresourceRange.baseMipLevel = 0;
16086
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060016088 // View can't have baseArrayLayer >= image's arraySize - Expect
16089 // VIEW_CREATE_ERROR
16090 imgViewInfo.subresourceRange.baseArrayLayer = 1;
16091 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16092 m_errorMonitor->VerifyFound();
16093 imgViewInfo.subresourceRange.baseArrayLayer = 0;
16094
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
16096 "pCreateInfo->subresourceRange."
16097 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060016098 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
16099 imgViewInfo.subresourceRange.levelCount = 0;
16100 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16101 m_errorMonitor->VerifyFound();
16102 imgViewInfo.subresourceRange.levelCount = 1;
16103
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
16105 "pCreateInfo->subresourceRange."
16106 "layerCount");
Tony Barbourd6673642016-05-05 14:46:39 -060016107 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
16108 imgViewInfo.subresourceRange.layerCount = 0;
16109 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16110 m_errorMonitor->VerifyFound();
16111 imgViewInfo.subresourceRange.layerCount = 1;
16112
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tony Barbourd6673642016-05-05 14:46:39 -060016114 // Can't use depth format for view into color image - Expect INVALID_FORMAT
16115 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
16116 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16117 m_errorMonitor->VerifyFound();
16118 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16119
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
16121 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
16122 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060016123 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
16124 // VIEW_CREATE_ERROR
16125 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
16126 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16127 m_errorMonitor->VerifyFound();
16128 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16129
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
16131 "differing formats but they must be "
16132 "in the same compatibility class.");
Tony Barbourd6673642016-05-05 14:46:39 -060016133 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
16134 // VIEW_CREATE_ERROR
16135 VkImageCreateInfo mutImgInfo = image.create_info();
16136 VkImage mutImage;
16137 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016138 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060016139 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
16140 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16141 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
16142 ASSERT_VK_SUCCESS(ret);
16143 imgViewInfo.image = mutImage;
16144 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16145 m_errorMonitor->VerifyFound();
16146 imgViewInfo.image = image.handle();
16147 vkDestroyImage(m_device->handle(), mutImage, NULL);
16148}
16149
16150TEST_F(VkLayerTest, MiscImageLayerTests) {
16151
16152 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
16153
16154 ASSERT_NO_FATAL_FAILURE(InitState());
16155
16156 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016157 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 -060016158 VK_IMAGE_TILING_OPTIMAL, 0);
16159 ASSERT_TRUE(image.initialized());
16160
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060016162 vk_testing::Buffer buffer;
16163 VkMemoryPropertyFlags reqs = 0;
16164 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
16165 VkBufferImageCopy region = {};
16166 region.bufferRowLength = 128;
16167 region.bufferImageHeight = 128;
16168 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16169 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16170 region.imageSubresource.layerCount = 0;
16171 region.imageExtent.height = 4;
16172 region.imageExtent.width = 4;
16173 region.imageExtent.depth = 1;
16174 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016175 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16176 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060016177 m_errorMonitor->VerifyFound();
16178 region.imageSubresource.layerCount = 1;
16179
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016180 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16181 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
16182 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
16184 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16185 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016186 m_errorMonitor->VerifyFound();
16187
16188 // BufferOffset must be a multiple of 4
16189 // Introduce failure by setting bufferOffset to a value not divisible by 4
16190 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016191 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
16192 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16193 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016194 m_errorMonitor->VerifyFound();
16195
16196 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16197 region.bufferOffset = 0;
16198 region.imageExtent.height = 128;
16199 region.imageExtent.width = 128;
16200 // Introduce failure by setting bufferRowLength > 0 but less than width
16201 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16203 "must be zero or greater-than-or-equal-to imageExtent.width");
16204 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16205 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016206 m_errorMonitor->VerifyFound();
16207
16208 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16209 region.bufferRowLength = 128;
16210 // Introduce failure by setting bufferRowHeight > 0 but less than height
16211 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16213 "must be zero or greater-than-or-equal-to imageExtent.height");
16214 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16215 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016216 m_errorMonitor->VerifyFound();
16217
16218 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
16220 "specify only COLOR or DEPTH or "
16221 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060016222 // Expect MISMATCHED_IMAGE_ASPECT
16223 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016224 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16225 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060016226 m_errorMonitor->VerifyFound();
16227 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16228
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16230 "If the format of srcImage is a depth, stencil, depth stencil or "
16231 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060016232 // Expect INVALID_FILTER
16233 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016234 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 -060016235 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016236 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 -060016237 VkImageBlit blitRegion = {};
16238 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16239 blitRegion.srcSubresource.baseArrayLayer = 0;
16240 blitRegion.srcSubresource.layerCount = 1;
16241 blitRegion.srcSubresource.mipLevel = 0;
16242 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16243 blitRegion.dstSubresource.baseArrayLayer = 0;
16244 blitRegion.dstSubresource.layerCount = 1;
16245 blitRegion.dstSubresource.mipLevel = 0;
16246
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016247 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16248 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060016249 m_errorMonitor->VerifyFound();
16250
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016251 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
16253 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16254 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016255 m_errorMonitor->VerifyFound();
16256
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060016258 VkImageMemoryBarrier img_barrier;
16259 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16260 img_barrier.pNext = NULL;
16261 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16262 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16263 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16264 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16265 img_barrier.image = image.handle();
16266 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16267 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16268 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16269 img_barrier.subresourceRange.baseArrayLayer = 0;
16270 img_barrier.subresourceRange.baseMipLevel = 0;
16271 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
16272 img_barrier.subresourceRange.layerCount = 0;
16273 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016274 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16275 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016276 m_errorMonitor->VerifyFound();
16277 img_barrier.subresourceRange.layerCount = 1;
16278}
16279
16280TEST_F(VkLayerTest, ImageFormatLimits) {
16281
16282 TEST_DESCRIPTION("Exceed the limits of image format ");
16283
Cody Northropc31a84f2016-08-22 10:41:47 -060016284 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016286 VkImageCreateInfo image_create_info = {};
16287 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16288 image_create_info.pNext = NULL;
16289 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16290 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16291 image_create_info.extent.width = 32;
16292 image_create_info.extent.height = 32;
16293 image_create_info.extent.depth = 1;
16294 image_create_info.mipLevels = 1;
16295 image_create_info.arrayLayers = 1;
16296 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16297 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16298 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16299 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16300 image_create_info.flags = 0;
16301
16302 VkImage nullImg;
16303 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016304 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16305 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060016306 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
16307 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16308 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16309 m_errorMonitor->VerifyFound();
16310 image_create_info.extent.depth = 1;
16311
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016313 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16314 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16315 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16316 m_errorMonitor->VerifyFound();
16317 image_create_info.mipLevels = 1;
16318
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016320 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16321 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16322 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16323 m_errorMonitor->VerifyFound();
16324 image_create_info.arrayLayers = 1;
16325
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016327 int samples = imgFmtProps.sampleCounts >> 1;
16328 image_create_info.samples = (VkSampleCountFlagBits)samples;
16329 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16330 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16331 m_errorMonitor->VerifyFound();
16332 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16333
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
16335 "VK_IMAGE_LAYOUT_UNDEFINED or "
16336 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016337 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16338 // Expect INVALID_LAYOUT
16339 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16340 m_errorMonitor->VerifyFound();
16341 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16342}
16343
Karl Schultz6addd812016-02-02 17:17:23 -070016344TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016345 VkResult err;
16346 bool pass;
16347
16348 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16350 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060016351
16352 ASSERT_NO_FATAL_FAILURE(InitState());
16353
16354 // Create two images of different types and try to copy between them
16355 VkImage srcImage;
16356 VkImage dstImage;
16357 VkDeviceMemory srcMem;
16358 VkDeviceMemory destMem;
16359 VkMemoryRequirements memReqs;
16360
16361 VkImageCreateInfo image_create_info = {};
16362 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16363 image_create_info.pNext = NULL;
16364 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16365 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16366 image_create_info.extent.width = 32;
16367 image_create_info.extent.height = 32;
16368 image_create_info.extent.depth = 1;
16369 image_create_info.mipLevels = 1;
16370 image_create_info.arrayLayers = 1;
16371 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16372 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16373 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16374 image_create_info.flags = 0;
16375
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016376 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016377 ASSERT_VK_SUCCESS(err);
16378
16379 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16380 // Introduce failure by creating second image with a different-sized format.
16381 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16382
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016383 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016384 ASSERT_VK_SUCCESS(err);
16385
16386 // Allocate memory
16387 VkMemoryAllocateInfo memAlloc = {};
16388 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16389 memAlloc.pNext = NULL;
16390 memAlloc.allocationSize = 0;
16391 memAlloc.memoryTypeIndex = 0;
16392
16393 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16394 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016395 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016396 ASSERT_TRUE(pass);
16397 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16398 ASSERT_VK_SUCCESS(err);
16399
16400 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16401 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016402 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016403 ASSERT_TRUE(pass);
16404 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16405 ASSERT_VK_SUCCESS(err);
16406
16407 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16408 ASSERT_VK_SUCCESS(err);
16409 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16410 ASSERT_VK_SUCCESS(err);
16411
16412 BeginCommandBuffer();
16413 VkImageCopy copyRegion;
16414 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16415 copyRegion.srcSubresource.mipLevel = 0;
16416 copyRegion.srcSubresource.baseArrayLayer = 0;
16417 copyRegion.srcSubresource.layerCount = 0;
16418 copyRegion.srcOffset.x = 0;
16419 copyRegion.srcOffset.y = 0;
16420 copyRegion.srcOffset.z = 0;
16421 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16422 copyRegion.dstSubresource.mipLevel = 0;
16423 copyRegion.dstSubresource.baseArrayLayer = 0;
16424 copyRegion.dstSubresource.layerCount = 0;
16425 copyRegion.dstOffset.x = 0;
16426 copyRegion.dstOffset.y = 0;
16427 copyRegion.dstOffset.z = 0;
16428 copyRegion.extent.width = 1;
16429 copyRegion.extent.height = 1;
16430 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016431 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060016432 EndCommandBuffer();
16433
16434 m_errorMonitor->VerifyFound();
16435
16436 vkDestroyImage(m_device->device(), srcImage, NULL);
16437 vkDestroyImage(m_device->device(), dstImage, NULL);
16438 vkFreeMemory(m_device->device(), srcMem, NULL);
16439 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016440}
16441
Karl Schultz6addd812016-02-02 17:17:23 -070016442TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16443 VkResult err;
16444 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016445
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016446 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16448 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016449
Mike Stroyana3082432015-09-25 13:39:21 -060016450 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016451
16452 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016453 VkImage srcImage;
16454 VkImage dstImage;
16455 VkDeviceMemory srcMem;
16456 VkDeviceMemory destMem;
16457 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016458
16459 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016460 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16461 image_create_info.pNext = NULL;
16462 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16463 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16464 image_create_info.extent.width = 32;
16465 image_create_info.extent.height = 32;
16466 image_create_info.extent.depth = 1;
16467 image_create_info.mipLevels = 1;
16468 image_create_info.arrayLayers = 1;
16469 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16470 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16471 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16472 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016473
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016474 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016475 ASSERT_VK_SUCCESS(err);
16476
Karl Schultzbdb75952016-04-19 11:36:49 -060016477 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16478
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016479 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016480 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016481 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16482 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016483
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016484 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016485 ASSERT_VK_SUCCESS(err);
16486
16487 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016488 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016489 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16490 memAlloc.pNext = NULL;
16491 memAlloc.allocationSize = 0;
16492 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016493
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016494 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016495 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016496 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016497 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016498 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016499 ASSERT_VK_SUCCESS(err);
16500
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016501 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016502 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016503 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016504 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016505 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016506 ASSERT_VK_SUCCESS(err);
16507
16508 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16509 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016510 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016511 ASSERT_VK_SUCCESS(err);
16512
16513 BeginCommandBuffer();
16514 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016515 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016516 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016517 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016518 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016519 copyRegion.srcOffset.x = 0;
16520 copyRegion.srcOffset.y = 0;
16521 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016522 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016523 copyRegion.dstSubresource.mipLevel = 0;
16524 copyRegion.dstSubresource.baseArrayLayer = 0;
16525 copyRegion.dstSubresource.layerCount = 0;
16526 copyRegion.dstOffset.x = 0;
16527 copyRegion.dstOffset.y = 0;
16528 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016529 copyRegion.extent.width = 1;
16530 copyRegion.extent.height = 1;
16531 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016532 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016533 EndCommandBuffer();
16534
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016535 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016536
Chia-I Wuf7458c52015-10-26 21:10:41 +080016537 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016538 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016539 vkFreeMemory(m_device->device(), srcMem, NULL);
16540 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016541}
16542
Karl Schultz6addd812016-02-02 17:17:23 -070016543TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16544 VkResult err;
16545 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016546
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16548 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016549
Mike Stroyana3082432015-09-25 13:39:21 -060016550 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016551
16552 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016553 VkImage srcImage;
16554 VkImage dstImage;
16555 VkDeviceMemory srcMem;
16556 VkDeviceMemory destMem;
16557 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016558
16559 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016560 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16561 image_create_info.pNext = NULL;
16562 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16563 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16564 image_create_info.extent.width = 32;
16565 image_create_info.extent.height = 1;
16566 image_create_info.extent.depth = 1;
16567 image_create_info.mipLevels = 1;
16568 image_create_info.arrayLayers = 1;
16569 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16570 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16571 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16572 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016573
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016574 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016575 ASSERT_VK_SUCCESS(err);
16576
Karl Schultz6addd812016-02-02 17:17:23 -070016577 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016578
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016579 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016580 ASSERT_VK_SUCCESS(err);
16581
16582 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016583 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016584 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16585 memAlloc.pNext = NULL;
16586 memAlloc.allocationSize = 0;
16587 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016588
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016589 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016590 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016591 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016592 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016593 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016594 ASSERT_VK_SUCCESS(err);
16595
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016596 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016597 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016598 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016599 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016600 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016601 ASSERT_VK_SUCCESS(err);
16602
16603 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16604 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016605 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016606 ASSERT_VK_SUCCESS(err);
16607
16608 BeginCommandBuffer();
16609 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016610 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16611 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016612 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016613 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016614 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016615 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016616 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016617 resolveRegion.srcOffset.x = 0;
16618 resolveRegion.srcOffset.y = 0;
16619 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016620 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016621 resolveRegion.dstSubresource.mipLevel = 0;
16622 resolveRegion.dstSubresource.baseArrayLayer = 0;
16623 resolveRegion.dstSubresource.layerCount = 0;
16624 resolveRegion.dstOffset.x = 0;
16625 resolveRegion.dstOffset.y = 0;
16626 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016627 resolveRegion.extent.width = 1;
16628 resolveRegion.extent.height = 1;
16629 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016630 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016631 EndCommandBuffer();
16632
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016633 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016634
Chia-I Wuf7458c52015-10-26 21:10:41 +080016635 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016636 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016637 vkFreeMemory(m_device->device(), srcMem, NULL);
16638 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016639}
16640
Karl Schultz6addd812016-02-02 17:17:23 -070016641TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16642 VkResult err;
16643 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016644
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16646 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016647
Mike Stroyana3082432015-09-25 13:39:21 -060016648 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016649
Chris Forbesa7530692016-05-08 12:35:39 +120016650 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016651 VkImage srcImage;
16652 VkImage dstImage;
16653 VkDeviceMemory srcMem;
16654 VkDeviceMemory destMem;
16655 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016656
16657 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016658 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16659 image_create_info.pNext = NULL;
16660 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16661 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16662 image_create_info.extent.width = 32;
16663 image_create_info.extent.height = 1;
16664 image_create_info.extent.depth = 1;
16665 image_create_info.mipLevels = 1;
16666 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016667 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016668 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16669 // Note: Some implementations expect color attachment usage for any
16670 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016671 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016672 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016673
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016674 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016675 ASSERT_VK_SUCCESS(err);
16676
Karl Schultz6addd812016-02-02 17:17:23 -070016677 // Note: Some implementations expect color attachment usage for any
16678 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016679 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016680
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016681 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016682 ASSERT_VK_SUCCESS(err);
16683
16684 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016685 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016686 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16687 memAlloc.pNext = NULL;
16688 memAlloc.allocationSize = 0;
16689 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016690
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016691 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016692 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016693 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016694 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016695 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016696 ASSERT_VK_SUCCESS(err);
16697
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016698 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016699 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016700 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016701 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016702 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016703 ASSERT_VK_SUCCESS(err);
16704
16705 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16706 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016707 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016708 ASSERT_VK_SUCCESS(err);
16709
16710 BeginCommandBuffer();
16711 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016712 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16713 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016714 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016715 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016716 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016717 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016718 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016719 resolveRegion.srcOffset.x = 0;
16720 resolveRegion.srcOffset.y = 0;
16721 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016722 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016723 resolveRegion.dstSubresource.mipLevel = 0;
16724 resolveRegion.dstSubresource.baseArrayLayer = 0;
16725 resolveRegion.dstSubresource.layerCount = 0;
16726 resolveRegion.dstOffset.x = 0;
16727 resolveRegion.dstOffset.y = 0;
16728 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016729 resolveRegion.extent.width = 1;
16730 resolveRegion.extent.height = 1;
16731 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016732 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016733 EndCommandBuffer();
16734
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016735 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016736
Chia-I Wuf7458c52015-10-26 21:10:41 +080016737 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016738 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016739 vkFreeMemory(m_device->device(), srcMem, NULL);
16740 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016741}
16742
Karl Schultz6addd812016-02-02 17:17:23 -070016743TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16744 VkResult err;
16745 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016746
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16748 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016749
Mike Stroyana3082432015-09-25 13:39:21 -060016750 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016751
16752 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016753 VkImage srcImage;
16754 VkImage dstImage;
16755 VkDeviceMemory srcMem;
16756 VkDeviceMemory destMem;
16757 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016758
16759 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016760 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16761 image_create_info.pNext = NULL;
16762 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16763 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16764 image_create_info.extent.width = 32;
16765 image_create_info.extent.height = 1;
16766 image_create_info.extent.depth = 1;
16767 image_create_info.mipLevels = 1;
16768 image_create_info.arrayLayers = 1;
16769 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16770 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16771 // Note: Some implementations expect color attachment usage for any
16772 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016773 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016774 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016775
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016776 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016777 ASSERT_VK_SUCCESS(err);
16778
Karl Schultz6addd812016-02-02 17:17:23 -070016779 // Set format to something other than source image
16780 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16781 // Note: Some implementations expect color attachment usage for any
16782 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016783 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016784 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016785
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016786 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016787 ASSERT_VK_SUCCESS(err);
16788
16789 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016790 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016791 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16792 memAlloc.pNext = NULL;
16793 memAlloc.allocationSize = 0;
16794 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016795
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016796 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016797 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016798 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016799 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016800 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016801 ASSERT_VK_SUCCESS(err);
16802
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016803 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016804 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016805 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016806 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016807 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016808 ASSERT_VK_SUCCESS(err);
16809
16810 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16811 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016812 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016813 ASSERT_VK_SUCCESS(err);
16814
16815 BeginCommandBuffer();
16816 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016817 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16818 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016819 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016820 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016821 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016822 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016823 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016824 resolveRegion.srcOffset.x = 0;
16825 resolveRegion.srcOffset.y = 0;
16826 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016827 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016828 resolveRegion.dstSubresource.mipLevel = 0;
16829 resolveRegion.dstSubresource.baseArrayLayer = 0;
16830 resolveRegion.dstSubresource.layerCount = 0;
16831 resolveRegion.dstOffset.x = 0;
16832 resolveRegion.dstOffset.y = 0;
16833 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016834 resolveRegion.extent.width = 1;
16835 resolveRegion.extent.height = 1;
16836 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016837 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016838 EndCommandBuffer();
16839
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016840 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016841
Chia-I Wuf7458c52015-10-26 21:10:41 +080016842 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016843 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016844 vkFreeMemory(m_device->device(), srcMem, NULL);
16845 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016846}
16847
Karl Schultz6addd812016-02-02 17:17:23 -070016848TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
16849 VkResult err;
16850 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016851
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16853 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016854
Mike Stroyana3082432015-09-25 13:39:21 -060016855 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016856
16857 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016858 VkImage srcImage;
16859 VkImage dstImage;
16860 VkDeviceMemory srcMem;
16861 VkDeviceMemory destMem;
16862 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016863
16864 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016865 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16866 image_create_info.pNext = NULL;
16867 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16868 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16869 image_create_info.extent.width = 32;
16870 image_create_info.extent.height = 1;
16871 image_create_info.extent.depth = 1;
16872 image_create_info.mipLevels = 1;
16873 image_create_info.arrayLayers = 1;
16874 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16875 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16876 // Note: Some implementations expect color attachment usage for any
16877 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016878 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016879 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016880
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016881 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016882 ASSERT_VK_SUCCESS(err);
16883
Karl Schultz6addd812016-02-02 17:17:23 -070016884 image_create_info.imageType = VK_IMAGE_TYPE_1D;
16885 // Note: Some implementations expect color attachment usage for any
16886 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016887 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016888 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016889
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016890 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016891 ASSERT_VK_SUCCESS(err);
16892
16893 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016894 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016895 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16896 memAlloc.pNext = NULL;
16897 memAlloc.allocationSize = 0;
16898 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016899
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016900 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016901 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016902 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016903 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016904 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016905 ASSERT_VK_SUCCESS(err);
16906
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016907 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016908 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016909 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016910 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016911 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016912 ASSERT_VK_SUCCESS(err);
16913
16914 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16915 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016916 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016917 ASSERT_VK_SUCCESS(err);
16918
16919 BeginCommandBuffer();
16920 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016921 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16922 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016923 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016924 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016925 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016926 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016927 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016928 resolveRegion.srcOffset.x = 0;
16929 resolveRegion.srcOffset.y = 0;
16930 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016931 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016932 resolveRegion.dstSubresource.mipLevel = 0;
16933 resolveRegion.dstSubresource.baseArrayLayer = 0;
16934 resolveRegion.dstSubresource.layerCount = 0;
16935 resolveRegion.dstOffset.x = 0;
16936 resolveRegion.dstOffset.y = 0;
16937 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016938 resolveRegion.extent.width = 1;
16939 resolveRegion.extent.height = 1;
16940 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016941 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016942 EndCommandBuffer();
16943
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016944 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016945
Chia-I Wuf7458c52015-10-26 21:10:41 +080016946 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016947 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016948 vkFreeMemory(m_device->device(), srcMem, NULL);
16949 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016950}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016951
Karl Schultz6addd812016-02-02 17:17:23 -070016952TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016953 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016954 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16955 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016956 // The image format check comes 2nd in validation so we trigger it first,
16957 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016958 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16961 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016962
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016963 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016964
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016965 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016966 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16967 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016968
16969 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016970 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16971 ds_pool_ci.pNext = NULL;
16972 ds_pool_ci.maxSets = 1;
16973 ds_pool_ci.poolSizeCount = 1;
16974 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016975
16976 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016977 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016978 ASSERT_VK_SUCCESS(err);
16979
16980 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016981 dsl_binding.binding = 0;
16982 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16983 dsl_binding.descriptorCount = 1;
16984 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16985 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016986
16987 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016988 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16989 ds_layout_ci.pNext = NULL;
16990 ds_layout_ci.bindingCount = 1;
16991 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016992 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016993 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016994 ASSERT_VK_SUCCESS(err);
16995
16996 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016997 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080016998 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070016999 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017000 alloc_info.descriptorPool = ds_pool;
17001 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017002 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017003 ASSERT_VK_SUCCESS(err);
17004
Karl Schultz6addd812016-02-02 17:17:23 -070017005 VkImage image_bad;
17006 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017007 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060017008 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017009 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017010 const int32_t tex_width = 32;
17011 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017012
17013 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017014 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17015 image_create_info.pNext = NULL;
17016 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17017 image_create_info.format = tex_format_bad;
17018 image_create_info.extent.width = tex_width;
17019 image_create_info.extent.height = tex_height;
17020 image_create_info.extent.depth = 1;
17021 image_create_info.mipLevels = 1;
17022 image_create_info.arrayLayers = 1;
17023 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17024 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017025 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017026 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017027
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017028 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017029 ASSERT_VK_SUCCESS(err);
17030 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017031 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17032 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017033 ASSERT_VK_SUCCESS(err);
17034
17035 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017036 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17037 image_view_create_info.image = image_bad;
17038 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17039 image_view_create_info.format = tex_format_bad;
17040 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17041 image_view_create_info.subresourceRange.baseMipLevel = 0;
17042 image_view_create_info.subresourceRange.layerCount = 1;
17043 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017044 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017045
17046 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017047 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017048
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017049 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017050
Chia-I Wuf7458c52015-10-26 21:10:41 +080017051 vkDestroyImage(m_device->device(), image_bad, NULL);
17052 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017053 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17054 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017055}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017056
17057TEST_F(VkLayerTest, ClearImageErrors) {
17058 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
17059 "ClearDepthStencilImage with a color image.");
17060
17061 ASSERT_NO_FATAL_FAILURE(InitState());
17062 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17063
17064 // Renderpass is started here so end it as Clear cmds can't be in renderpass
17065 BeginCommandBuffer();
17066 m_commandBuffer->EndRenderPass();
17067
17068 // Color image
17069 VkClearColorValue clear_color;
17070 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17071 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17072 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17073 const int32_t img_width = 32;
17074 const int32_t img_height = 32;
17075 VkImageCreateInfo image_create_info = {};
17076 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17077 image_create_info.pNext = NULL;
17078 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17079 image_create_info.format = color_format;
17080 image_create_info.extent.width = img_width;
17081 image_create_info.extent.height = img_height;
17082 image_create_info.extent.depth = 1;
17083 image_create_info.mipLevels = 1;
17084 image_create_info.arrayLayers = 1;
17085 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17086 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17087 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17088
17089 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017090 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017091
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017092 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017093
17094 // Depth/Stencil image
17095 VkClearDepthStencilValue clear_value = {0};
17096 reqs = 0; // don't need HOST_VISIBLE DS image
17097 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17098 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
17099 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
17100 ds_image_create_info.extent.width = 64;
17101 ds_image_create_info.extent.height = 64;
17102 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17103 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
17104
17105 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017106 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017107
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017108 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 -060017109
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017111
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017112 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017113 &color_range);
17114
17115 m_errorMonitor->VerifyFound();
17116
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
17118 "image created without "
17119 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017120
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017121 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017122 &color_range);
17123
17124 m_errorMonitor->VerifyFound();
17125
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017126 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17128 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017129
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017130 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
17131 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017132
17133 m_errorMonitor->VerifyFound();
17134}
Tobin Ehliscde08892015-09-22 10:11:37 -060017135#endif // IMAGE_TESTS
17136
Cody Northrop1242dfd2016-07-13 17:24:59 -060017137#if defined(ANDROID) && defined(VALIDATION_APK)
17138static bool initialized = false;
17139static bool active = false;
17140
17141// Convert Intents to argv
17142// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017143std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017144 std::vector<std::string> args;
17145 JavaVM &vm = *app.activity->vm;
17146 JNIEnv *p_env;
17147 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
17148 return args;
17149
17150 JNIEnv &env = *p_env;
17151 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017152 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060017153 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017154 jmethodID get_string_extra_method =
17155 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060017156 jvalue get_string_extra_args;
17157 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017158 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060017159
17160 std::string args_str;
17161 if (extra_str) {
17162 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
17163 args_str = extra_utf;
17164 env.ReleaseStringUTFChars(extra_str, extra_utf);
17165 env.DeleteLocalRef(extra_str);
17166 }
17167
17168 env.DeleteLocalRef(get_string_extra_args.l);
17169 env.DeleteLocalRef(intent);
17170 vm.DetachCurrentThread();
17171
17172 // split args_str
17173 std::stringstream ss(args_str);
17174 std::string arg;
17175 while (std::getline(ss, arg, ' ')) {
17176 if (!arg.empty())
17177 args.push_back(arg);
17178 }
17179
17180 return args;
17181}
17182
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017183static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017184
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017185static void processCommand(struct android_app *app, int32_t cmd) {
17186 switch (cmd) {
17187 case APP_CMD_INIT_WINDOW: {
17188 if (app->window) {
17189 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060017190 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017191 break;
17192 }
17193 case APP_CMD_GAINED_FOCUS: {
17194 active = true;
17195 break;
17196 }
17197 case APP_CMD_LOST_FOCUS: {
17198 active = false;
17199 break;
17200 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017201 }
17202}
17203
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017204void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017205 app_dummy();
17206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017207 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060017208
17209 int vulkanSupport = InitVulkan();
17210 if (vulkanSupport == 0) {
17211 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
17212 return;
17213 }
17214
17215 app->onAppCmd = processCommand;
17216 app->onInputEvent = processInput;
17217
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017218 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017219 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017220 struct android_poll_source *source;
17221 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017222 if (source) {
17223 source->process(app, source);
17224 }
17225
17226 if (app->destroyRequested != 0) {
17227 VkTestFramework::Finish();
17228 return;
17229 }
17230 }
17231
17232 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017233 // Use the following key to send arguments to gtest, i.e.
17234 // --es args "--gtest_filter=-VkLayerTest.foo"
17235 const char key[] = "args";
17236 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017238 std::string filter = "";
17239 if (args.size() > 0) {
17240 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
17241 filter += args[0];
17242 } else {
17243 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
17244 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017245
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017246 int argc = 2;
17247 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
17248 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017249
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017250 // Route output to files until we can override the gtest output
17251 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
17252 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017254 ::testing::InitGoogleTest(&argc, argv);
17255 VkTestFramework::InitArgs(&argc, argv);
17256 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017258 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017260 if (result != 0) {
17261 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
17262 } else {
17263 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
17264 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017265
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017266 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017267
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017268 fclose(stdout);
17269 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017271 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017272
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017273 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060017274 }
17275 }
17276}
17277#endif
17278
Tony Barbour300a6082015-04-07 13:44:53 -060017279int main(int argc, char **argv) {
17280 int result;
17281
Cody Northrop8e54a402016-03-08 22:25:52 -070017282#ifdef ANDROID
17283 int vulkanSupport = InitVulkan();
17284 if (vulkanSupport == 0)
17285 return 1;
17286#endif
17287
Tony Barbour300a6082015-04-07 13:44:53 -060017288 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060017289 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060017290
17291 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
17292
17293 result = RUN_ALL_TESTS();
17294
Tony Barbour6918cd52015-04-09 12:58:51 -060017295 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060017296 return result;
17297}