blob: bba6907bfd1c60e04a31221973d956096ac82919 [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>
20 */
Tony Barbour65c48b32015-11-17 10:02:56 -070021
Cody Northrop8e54a402016-03-08 22:25:52 -070022#ifdef ANDROID
23#include "vulkan_wrapper.h"
24#else
David Pinedo9316d3b2015-11-06 12:54:48 -070025#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070026#endif
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -060027#include "test_common.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060028#include "vkrenderframework.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060029#include "vk_layer_config.h"
Jon Ashburn7fa7e222016-02-02 12:08:10 -070030#include "icd-spv.h"
Tony Barbour300a6082015-04-07 13:44:53 -060031
Mark Lobodzinski3780e142015-05-14 15:08:13 -050032#define GLM_FORCE_RADIANS
33#include "glm/glm.hpp"
34#include <glm/gtc/matrix_transform.hpp>
35
Dustin Gravesffa90fa2016-05-06 11:20:38 -060036#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060037#define MEM_TRACKER_TESTS 1
38#define OBJ_TRACKER_TESTS 1
39#define DRAW_STATE_TESTS 1
40#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120041#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060042#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060043#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060044
Mark Lobodzinski3780e142015-05-14 15:08:13 -050045//--------------------------------------------------------------------------------------
46// Mesh and VertexFormat Data
47//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070048struct Vertex {
49 float posX, posY, posZ, posW; // Position data
50 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050051};
52
Karl Schultz6addd812016-02-02 17:17:23 -070053#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050054
55typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070056 BsoFailNone = 0x00000000,
57 BsoFailLineWidth = 0x00000001,
58 BsoFailDepthBias = 0x00000002,
59 BsoFailViewport = 0x00000004,
60 BsoFailScissor = 0x00000008,
61 BsoFailBlend = 0x00000010,
62 BsoFailDepthBounds = 0x00000020,
63 BsoFailStencilReadMask = 0x00000040,
64 BsoFailStencilWriteMask = 0x00000080,
65 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060066 BsoFailCmdClearAttachments = 0x00000200,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050067} BsoFailSelect;
68
69struct vktriangle_vs_uniform {
70 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070071 float mvp[4][4];
72 float position[3][4];
73 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050074};
75
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050076static const char bindStateVertShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120077 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070078 "vec2 vertices[3];\n"
79 "out gl_PerVertex {\n"
80 " vec4 gl_Position;\n"
81 "};\n"
82 "void main() {\n"
83 " vertices[0] = vec2(-1.0, -1.0);\n"
84 " vertices[1] = vec2( 1.0, -1.0);\n"
85 " vertices[2] = vec2( 0.0, 1.0);\n"
86 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
87 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050088
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050089static const char bindStateFragShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120090 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070091 "\n"
92 "layout(location = 0) out vec4 uFragColor;\n"
93 "void main(){\n"
94 " uFragColor = vec4(0,1,0,1);\n"
95 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050096
Karl Schultz6addd812016-02-02 17:17:23 -070097static VKAPI_ATTR VkBool32 VKAPI_CALL
98myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
99 uint64_t srcObject, size_t location, int32_t msgCode,
100 const char *pLayerPrefix, const char *pMsg, void *pUserData);
Tony Barbour300a6082015-04-07 13:44:53 -0600101
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600102// ********************************************************
103// ErrorMonitor Usage:
104//
105// Call SetDesiredFailureMsg with a string to be compared against all
106// encountered log messages. Passing NULL will match all log messages.
107// logMsg will return true for skipCall only if msg is matched or NULL.
108//
109// Call DesiredMsgFound to determine if the desired failure message
110// was encountered.
111
Tony Barbour300a6082015-04-07 13:44:53 -0600112class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700113 public:
114 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600115 test_platform_thread_create_mutex(&m_mutex);
116 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700117 m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700118 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600119 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600120 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600121
Dustin Graves48458142016-04-29 16:11:55 -0600122 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
123
Karl Schultz6addd812016-02-02 17:17:23 -0700124 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200125 // also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600126 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600127 m_failureMsg.clear();
128 m_otherMsgs.clear();
129 m_desiredMsg = msgString;
Karl Schultz6addd812016-02-02 17:17:23 -0700130 m_msgFound = VK_FALSE;
131 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600132 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600133 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600134
Karl Schultz6addd812016-02-02 17:17:23 -0700135 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600136 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600137 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600138 if (m_bailout != NULL) {
139 *m_bailout = true;
140 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600141 string errorString(msgString);
142 if (msgFlags & m_msgFlags) {
143 if (errorString.find(m_desiredMsg) != string::npos) {
Chris Forbesc7b8ad72016-04-04 18:50:38 +1200144 if (m_msgFound) { /* if multiple matches, don't lose all but the last! */
145 m_otherMsgs.push_back(m_failureMsg);
146 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600147 m_failureMsg = errorString;
Karl Schultz6addd812016-02-02 17:17:23 -0700148 m_msgFound = VK_TRUE;
149 result = VK_TRUE;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600150 } else {
151 m_otherMsgs.push_back(errorString);
152 }
153 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600154 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600155 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600156 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600157
Karl Schultz6addd812016-02-02 17:17:23 -0700158 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600159
Karl Schultz6addd812016-02-02 17:17:23 -0700160 string GetFailureMsg(void) { return m_failureMsg; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161
Karl Schultz6addd812016-02-02 17:17:23 -0700162 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600163
Karl Schultz6addd812016-02-02 17:17:23 -0700164 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600165
Karl Schultz6addd812016-02-02 17:17:23 -0700166 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600167 vector<string> otherMsgs = GetOtherFailureMsgs();
168 cout << "Other error messages logged for this test were:" << endl;
169 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
170 cout << " " << *iter << endl;
171 }
172 }
173
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200174 /* helpers */
175
176 void ExpectSuccess() {
177 // match anything
178 SetDesiredFailureMsg(~0u, "");
179 }
180
181 void VerifyFound() {
182 // Not seeing the desired message is a failure. /Before/ throwing, dump
183 // any other messages.
184 if (!DesiredMsgFound()) {
185 DumpFailureMsgs();
186 FAIL() << "Did not receive expected error '" << m_desiredMsg << "'";
187 }
188 }
189
190 void VerifyNotFound() {
191 // ExpectSuccess() configured us to match anything. Any error is a
192 // failure.
193 if (DesiredMsgFound()) {
194 DumpFailureMsgs();
195 FAIL() << "Expected to succeed but got error: " << GetFailureMsg();
196 }
197 }
198
Karl Schultz6addd812016-02-02 17:17:23 -0700199 private:
200 VkFlags m_msgFlags;
201 string m_desiredMsg;
202 string m_failureMsg;
203 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600204 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700205 bool *m_bailout;
206 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600207};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500208
Karl Schultz6addd812016-02-02 17:17:23 -0700209static VKAPI_ATTR VkBool32 VKAPI_CALL
210myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
211 uint64_t srcObject, size_t location, int32_t msgCode,
212 const char *pLayerPrefix, const char *pMsg, void *pUserData) {
213 if (msgFlags &
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700214 (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
Karl Schultz6addd812016-02-02 17:17:23 -0700215 VK_DEBUG_REPORT_ERROR_BIT_EXT)) {
Tony Barbour0b4d9562015-04-09 10:48:04 -0600216 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600217 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600218 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600219 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600220}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500221
Karl Schultz6addd812016-02-02 17:17:23 -0700222class VkLayerTest : public VkRenderFramework {
223 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800224 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
225 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700226 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText,
227 BsoFailSelect failMask);
228 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
229 VkPipelineObj &pipelineobj,
230 VkDescriptorSetObj &descriptorSet,
231 BsoFailSelect failMask);
232 void GenericDrawPreparation(VkPipelineObj &pipelineobj,
233 VkDescriptorSetObj &descriptorSet,
234 BsoFailSelect failMask) {
235 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet,
236 failMask);
237 }
Tony Barbour300a6082015-04-07 13:44:53 -0600238
Tony Barbourfe3351b2015-07-28 10:17:20 -0600239 /* Convenience functions that use built-in command buffer */
Karl Schultz6addd812016-02-02 17:17:23 -0700240 VkResult BeginCommandBuffer() {
241 return BeginCommandBuffer(*m_commandBuffer);
242 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800243 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Karl Schultz6addd812016-02-02 17:17:23 -0700244 void Draw(uint32_t vertexCount, uint32_t instanceCount,
245 uint32_t firstVertex, uint32_t firstInstance) {
246 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex,
247 firstInstance);
248 }
249 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount,
250 uint32_t firstIndex, int32_t vertexOffset,
251 uint32_t firstInstance) {
252 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex,
253 vertexOffset, firstInstance);
254 }
Mark Mueller979ba7b2016-06-22 19:40:33 -0600255 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
Karl Schultz6addd812016-02-02 17:17:23 -0700256 void QueueCommandBuffer(const VkFence &fence) {
257 m_commandBuffer->QueueCommandBuffer(fence);
258 }
259 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer,
260 VkDeviceSize offset, uint32_t binding) {
261 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
262 }
263 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
264 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
265 }
266
267 protected:
268 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600269 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600270
271 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600272 std::vector<const char *> instance_layer_names;
273 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600274 std::vector<const char *> instance_extension_names;
275 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600276
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700277 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600278 /*
279 * Since CreateDbgMsgCallback is an instance level extension call
280 * any extension / layer that utilizes that feature also needs
281 * to be enabled at create instance time.
282 */
Karl Schultz6addd812016-02-02 17:17:23 -0700283 // Use Threading layer first to protect others from
284 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700285 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600286 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800287 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700288 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800289 instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
290 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600291 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700292 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600293
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700294 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600295 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800296 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700297 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800298 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
299 device_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600300 device_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700301 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Tony Barbour300a6082015-04-07 13:44:53 -0600302
Ian Elliott2c1daf52016-05-12 09:41:46 -0600303 if (m_enableWSI) {
304 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
305 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
306#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
307#if defined(VK_USE_PLATFORM_ANDROID_KHR)
308 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
309#endif // VK_USE_PLATFORM_ANDROID_KHR
310#if defined(VK_USE_PLATFORM_MIR_KHR)
311 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
312#endif // VK_USE_PLATFORM_MIR_KHR
313#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
314 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
315#endif // VK_USE_PLATFORM_WAYLAND_KHR
316#if defined(VK_USE_PLATFORM_WIN32_KHR)
317 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
318#endif // VK_USE_PLATFORM_WIN32_KHR
319#endif // NEED_TO_TEST_THIS_ON_PLATFORM
320#if defined(VK_USE_PLATFORM_XCB_KHR)
321 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
322#elif defined(VK_USE_PLATFORM_XLIB_KHR)
323 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
324#endif // VK_USE_PLATFORM_XLIB_KHR
325 }
326
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600327 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600328 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800329 this->app_info.pApplicationName = "layer_tests";
330 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600331 this->app_info.pEngineName = "unittest";
332 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600333 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600334
Tony Barbour15524c32015-04-29 17:34:29 -0600335 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600336 InitFramework(instance_layer_names, device_layer_names,
337 instance_extension_names, device_extension_names,
338 myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600339 }
340
341 virtual void TearDown() {
342 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600343 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600344 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600345 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600346
347 VkLayerTest() {
348 m_enableWSI = false;
349 }
Tony Barbour300a6082015-04-07 13:44:53 -0600350};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500351
Karl Schultz6addd812016-02-02 17:17:23 -0700352VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600353 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600354
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800355 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600356
357 /*
358 * For render test all drawing happens in a single render pass
359 * on a single command buffer.
360 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200361 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800362 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600363 }
364
365 return result;
366}
367
Karl Schultz6addd812016-02-02 17:17:23 -0700368VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600369 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600370
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200371 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800372 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200373 }
Tony Barbour300a6082015-04-07 13:44:53 -0600374
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800375 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600376
377 return result;
378}
379
Karl Schultz6addd812016-02-02 17:17:23 -0700380void VkLayerTest::VKTriangleTest(const char *vertShaderText,
381 const char *fragShaderText,
382 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500383 // Create identity matrix
384 int i;
385 struct vktriangle_vs_uniform data;
386
387 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700388 glm::mat4 View = glm::mat4(1.0f);
389 glm::mat4 Model = glm::mat4(1.0f);
390 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500391 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700392 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500393
394 memcpy(&data.mvp, &MVP[0][0], matrixSize);
395
Karl Schultz6addd812016-02-02 17:17:23 -0700396 static const Vertex tri_data[] = {
397 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)},
398 {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)},
399 {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500400 };
401
Karl Schultz6addd812016-02-02 17:17:23 -0700402 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500403 data.position[i][0] = tri_data[i].posX;
404 data.position[i][1] = tri_data[i].posY;
405 data.position[i][2] = tri_data[i].posZ;
406 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700407 data.color[i][0] = tri_data[i].r;
408 data.color[i][1] = tri_data[i].g;
409 data.color[i][2] = tri_data[i].b;
410 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500411 }
412
413 ASSERT_NO_FATAL_FAILURE(InitState());
414 ASSERT_NO_FATAL_FAILURE(InitViewport());
415
Karl Schultz6addd812016-02-02 17:17:23 -0700416 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float),
417 (const void *)&data);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500418
Karl Schultz6addd812016-02-02 17:17:23 -0700419 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
420 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
421 this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500422
423 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800424 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425 pipelineobj.AddShader(&vs);
426 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600427 if (failMask & BsoFailLineWidth) {
428 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600429 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
430 ia_state.sType =
431 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
432 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
433 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600434 }
435 if (failMask & BsoFailDepthBias) {
436 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600437 VkPipelineRasterizationStateCreateInfo rs_state = {};
438 rs_state.sType =
439 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
440 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600441 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600442 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600443 }
Karl Schultz6addd812016-02-02 17:17:23 -0700444 // Viewport and scissors must stay in synch or other errors will occur than
445 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600446 if (failMask & BsoFailViewport) {
447 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600448 m_viewports.clear();
449 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600450 }
451 if (failMask & BsoFailScissor) {
452 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600453 m_scissors.clear();
454 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600455 }
456 if (failMask & BsoFailBlend) {
457 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600458 VkPipelineColorBlendAttachmentState att_state = {};
459 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
460 att_state.blendEnable = VK_TRUE;
461 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600462 }
463 if (failMask & BsoFailDepthBounds) {
464 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
465 }
466 if (failMask & BsoFailStencilReadMask) {
467 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
468 }
469 if (failMask & BsoFailStencilWriteMask) {
470 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
471 }
472 if (failMask & BsoFailStencilReference) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
474 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500475
476 VkDescriptorSetObj descriptorSet(m_device);
Karl Schultz6addd812016-02-02 17:17:23 -0700477 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
478 constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500479
480 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600481 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500482
Tony Barbourfe3351b2015-07-28 10:17:20 -0600483 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500484
485 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600486 Draw(3, 1, 0, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500487
Mark Muellerd4914412016-06-13 17:52:06 -0600488 if (failMask & BsoFailCmdClearAttachments) {
489 VkClearAttachment color_attachment = {};
490 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
491 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
492 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
493
494 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
495 &color_attachment, 1, &clear_rect);
496 }
497
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500498 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600499 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
Tony Barbourfe3351b2015-07-28 10:17:20 -0600501 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500502}
503
Karl Schultz6addd812016-02-02 17:17:23 -0700504void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
505 VkPipelineObj &pipelineobj,
506 VkDescriptorSetObj &descriptorSet,
507 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500508 if (m_depthStencil->Initialized()) {
Karl Schultz6addd812016-02-02 17:17:23 -0700509 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
510 m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500511 } else {
Karl Schultz6addd812016-02-02 17:17:23 -0700512 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
513 m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514 }
515
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800516 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700517 // Make sure depthWriteEnable is set so that Depth fail test will work
518 // correctly
519 // Make sure stencilTestEnable is set so that Stencil fail test will work
520 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600521 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800522 stencil.failOp = VK_STENCIL_OP_KEEP;
523 stencil.passOp = VK_STENCIL_OP_KEEP;
524 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
525 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600526
527 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
528 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600529 ds_ci.pNext = NULL;
530 ds_ci.depthTestEnable = VK_FALSE;
531 ds_ci.depthWriteEnable = VK_TRUE;
532 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
533 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600534 if (failMask & BsoFailDepthBounds) {
535 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600536 ds_ci.maxDepthBounds = 0.0f;
537 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600538 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600539 ds_ci.stencilTestEnable = VK_TRUE;
540 ds_ci.front = stencil;
541 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600542
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600543 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600544 pipelineobj.SetViewport(m_viewports);
545 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800546 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700547 VkResult err = pipelineobj.CreateVKPipeline(
548 descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600549 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800550 commandBuffer->BindPipeline(pipelineobj);
551 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500552}
553
Ian Elliott2c1daf52016-05-12 09:41:46 -0600554class VkWsiEnabledLayerTest : public VkLayerTest {
555 public:
556protected:
557 VkWsiEnabledLayerTest() {
558 m_enableWSI = true;
559 }
560};
561
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500562// ********************************************************************************************************************
563// ********************************************************************************************************************
564// ********************************************************************************************************************
565// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600566#if PARAMETER_VALIDATION_TESTS
567TEST_F(VkLayerTest, RequiredParameter) {
568 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
569 "pointer, array, and array count parameters");
570
571 ASSERT_NO_FATAL_FAILURE(InitState());
572
573 m_errorMonitor->SetDesiredFailureMsg(
574 VK_DEBUG_REPORT_ERROR_BIT_EXT,
575 "required parameter pFeatures specified as NULL");
576 // Specify NULL for a pointer to a handle
577 // Expected to trigger an error with
578 // parameter_validation::validate_required_pointer
579 vkGetPhysicalDeviceFeatures(gpu(), NULL);
580 m_errorMonitor->VerifyFound();
581
582 m_errorMonitor->SetDesiredFailureMsg(
583 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600584 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600585 // Specify NULL for pointer to array count
586 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600587 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600588 m_errorMonitor->VerifyFound();
589
590 m_errorMonitor->SetDesiredFailureMsg(
591 VK_DEBUG_REPORT_ERROR_BIT_EXT,
592 "parameter viewportCount must be greater than 0");
593 // Specify 0 for a required array count
594 // Expected to trigger an error with parameter_validation::validate_array
595 VkViewport view_port = {};
596 m_commandBuffer->SetViewport(0, 0, &view_port);
597 m_errorMonitor->VerifyFound();
598
599 m_errorMonitor->SetDesiredFailureMsg(
600 VK_DEBUG_REPORT_ERROR_BIT_EXT,
601 "required parameter pViewports specified as NULL");
602 // Specify NULL for a required array
603 // Expected to trigger an error with parameter_validation::validate_array
604 m_commandBuffer->SetViewport(0, 1, NULL);
605 m_errorMonitor->VerifyFound();
606
607 m_errorMonitor->SetDesiredFailureMsg(
608 VK_DEBUG_REPORT_ERROR_BIT_EXT,
609 "required parameter memory specified as VK_NULL_HANDLE");
610 // Specify VK_NULL_HANDLE for a required handle
611 // Expected to trigger an error with
612 // parameter_validation::validate_required_handle
613 vkUnmapMemory(device(), VK_NULL_HANDLE);
614 m_errorMonitor->VerifyFound();
615
616 m_errorMonitor->SetDesiredFailureMsg(
617 VK_DEBUG_REPORT_ERROR_BIT_EXT,
618 "required parameter pFences[0] specified as VK_NULL_HANDLE");
619 // Specify VK_NULL_HANDLE for a required handle array entry
620 // Expected to trigger an error with
621 // parameter_validation::validate_required_handle_array
622 VkFence fence = VK_NULL_HANDLE;
623 vkResetFences(device(), 1, &fence);
624 m_errorMonitor->VerifyFound();
625
626 m_errorMonitor->SetDesiredFailureMsg(
627 VK_DEBUG_REPORT_ERROR_BIT_EXT,
628 "required parameter pAllocateInfo specified as NULL");
629 // Specify NULL for a required struct pointer
630 // Expected to trigger an error with
631 // parameter_validation::validate_struct_type
632 VkDeviceMemory memory = VK_NULL_HANDLE;
633 vkAllocateMemory(device(), NULL, NULL, &memory);
634 m_errorMonitor->VerifyFound();
635
636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
637 "value of faceMask must not be 0");
638 // Specify 0 for a required VkFlags parameter
639 // Expected to trigger an error with parameter_validation::validate_flags
640 m_commandBuffer->SetStencilReference(0, 0);
641 m_errorMonitor->VerifyFound();
642
643 m_errorMonitor->SetDesiredFailureMsg(
644 VK_DEBUG_REPORT_ERROR_BIT_EXT,
645 "value of pSubmits[i].pWaitDstStageMask[0] must not be 0");
646 // Specify 0 for a required VkFlags array entry
647 // Expected to trigger an error with
648 // parameter_validation::validate_flags_array
649 VkSemaphore semaphore = VK_NULL_HANDLE;
650 VkPipelineStageFlags stageFlags = 0;
651 VkSubmitInfo submitInfo = {};
652 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
653 submitInfo.waitSemaphoreCount = 1;
654 submitInfo.pWaitSemaphores = &semaphore;
655 submitInfo.pWaitDstStageMask = &stageFlags;
656 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
657 m_errorMonitor->VerifyFound();
658}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600659
Dustin Gravesfce74c02016-05-10 11:42:58 -0600660TEST_F(VkLayerTest, ReservedParameter) {
661 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
662
663 ASSERT_NO_FATAL_FAILURE(InitState());
664
665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
666 " must be 0");
667 // Specify 0 for a reserved VkFlags parameter
668 // Expected to trigger an error with
669 // parameter_validation::validate_reserved_flags
670 VkEvent event_handle = VK_NULL_HANDLE;
671 VkEventCreateInfo event_info = {};
672 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
673 event_info.flags = 1;
674 vkCreateEvent(device(), &event_info, NULL, &event_handle);
675 m_errorMonitor->VerifyFound();
676}
677
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600678TEST_F(VkLayerTest, InvalidStructSType) {
679 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
680 "structure's sType field");
681
682 ASSERT_NO_FATAL_FAILURE(InitState());
683
684 m_errorMonitor->SetDesiredFailureMsg(
685 VK_DEBUG_REPORT_ERROR_BIT_EXT,
686 "parameter pAllocateInfo->sType must be");
687 // Zero struct memory, effectively setting sType to
688 // VK_STRUCTURE_TYPE_APPLICATION_INFO
689 // Expected to trigger an error with
690 // parameter_validation::validate_struct_type
691 VkMemoryAllocateInfo alloc_info = {};
692 VkDeviceMemory memory = VK_NULL_HANDLE;
693 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
694 m_errorMonitor->VerifyFound();
695
696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
697 "parameter pSubmits[0].sType must be");
698 // Zero struct memory, effectively setting sType to
699 // VK_STRUCTURE_TYPE_APPLICATION_INFO
700 // Expected to trigger an error with
701 // parameter_validation::validate_struct_type_array
702 VkSubmitInfo submit_info = {};
703 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
704 m_errorMonitor->VerifyFound();
705}
706
707TEST_F(VkLayerTest, InvalidStructPNext) {
708 TEST_DESCRIPTION(
709 "Specify an invalid value for a Vulkan structure's pNext field");
710
711 ASSERT_NO_FATAL_FAILURE(InitState());
712
713 m_errorMonitor->SetDesiredFailureMsg(
714 VK_DEBUG_REPORT_ERROR_BIT_EXT,
715 "value of pAllocateInfo->pNext must be NULL");
716 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
717 // NULL
718 // Expected to trigger an error with
719 // parameter_validation::validate_struct_pnext
720 VkDeviceMemory memory = VK_NULL_HANDLE;
721 // Zero-initialization will provide the correct sType
722 VkApplicationInfo app_info = {};
Dustin Graves47b6cba2016-05-10 17:34:38 -0600723 VkMemoryAllocateInfo memory_alloc_info = {};
724 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
725 memory_alloc_info.pNext = &app_info;
726 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600727 m_errorMonitor->VerifyFound();
728
Dustin Graves47b6cba2016-05-10 17:34:38 -0600729 m_errorMonitor->SetDesiredFailureMsg(
730 VK_DEBUG_REPORT_ERROR_BIT_EXT,
731 " chain includes a structure with unexpected VkStructureType ");
732 // Set VkGraphicsPipelineCreateInfo::VkPipelineRasterizationStateCreateInfo::pNext to an invalid structure, when pNext is allowed to be a non-NULL value
733 // Expected to trigger an error with
734 // parameter_validation::validate_struct_pnext
735 VkDescriptorPoolSize ds_type_count = {};
736 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
737 ds_type_count.descriptorCount = 1;
738
739 VkDescriptorPoolCreateInfo ds_pool_ci = {};
740 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
741 ds_pool_ci.pNext = NULL;
742 ds_pool_ci.maxSets = 1;
743 ds_pool_ci.poolSizeCount = 1;
744 ds_pool_ci.pPoolSizes = &ds_type_count;
745
746 VkDescriptorPool ds_pool;
747 VkResult err =
748 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
749 ASSERT_VK_SUCCESS(err);
750
751 VkDescriptorSetLayoutBinding dsl_binding = {};
752 dsl_binding.binding = 0;
753 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
754 dsl_binding.descriptorCount = 1;
755 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
756 dsl_binding.pImmutableSamplers = NULL;
757
758 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
759 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
760 ds_layout_ci.pNext = NULL;
761 ds_layout_ci.bindingCount = 1;
762 ds_layout_ci.pBindings = &dsl_binding;
763
764 VkDescriptorSetLayout ds_layout;
765 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
766 &ds_layout);
767 ASSERT_VK_SUCCESS(err);
768
769 VkDescriptorSet descriptorSet;
770 VkDescriptorSetAllocateInfo ds_alloc_info = {};
771 ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
772 ds_alloc_info.descriptorSetCount = 1;
773 ds_alloc_info.descriptorPool = ds_pool;
774 ds_alloc_info.pSetLayouts = &ds_layout;
775 err = vkAllocateDescriptorSets(m_device->device(), &ds_alloc_info,
776 &descriptorSet);
777 ASSERT_VK_SUCCESS(err);
778
779 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
780 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
781 pipeline_layout_ci.setLayoutCount = 1;
782 pipeline_layout_ci.pSetLayouts = &ds_layout;
783
784 VkPipelineLayout pipeline_layout;
785 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
786 &pipeline_layout);
787 ASSERT_VK_SUCCESS(err);
788
789 VkViewport vp = {}; // Just need dummy vp to point to
790 VkRect2D sc = {}; // dummy scissor to point to
791
792 VkPipelineViewportStateCreateInfo vp_state_ci = {};
793 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
794 vp_state_ci.scissorCount = 1;
795 vp_state_ci.pScissors = &sc;
796 vp_state_ci.viewportCount = 1;
797 vp_state_ci.pViewports = &vp;
798
799 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
800 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
801 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
802 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
803 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
804 rs_state_ci.depthClampEnable = VK_FALSE;
805 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
806 rs_state_ci.depthBiasEnable = VK_FALSE;
807
808 VkGraphicsPipelineCreateInfo gp_ci = {};
809 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
810 gp_ci.pViewportState = &vp_state_ci;
811 gp_ci.pRasterizationState = &rs_state_ci;
812 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
813 gp_ci.layout = pipeline_layout;
814 gp_ci.renderPass = renderPass();
815
816 VkPipelineCacheCreateInfo pc_ci = {};
817 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
818 pc_ci.initialDataSize = 0;
819 pc_ci.pInitialData = 0;
820
821 VkPipeline pipeline;
822 VkPipelineCache pipelineCache;
823
824 err =
825 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
826 ASSERT_VK_SUCCESS(err);
827
828 // Set VkPipelineRasterizationStateCreateInfo::pNext to an invalid value
829 VkApplicationInfo invalid_pnext_struct = {};
830 rs_state_ci.pNext = &invalid_pnext_struct;
831
832 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
833 &gp_ci, NULL, &pipeline);
834 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -0600835 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
836 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
837 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
838 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
839
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600840}
Dustin Graves5d33d532016-05-09 16:21:12 -0600841
842TEST_F(VkLayerTest, UnrecognizedValue) {
843 TEST_DESCRIPTION(
844 "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
845
846 ASSERT_NO_FATAL_FAILURE(InitState());
847
848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
849 "does not fall within the begin..end "
850 "range of the core VkFormat "
851 "enumeration tokens");
852 // Specify an invalid VkFormat value
853 // Expected to trigger an error with
854 // parameter_validation::validate_ranged_enum
855 VkFormatProperties format_properties;
856 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000),
857 &format_properties);
858 m_errorMonitor->VerifyFound();
859
860 m_errorMonitor->SetDesiredFailureMsg(
861 VK_DEBUG_REPORT_ERROR_BIT_EXT,
862 "contains flag bits that are not recognized members of");
863 // Specify an invalid VkFlags bitmask value
864 // Expected to trigger an error with parameter_validation::validate_flags
865 VkImageFormatProperties image_format_properties;
866 vkGetPhysicalDeviceImageFormatProperties(
867 gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D,
868 VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0,
869 &image_format_properties);
870 m_errorMonitor->VerifyFound();
871
872 m_errorMonitor->SetDesiredFailureMsg(
873 VK_DEBUG_REPORT_ERROR_BIT_EXT,
874 "contains flag bits that are not recognized members of");
875 // Specify an invalid VkFlags array entry
876 // Expected to trigger an error with
877 // parameter_validation::validate_flags_array
878 VkSemaphore semaphore = VK_NULL_HANDLE;
879 VkPipelineStageFlags stage_flags =
880 static_cast<VkPipelineStageFlags>(1 << 25);
881 VkSubmitInfo submit_info = {};
882 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
883 submit_info.waitSemaphoreCount = 1;
884 submit_info.pWaitSemaphores = &semaphore;
885 submit_info.pWaitDstStageMask = &stage_flags;
886 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
887 m_errorMonitor->VerifyFound();
888
889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
890 "is neither VK_TRUE nor VK_FALSE");
891 // Specify an invalid VkBool32 value
892 // Expected to trigger a warning with
893 // parameter_validation::validate_bool32
894 VkSampler sampler = VK_NULL_HANDLE;
895 VkSamplerCreateInfo sampler_info = {};
896 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
897 sampler_info.pNext = NULL;
898 sampler_info.magFilter = VK_FILTER_NEAREST;
899 sampler_info.minFilter = VK_FILTER_NEAREST;
900 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
901 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
902 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
903 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
904 sampler_info.mipLodBias = 1.0;
905 sampler_info.maxAnisotropy = 1;
906 sampler_info.compareEnable = VK_FALSE;
907 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
908 sampler_info.minLod = 1.0;
909 sampler_info.maxLod = 1.0;
910 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
911 sampler_info.unnormalizedCoordinates = VK_FALSE;
912 // Not VK_TRUE or VK_FALSE
913 sampler_info.anisotropyEnable = 3;
914 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
915 m_errorMonitor->VerifyFound();
916}
Dustin Gravesfce74c02016-05-10 11:42:58 -0600917
918TEST_F(VkLayerTest, FailedReturnValue) {
919 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
920
921 ASSERT_NO_FATAL_FAILURE(InitState());
922
Dustin Graves13c1e2b2016-05-16 15:31:02 -0600923 // Find an unsupported image format
924 VkFormat unsupported = VK_FORMAT_UNDEFINED;
925 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
926 VkFormat format = static_cast<VkFormat>(f);
927 VkFormatProperties fProps = m_device->format_properties(format);
928 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
929 fProps.optimalTilingFeatures == 0) {
930 unsupported = format;
931 break;
932 }
933 }
934
935 if (unsupported != VK_FORMAT_UNDEFINED) {
936 m_errorMonitor->SetDesiredFailureMsg(
937 VK_DEBUG_REPORT_WARNING_BIT_EXT,
938 "the requested format is not supported on this device");
939 // Specify an unsupported VkFormat value to generate a
940 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
941 // Expected to trigger a warning from
942 // parameter_validation::validate_result
943 VkImageFormatProperties image_format_properties;
944 VkResult err = vkGetPhysicalDeviceImageFormatProperties(
945 gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
946 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
947 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
948 m_errorMonitor->VerifyFound();
949 }
Dustin Gravesfce74c02016-05-10 11:42:58 -0600950}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -0600951
952TEST_F(VkLayerTest, UpdateBufferAlignment) {
953 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
954 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
955
956 ASSERT_NO_FATAL_FAILURE(InitState());
957
958 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
959 vk_testing::Buffer buffer;
960 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
961
962 BeginCommandBuffer();
963 // Introduce failure by using dstOffset that is not multiple of 4
964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
965 " is not a multiple of 4");
966 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
967 m_errorMonitor->VerifyFound();
968
969 // Introduce failure by using dataSize that is not multiple of 4
970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
971 " is not a multiple of 4");
972 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
973 m_errorMonitor->VerifyFound();
974
975 // Introduce failure by using dataSize that is < 0
976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
977 "must be greater than zero and less than or equal to 65536");
978 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
979 m_errorMonitor->VerifyFound();
980
981 // Introduce failure by using dataSize that is > 65536
982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
983 "must be greater than zero and less than or equal to 65536");
984 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
985 m_errorMonitor->VerifyFound();
986
987 EndCommandBuffer();
988}
989
990TEST_F(VkLayerTest, FillBufferAlignment) {
991 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
992
993 ASSERT_NO_FATAL_FAILURE(InitState());
994
995 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
996 vk_testing::Buffer buffer;
997 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
998
999 BeginCommandBuffer();
1000
1001 // Introduce failure by using dstOffset that is not multiple of 4
1002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1003 " is not a multiple of 4");
1004 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1005 m_errorMonitor->VerifyFound();
1006
1007 // Introduce failure by using size that is not multiple of 4
1008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1009 " is not a multiple of 4");
1010 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1011 m_errorMonitor->VerifyFound();
1012
1013 // Introduce failure by using size that is zero
1014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1015 "must be greater than zero");
1016 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1017 m_errorMonitor->VerifyFound();
1018
1019 EndCommandBuffer();
1020}
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001021#endif // PARAMETER_VALIDATION_TESTS
1022
Tobin Ehlis0788f522015-05-26 16:11:58 -06001023#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001024#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001025TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001026{
1027 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001028 VkFenceCreateInfo fenceInfo = {};
1029 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1030 fenceInfo.pNext = NULL;
1031 fenceInfo.flags = 0;
1032
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001034
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001035 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001036
1037 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1038 vk_testing::Buffer buffer;
1039 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001040
Tony Barbourfe3351b2015-07-28 10:17:20 -06001041 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001042 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001043 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001044
1045 testFence.init(*m_device, fenceInfo);
1046
1047 // Bypass framework since it does the waits automatically
1048 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001049 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001050 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1051 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001052 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001053 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001054 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001055 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001056 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001057 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001058 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001059
1060 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001061 ASSERT_VK_SUCCESS( err );
1062
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001063 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001064 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001065
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001066 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001067}
1068
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001069TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001070{
1071 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001072 VkFenceCreateInfo fenceInfo = {};
1073 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1074 fenceInfo.pNext = NULL;
1075 fenceInfo.flags = 0;
1076
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001078
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001079 ASSERT_NO_FATAL_FAILURE(InitState());
1080 ASSERT_NO_FATAL_FAILURE(InitViewport());
1081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1082
Tony Barbourfe3351b2015-07-28 10:17:20 -06001083 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001084 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001085 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001086
1087 testFence.init(*m_device, fenceInfo);
1088
1089 // Bypass framework since it does the waits automatically
1090 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001091 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001092 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1093 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001094 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001095 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001096 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001097 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001098 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001099 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001100 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001101
1102 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001103 ASSERT_VK_SUCCESS( err );
1104
Jon Ashburnf19916e2016-01-11 13:12:43 -07001105 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001106 VkCommandBufferBeginInfo info = {};
1107 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1108 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001109 info.renderPass = VK_NULL_HANDLE;
1110 info.subpass = 0;
1111 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001112 info.occlusionQueryEnable = VK_FALSE;
1113 info.queryFlags = 0;
1114 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001115
1116 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001117 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001118
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001119 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001120}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001121#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001122
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001123// This is a positive test. No failures are expected.
1124TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1125 VkResult err;
1126 bool pass;
1127
1128 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1129 "the buffer, create an image, and bind the same memory to "
1130 "it");
1131
1132 m_errorMonitor->ExpectSuccess();
1133
1134 ASSERT_NO_FATAL_FAILURE(InitState());
1135
1136 VkBuffer buffer;
1137 VkImage image;
1138 VkDeviceMemory mem;
1139 VkMemoryRequirements mem_reqs;
1140
1141 VkBufferCreateInfo buf_info = {};
1142 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1143 buf_info.pNext = NULL;
1144 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1145 buf_info.size = 256;
1146 buf_info.queueFamilyIndexCount = 0;
1147 buf_info.pQueueFamilyIndices = NULL;
1148 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1149 buf_info.flags = 0;
1150 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1151 ASSERT_VK_SUCCESS(err);
1152
1153 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1154
1155 VkMemoryAllocateInfo alloc_info = {};
1156 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1157 alloc_info.pNext = NULL;
1158 alloc_info.memoryTypeIndex = 0;
1159
1160 // Ensure memory is big enough for both bindings
1161 alloc_info.allocationSize = 0x10000;
1162
1163 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1164 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1165 if (!pass) {
1166 vkDestroyBuffer(m_device->device(), buffer, NULL);
1167 return;
1168 }
1169
1170 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1171 ASSERT_VK_SUCCESS(err);
1172
1173 uint8_t *pData;
1174 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1175 (void **)&pData);
1176 ASSERT_VK_SUCCESS(err);
1177
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001178 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001179
1180 vkUnmapMemory(m_device->device(), mem);
1181
1182 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1183 ASSERT_VK_SUCCESS(err);
1184
1185 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1186 // memory. In fact, it was never used by the GPU.
1187 // Just be be sure, wait for idle.
1188 vkDestroyBuffer(m_device->device(), buffer, NULL);
1189 vkDeviceWaitIdle(m_device->device());
1190
1191 VkImageCreateInfo image_create_info = {};
1192 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1193 image_create_info.pNext = NULL;
1194 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1195 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1196 image_create_info.extent.width = 64;
1197 image_create_info.extent.height = 64;
1198 image_create_info.extent.depth = 1;
1199 image_create_info.mipLevels = 1;
1200 image_create_info.arrayLayers = 1;
1201 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1202 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1203 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1204 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1205 image_create_info.queueFamilyIndexCount = 0;
1206 image_create_info.pQueueFamilyIndices = NULL;
1207 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1208 image_create_info.flags = 0;
1209
1210 VkMemoryAllocateInfo mem_alloc = {};
1211 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1212 mem_alloc.pNext = NULL;
1213 mem_alloc.allocationSize = 0;
1214 mem_alloc.memoryTypeIndex = 0;
1215
1216 /* Create a mappable image. It will be the texture if linear images are ok
1217 * to be textures or it will be the staging image if they are not.
1218 */
1219 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1220 ASSERT_VK_SUCCESS(err);
1221
1222 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1223
1224 mem_alloc.allocationSize = mem_reqs.size;
1225
1226 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc,
1227 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1228 if (!pass) {
1229 vkDestroyImage(m_device->device(), image, NULL);
1230 return;
1231 }
1232
Tobin Ehlis077ded32016-05-12 17:39:13 -06001233 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001234 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1235 ASSERT_VK_SUCCESS(err);
1236
1237 m_errorMonitor->VerifyNotFound();
1238
Tony Barbourdf4c0042016-06-01 15:55:43 -06001239 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001240 vkDestroyBuffer(m_device->device(), buffer, NULL);
1241 vkDestroyImage(m_device->device(), image, NULL);
1242}
1243
Tobin Ehlisf11be982016-05-11 13:52:53 -06001244TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1245 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1246 "buffer and image to memory such that they will alias.");
1247 VkResult err;
1248 bool pass;
1249 ASSERT_NO_FATAL_FAILURE(InitState());
1250
Tobin Ehlis077ded32016-05-12 17:39:13 -06001251 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001252 VkImage image;
1253 VkDeviceMemory mem; // buffer will be bound first
1254 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001255 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001256
1257 VkBufferCreateInfo buf_info = {};
1258 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1259 buf_info.pNext = NULL;
1260 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1261 buf_info.size = 256;
1262 buf_info.queueFamilyIndexCount = 0;
1263 buf_info.pQueueFamilyIndices = NULL;
1264 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1265 buf_info.flags = 0;
1266 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1267 ASSERT_VK_SUCCESS(err);
1268
Tobin Ehlis077ded32016-05-12 17:39:13 -06001269 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001270
1271 VkImageCreateInfo image_create_info = {};
1272 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1273 image_create_info.pNext = NULL;
1274 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1275 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1276 image_create_info.extent.width = 64;
1277 image_create_info.extent.height = 64;
1278 image_create_info.extent.depth = 1;
1279 image_create_info.mipLevels = 1;
1280 image_create_info.arrayLayers = 1;
1281 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1282 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1283 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1284 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1285 image_create_info.queueFamilyIndexCount = 0;
1286 image_create_info.pQueueFamilyIndices = NULL;
1287 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1288 image_create_info.flags = 0;
1289
Tobin Ehlisf11be982016-05-11 13:52:53 -06001290 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1291 ASSERT_VK_SUCCESS(err);
1292
Tobin Ehlis077ded32016-05-12 17:39:13 -06001293 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1294
1295 VkMemoryAllocateInfo alloc_info = {};
1296 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1297 alloc_info.pNext = NULL;
1298 alloc_info.memoryTypeIndex = 0;
1299 // Ensure memory is big enough for both bindings
1300 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
1301 pass = m_device->phy().set_memory_type(
1302 buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info,
1303 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001304 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001305 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001306 vkDestroyImage(m_device->device(), image, NULL);
1307 return;
1308 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001309 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1310 ASSERT_VK_SUCCESS(err);
1311 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1312 ASSERT_VK_SUCCESS(err);
1313
Tobin Ehlisf11be982016-05-11 13:52:53 -06001314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1315 " is aliased with buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001316 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001317 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1318 m_errorMonitor->VerifyFound();
1319
1320 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001321 // aliasing buffer2
1322 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1323 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001324 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1325 ASSERT_VK_SUCCESS(err);
1326 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1327 ASSERT_VK_SUCCESS(err);
1328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1329 " is aliased with image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001330 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001331 m_errorMonitor->VerifyFound();
1332
1333 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001334 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001335 vkDestroyImage(m_device->device(), image, NULL);
1336 vkFreeMemory(m_device->device(), mem, NULL);
1337 vkFreeMemory(m_device->device(), mem_img, NULL);
1338}
1339
Tobin Ehlis35372522016-05-12 08:32:31 -06001340TEST_F(VkLayerTest, InvalidMemoryMapping) {
1341 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1342 VkResult err;
1343 bool pass;
1344 ASSERT_NO_FATAL_FAILURE(InitState());
1345
1346 VkBuffer buffer;
1347 VkDeviceMemory mem;
1348 VkMemoryRequirements mem_reqs;
1349
1350 VkBufferCreateInfo buf_info = {};
1351 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1352 buf_info.pNext = NULL;
1353 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1354 buf_info.size = 256;
1355 buf_info.queueFamilyIndexCount = 0;
1356 buf_info.pQueueFamilyIndices = NULL;
1357 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1358 buf_info.flags = 0;
1359 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1360 ASSERT_VK_SUCCESS(err);
1361
1362 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1363 VkMemoryAllocateInfo alloc_info = {};
1364 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1365 alloc_info.pNext = NULL;
1366 alloc_info.memoryTypeIndex = 0;
1367
1368 // Ensure memory is big enough for both bindings
1369 static const VkDeviceSize allocation_size = 0x10000;
1370 alloc_info.allocationSize = allocation_size;
1371 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1372 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1373 if (!pass) {
1374 vkDestroyBuffer(m_device->device(), buffer, NULL);
1375 return;
1376 }
1377 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1378 ASSERT_VK_SUCCESS(err);
1379
1380 uint8_t *pData;
1381 // Attempt to map memory size 0 is invalid
1382 m_errorMonitor->SetDesiredFailureMsg(
1383 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1384 "VkMapMemory: Attempting to map memory range of size zero");
1385 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1386 m_errorMonitor->VerifyFound();
1387 // Map memory twice
1388 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1389 (void **)&pData);
1390 ASSERT_VK_SUCCESS(err);
1391 m_errorMonitor->SetDesiredFailureMsg(
1392 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1393 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1394 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1395 (void **)&pData);
1396 m_errorMonitor->VerifyFound();
1397
1398 // Unmap the memory to avoid re-map error
1399 vkUnmapMemory(m_device->device(), mem);
1400 // overstep allocation with VK_WHOLE_SIZE
1401 m_errorMonitor->SetDesiredFailureMsg(
1402 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1403 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1404 err = vkMapMemory(m_device->device(), mem, allocation_size + 1,
1405 VK_WHOLE_SIZE, 0, (void **)&pData);
1406 m_errorMonitor->VerifyFound();
1407 // overstep allocation w/o VK_WHOLE_SIZE
1408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1409 " oversteps total array size 0x");
1410 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0,
1411 (void **)&pData);
1412 m_errorMonitor->VerifyFound();
1413 // Now error due to unmapping memory that's not mapped
1414 m_errorMonitor->SetDesiredFailureMsg(
1415 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1416 "Unmapping Memory without memory being mapped: ");
1417 vkUnmapMemory(m_device->device(), mem);
1418 m_errorMonitor->VerifyFound();
1419 // Now map memory and cause errors due to flushing invalid ranges
1420 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0,
1421 (void **)&pData);
1422 ASSERT_VK_SUCCESS(err);
1423 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001424 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001425 mmr.memory = mem;
1426 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
1427 m_errorMonitor->SetDesiredFailureMsg(
1428 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1429 ") is less than Memory Object's offset (");
1430 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1431 m_errorMonitor->VerifyFound();
1432 // Now flush range that oversteps mapped range
1433 vkUnmapMemory(m_device->device(), mem);
1434 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1435 ASSERT_VK_SUCCESS(err);
1436 mmr.offset = 16;
1437 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
1438 m_errorMonitor->SetDesiredFailureMsg(
1439 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1440 ") exceeds the Memory Object's upper-bound (");
1441 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1442 m_errorMonitor->VerifyFound();
1443
1444 pass =
1445 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1446 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1447 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
1448 if (!pass) {
1449 vkFreeMemory(m_device->device(), mem, NULL);
1450 vkDestroyBuffer(m_device->device(), buffer, NULL);
1451 return;
1452 }
1453 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1454 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1455
1456 vkDestroyBuffer(m_device->device(), buffer, NULL);
1457 vkFreeMemory(m_device->device(), mem, NULL);
1458}
1459
Ian Elliott1c32c772016-04-28 14:47:13 -06001460TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1461 VkResult err;
1462 bool pass;
1463
Ian Elliott489eec02016-05-05 14:12:44 -06001464// FIXME: After we turn on this code for non-Linux platforms, uncomment the
1465// following declaration (which is temporarily being moved below):
1466// VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001467 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1468 VkSwapchainCreateInfoKHR swapchain_create_info = {};
1469 uint32_t swapchain_image_count = 0;
1470// VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1471 uint32_t image_index = 0;
1472// VkPresentInfoKHR present_info = {};
1473
1474 ASSERT_NO_FATAL_FAILURE(InitState());
1475
Ian Elliott3f06ce52016-04-29 14:46:21 -06001476#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1477#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1478 // Use the functions from the VK_KHR_android_surface extension without
1479 // enabling that extension:
1480
1481 // Create a surface:
1482 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001483 m_errorMonitor->SetDesiredFailureMsg(
1484 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1485 "extension was not enabled for this");
1486 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL,
1487 &surface);
1488 pass = (err != VK_SUCCESS);
1489 ASSERT_TRUE(pass);
1490 m_errorMonitor->VerifyFound();
1491#endif // VK_USE_PLATFORM_ANDROID_KHR
1492
1493
1494#if defined(VK_USE_PLATFORM_MIR_KHR)
1495 // Use the functions from the VK_KHR_mir_surface extension without enabling
1496 // that extension:
1497
1498 // Create a surface:
1499 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001500 m_errorMonitor->SetDesiredFailureMsg(
1501 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1502 "extension was not enabled for this");
1503 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1504 pass = (err != VK_SUCCESS);
1505 ASSERT_TRUE(pass);
1506 m_errorMonitor->VerifyFound();
1507
1508 // Tell whether an mir_connection supports presentation:
1509 MirConnection *mir_connection = NULL;
1510 m_errorMonitor->SetDesiredFailureMsg(
1511 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1512 "extension was not enabled for this");
1513 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection,
1514 visual_id);
1515 m_errorMonitor->VerifyFound();
1516#endif // VK_USE_PLATFORM_MIR_KHR
1517
1518
1519#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1520 // Use the functions from the VK_KHR_wayland_surface extension without
1521 // enabling that extension:
1522
1523 // Create a surface:
1524 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001525 m_errorMonitor->SetDesiredFailureMsg(
1526 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1527 "extension was not enabled for this");
1528 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL,
1529 &surface);
1530 pass = (err != VK_SUCCESS);
1531 ASSERT_TRUE(pass);
1532 m_errorMonitor->VerifyFound();
1533
1534 // Tell whether an wayland_display supports presentation:
1535 struct wl_display wayland_display = {};
1536 m_errorMonitor->SetDesiredFailureMsg(
1537 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1538 "extension was not enabled for this");
1539 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0,
1540 &wayland_display);
1541 m_errorMonitor->VerifyFound();
1542#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001543#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001544
1545
1546#if defined(VK_USE_PLATFORM_WIN32_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001547// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1548// TO NON-LINUX PLATFORMS:
1549VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001550 // Use the functions from the VK_KHR_win32_surface extension without
1551 // enabling that extension:
1552
1553 // Create a surface:
1554 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001555 m_errorMonitor->SetDesiredFailureMsg(
1556 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1557 "extension was not enabled for this");
1558 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL,
1559 &surface);
1560 pass = (err != VK_SUCCESS);
1561 ASSERT_TRUE(pass);
1562 m_errorMonitor->VerifyFound();
1563
1564 // Tell whether win32 supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001565 m_errorMonitor->SetDesiredFailureMsg(
1566 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1567 "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001568 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001569 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001570// Set this (for now, until all platforms are supported and tested):
1571#define NEED_TO_TEST_THIS_ON_PLATFORM
1572#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001573
1574
Ian Elliott1c32c772016-04-28 14:47:13 -06001575#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001576// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1577// TO NON-LINUX PLATFORMS:
1578VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001579 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1580 // that extension:
1581
1582 // Create a surface:
1583 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001584 m_errorMonitor->SetDesiredFailureMsg(
1585 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1586 "extension was not enabled for this");
1587 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1588 pass = (err != VK_SUCCESS);
1589 ASSERT_TRUE(pass);
1590 m_errorMonitor->VerifyFound();
1591
1592 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001593 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001594 xcb_visualid_t visual_id = 0;
1595 m_errorMonitor->SetDesiredFailureMsg(
1596 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1597 "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001598 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection,
Ian Elliott1c32c772016-04-28 14:47:13 -06001599 visual_id);
1600 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001601// Set this (for now, until all platforms are supported and tested):
1602#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001603#endif // VK_USE_PLATFORM_XCB_KHR
1604
1605
Ian Elliott12630812016-04-29 14:35:43 -06001606#if defined(VK_USE_PLATFORM_XLIB_KHR)
1607 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1608 // that extension:
1609
1610 // Create a surface:
1611 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Ian Elliott12630812016-04-29 14:35:43 -06001612 m_errorMonitor->SetDesiredFailureMsg(
1613 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1614 "extension was not enabled for this");
1615 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1616 pass = (err != VK_SUCCESS);
1617 ASSERT_TRUE(pass);
1618 m_errorMonitor->VerifyFound();
1619
1620 // Tell whether an Xlib VisualID supports presentation:
1621 Display *dpy = NULL;
1622 VisualID visual = 0;
1623 m_errorMonitor->SetDesiredFailureMsg(
1624 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1625 "extension was not enabled for this");
1626 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1627 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001628// Set this (for now, until all platforms are supported and tested):
1629#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001630#endif // VK_USE_PLATFORM_XLIB_KHR
1631
1632
Ian Elliott1c32c772016-04-28 14:47:13 -06001633 // Use the functions from the VK_KHR_surface extension without enabling
1634 // that extension:
1635
Ian Elliott489eec02016-05-05 14:12:44 -06001636#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001637 // Destroy a surface:
1638 m_errorMonitor->SetDesiredFailureMsg(
1639 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1640 "extension was not enabled for this");
1641 vkDestroySurfaceKHR(instance(), surface, NULL);
1642 m_errorMonitor->VerifyFound();
1643
1644 // Check if surface supports presentation:
1645 VkBool32 supported = false;
1646 m_errorMonitor->SetDesiredFailureMsg(
1647 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1648 "extension was not enabled for this");
1649 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1650 pass = (err != VK_SUCCESS);
1651 ASSERT_TRUE(pass);
1652 m_errorMonitor->VerifyFound();
1653
1654 // Check surface capabilities:
1655 VkSurfaceCapabilitiesKHR capabilities = {};
1656 m_errorMonitor->SetDesiredFailureMsg(
1657 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1658 "extension was not enabled for this");
1659 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1660 &capabilities);
1661 pass = (err != VK_SUCCESS);
1662 ASSERT_TRUE(pass);
1663 m_errorMonitor->VerifyFound();
1664
1665 // Check surface formats:
1666 uint32_t format_count = 0;
1667 VkSurfaceFormatKHR *formats = NULL;
1668 m_errorMonitor->SetDesiredFailureMsg(
1669 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1670 "extension was not enabled for this");
1671 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1672 &format_count, formats);
1673 pass = (err != VK_SUCCESS);
1674 ASSERT_TRUE(pass);
1675 m_errorMonitor->VerifyFound();
1676
1677 // Check surface present modes:
1678 uint32_t present_mode_count = 0;
1679 VkSurfaceFormatKHR *present_modes = NULL;
1680 m_errorMonitor->SetDesiredFailureMsg(
1681 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1682 "extension was not enabled for this");
1683 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1684 &present_mode_count, present_modes);
1685 pass = (err != VK_SUCCESS);
1686 ASSERT_TRUE(pass);
1687 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001688#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001689
1690
1691 // Use the functions from the VK_KHR_swapchain extension without enabling
1692 // that extension:
1693
1694 // Create a swapchain:
1695 m_errorMonitor->SetDesiredFailureMsg(
1696 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1697 "extension was not enabled for this");
1698 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1699 swapchain_create_info.pNext = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001700 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info,
1701 NULL, &swapchain);
1702 pass = (err != VK_SUCCESS);
1703 ASSERT_TRUE(pass);
1704 m_errorMonitor->VerifyFound();
1705
1706 // Get the images from the swapchain:
1707 m_errorMonitor->SetDesiredFailureMsg(
1708 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1709 "extension was not enabled for this");
1710 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain,
1711 &swapchain_image_count, NULL);
1712 pass = (err != VK_SUCCESS);
1713 ASSERT_TRUE(pass);
1714 m_errorMonitor->VerifyFound();
1715
1716 // Try to acquire an image:
1717 m_errorMonitor->SetDesiredFailureMsg(
1718 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1719 "extension was not enabled for this");
1720 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0,
1721 VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index);
1722 pass = (err != VK_SUCCESS);
1723 ASSERT_TRUE(pass);
1724 m_errorMonitor->VerifyFound();
1725
1726 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001727 //
1728 // NOTE: Currently can't test this because a real swapchain is needed (as
1729 // opposed to the fake one we created) in order for the layer to lookup the
1730 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001731
1732 // Destroy the swapchain:
1733 m_errorMonitor->SetDesiredFailureMsg(
1734 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1735 "extension was not enabled for this");
1736 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1737 m_errorMonitor->VerifyFound();
1738}
1739
Ian Elliott2c1daf52016-05-12 09:41:46 -06001740TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06001741
Dustin Graves6c6d8982016-05-17 10:09:21 -06001742#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06001743 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001744
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001745 VkResult err;
1746 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06001747 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1748 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001749 // uint32_t swapchain_image_count = 0;
1750 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1751 // uint32_t image_index = 0;
1752 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06001753
1754 ASSERT_NO_FATAL_FAILURE(InitState());
1755
1756 // Use the create function from one of the VK_KHR_*_surface extension in
1757 // order to create a surface, testing all known errors in the process,
1758 // before successfully creating a surface:
1759 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1761 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001762 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
1763 pass = (err != VK_SUCCESS);
1764 ASSERT_TRUE(pass);
1765 m_errorMonitor->VerifyFound();
1766
1767 // Next, try to create a surface with the wrong
1768 // VkXcbSurfaceCreateInfoKHR::sType:
1769 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
1770 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1772 "called with the wrong value for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001773 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1774 pass = (err != VK_SUCCESS);
1775 ASSERT_TRUE(pass);
1776 m_errorMonitor->VerifyFound();
1777
Ian Elliott2c1daf52016-05-12 09:41:46 -06001778 // Create a native window, and then correctly create a surface:
1779 xcb_connection_t *connection;
1780 xcb_screen_t *screen;
1781 xcb_window_t xcb_window;
1782 xcb_intern_atom_reply_t *atom_wm_delete_window;
1783
1784 const xcb_setup_t *setup;
1785 xcb_screen_iterator_t iter;
1786 int scr;
1787 uint32_t value_mask, value_list[32];
1788 int width = 1;
1789 int height = 1;
1790
1791 connection = xcb_connect(NULL, &scr);
1792 ASSERT_TRUE(connection != NULL);
1793 setup = xcb_get_setup(connection);
1794 iter = xcb_setup_roots_iterator(setup);
1795 while (scr-- > 0)
1796 xcb_screen_next(&iter);
1797 screen = iter.data;
1798
1799 xcb_window = xcb_generate_id(connection);
1800
1801 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
1802 value_list[0] = screen->black_pixel;
1803 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE |
1804 XCB_EVENT_MASK_STRUCTURE_NOTIFY;
1805
1806 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window,
1807 screen->root, 0, 0, width, height, 0,
1808 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual,
1809 value_mask, value_list);
1810
1811 /* Magic code that will send notification when window is destroyed */
1812 xcb_intern_atom_cookie_t cookie =
1813 xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
1814 xcb_intern_atom_reply_t *reply =
1815 xcb_intern_atom_reply(connection, cookie, 0);
1816
1817 xcb_intern_atom_cookie_t cookie2 =
1818 xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001819 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001820 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window,
1821 (*reply).atom, 4, 32, 1,
1822 &(*atom_wm_delete_window).atom);
1823 free(reply);
1824
1825 xcb_map_window(connection, xcb_window);
1826
1827 // Force the x/y coordinates to 100,100 results are identical in consecutive
1828 // runs
1829 const uint32_t coords[] = {100, 100};
1830 xcb_configure_window(connection, xcb_window,
1831 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
1832
Ian Elliott2c1daf52016-05-12 09:41:46 -06001833 // Finally, try to correctly create a surface:
1834 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
1835 xcb_create_info.pNext = NULL;
1836 xcb_create_info.flags = 0;
1837 xcb_create_info.connection = connection;
1838 xcb_create_info.window = xcb_window;
1839 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1840 pass = (err == VK_SUCCESS);
1841 ASSERT_TRUE(pass);
1842
Ian Elliott2c1daf52016-05-12 09:41:46 -06001843 // Check if surface supports presentation:
1844
1845 // 1st, do so without having queried the queue families:
1846 VkBool32 supported = false;
1847 // TODO: Get the following error to come out:
1848 m_errorMonitor->SetDesiredFailureMsg(
1849 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1850 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
1851 "function");
1852 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1853 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001854 // ASSERT_TRUE(pass);
1855 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06001856
1857 // Next, query a queue family index that's too large:
1858 m_errorMonitor->SetDesiredFailureMsg(
1859 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1860 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001861 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface,
1862 &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001863 pass = (err != VK_SUCCESS);
1864 ASSERT_TRUE(pass);
1865 m_errorMonitor->VerifyFound();
1866
1867 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001868 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
1869 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06001870 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1871 pass = (err == VK_SUCCESS);
1872 ASSERT_TRUE(pass);
1873
Ian Elliott2c1daf52016-05-12 09:41:46 -06001874 // Before proceeding, try to create a swapchain without having called
1875 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
1876 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1877 swapchain_create_info.pNext = NULL;
1878 swapchain_create_info.flags = 0;
1879 m_errorMonitor->SetDesiredFailureMsg(
1880 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1881 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001882 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1883 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001884 pass = (err != VK_SUCCESS);
1885 ASSERT_TRUE(pass);
1886 m_errorMonitor->VerifyFound();
1887
Ian Elliott2c1daf52016-05-12 09:41:46 -06001888 // Get the surface capabilities:
1889 VkSurfaceCapabilitiesKHR surface_capabilities;
1890
1891 // Do so correctly (only error logged by this entrypoint is if the
1892 // extension isn't enabled):
1893 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1894 &surface_capabilities);
1895 pass = (err == VK_SUCCESS);
1896 ASSERT_TRUE(pass);
1897
Ian Elliott2c1daf52016-05-12 09:41:46 -06001898 // Get the surface formats:
1899 uint32_t surface_format_count;
1900
1901 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1903 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001904 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
1905 pass = (err == VK_SUCCESS);
1906 ASSERT_TRUE(pass);
1907 m_errorMonitor->VerifyFound();
1908
1909 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
1910 // correctly done a 1st try (to get the count):
1911 m_errorMonitor->SetDesiredFailureMsg(
1912 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1913 "but no prior positive value has been seen for");
1914 surface_format_count = 0;
1915 vkGetPhysicalDeviceSurfaceFormatsKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001916 gpu(), surface, &surface_format_count,
1917 (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001918 pass = (err == VK_SUCCESS);
1919 ASSERT_TRUE(pass);
1920 m_errorMonitor->VerifyFound();
1921
1922 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001923 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1924 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001925 pass = (err == VK_SUCCESS);
1926 ASSERT_TRUE(pass);
1927
1928 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001929 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(
1930 surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001931
1932 // Next, do a 2nd try with surface_format_count being set too high:
1933 surface_format_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1935 "that is greater than the value");
1936 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001937 surface_formats);
1938 pass = (err == VK_SUCCESS);
1939 ASSERT_TRUE(pass);
1940 m_errorMonitor->VerifyFound();
1941
1942 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001943 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1944 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001945 pass = (err == VK_SUCCESS);
1946 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001947 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001948 surface_formats);
1949 pass = (err == VK_SUCCESS);
1950 ASSERT_TRUE(pass);
1951
Ian Elliott2c1daf52016-05-12 09:41:46 -06001952 // Get the surface present modes:
1953 uint32_t surface_present_mode_count;
1954
1955 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1957 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001958 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
1959 pass = (err == VK_SUCCESS);
1960 ASSERT_TRUE(pass);
1961 m_errorMonitor->VerifyFound();
1962
1963 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
1964 // correctly done a 1st try (to get the count):
1965 m_errorMonitor->SetDesiredFailureMsg(
1966 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1967 "but no prior positive value has been seen for");
1968 surface_present_mode_count = 0;
1969 vkGetPhysicalDeviceSurfacePresentModesKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001970 gpu(), surface, &surface_present_mode_count,
1971 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001972 pass = (err == VK_SUCCESS);
1973 ASSERT_TRUE(pass);
1974 m_errorMonitor->VerifyFound();
1975
1976 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001977 vkGetPhysicalDeviceSurfacePresentModesKHR(
1978 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001979 pass = (err == VK_SUCCESS);
1980 ASSERT_TRUE(pass);
1981
1982 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001983 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(
1984 surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001985
1986 // Next, do a 2nd try with surface_format_count being set too high:
1987 surface_present_mode_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1989 "that is greater than the value");
1990 vkGetPhysicalDeviceSurfacePresentModesKHR(
1991 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001992 pass = (err == VK_SUCCESS);
1993 ASSERT_TRUE(pass);
1994 m_errorMonitor->VerifyFound();
1995
1996 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001997 vkGetPhysicalDeviceSurfacePresentModesKHR(
1998 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001999 pass = (err == VK_SUCCESS);
2000 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002001 vkGetPhysicalDeviceSurfacePresentModesKHR(
2002 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002003 pass = (err == VK_SUCCESS);
2004 ASSERT_TRUE(pass);
2005
Ian Elliott2c1daf52016-05-12 09:41:46 -06002006 // Create a swapchain:
2007
2008 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2010 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002011 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
2012 pass = (err != VK_SUCCESS);
2013 ASSERT_TRUE(pass);
2014 m_errorMonitor->VerifyFound();
2015
2016 // Next, call with a non-NULL swapchain_create_info, that has the wrong
2017 // sType:
2018 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2020 "called with the wrong value for");
2021 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2022 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002023 pass = (err != VK_SUCCESS);
2024 ASSERT_TRUE(pass);
2025 m_errorMonitor->VerifyFound();
2026
2027 // Next, call with a NULL swapchain pointer:
2028 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2029 swapchain_create_info.pNext = NULL;
2030 swapchain_create_info.flags = 0;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2032 "called with NULL pointer");
2033 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2034 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002035 pass = (err != VK_SUCCESS);
2036 ASSERT_TRUE(pass);
2037 m_errorMonitor->VerifyFound();
2038
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002039 // TODO: Enhance swapchain layer so that
2040 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06002041
2042 // Next, call with a queue family index that's too large:
2043 uint32_t queueFamilyIndex[2] = {100000, 0};
2044 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2045 swapchain_create_info.queueFamilyIndexCount = 2;
2046 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
2047 m_errorMonitor->SetDesiredFailureMsg(
2048 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2049 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002050 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2051 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002052 pass = (err != VK_SUCCESS);
2053 ASSERT_TRUE(pass);
2054 m_errorMonitor->VerifyFound();
2055
2056 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
2057 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2058 swapchain_create_info.queueFamilyIndexCount = 1;
2059 m_errorMonitor->SetDesiredFailureMsg(
2060 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2061 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
2062 "pCreateInfo->pQueueFamilyIndices).");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002063 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2064 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002065 pass = (err != VK_SUCCESS);
2066 ASSERT_TRUE(pass);
2067 m_errorMonitor->VerifyFound();
2068
2069 // Next, call with an invalid imageSharingMode:
2070 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
2071 swapchain_create_info.queueFamilyIndexCount = 1;
2072 m_errorMonitor->SetDesiredFailureMsg(
2073 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2074 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002075 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2076 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002077 pass = (err != VK_SUCCESS);
2078 ASSERT_TRUE(pass);
2079 m_errorMonitor->VerifyFound();
2080 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002081 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2082 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002083 swapchain_create_info.queueFamilyIndexCount = 0;
2084 queueFamilyIndex[0] = 0;
2085 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2086
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002087 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002088 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002089 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002090 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002091 // Destroy the swapchain:
2092
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002093 // TODOs:
2094 //
2095 // - Try destroying the device without first destroying the swapchain
2096 //
2097 // - Try destroying the device without first destroying the surface
2098 //
2099 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002100
2101 // Destroy the surface:
2102 vkDestroySurfaceKHR(instance(), surface, NULL);
2103
Ian Elliott2c1daf52016-05-12 09:41:46 -06002104 // Tear down the window:
2105 xcb_destroy_window(connection, xcb_window);
2106 xcb_disconnect(connection);
2107
2108#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002109 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002110#endif // VK_USE_PLATFORM_XCB_KHR
2111}
2112
Karl Schultz6addd812016-02-02 17:17:23 -07002113TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2114 VkResult err;
2115 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002116
Karl Schultz6addd812016-02-02 17:17:23 -07002117 m_errorMonitor->SetDesiredFailureMsg(
2118 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002119 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
2120
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002121 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002122
2123 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002124 VkImage image;
2125 VkDeviceMemory mem;
2126 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002127
Karl Schultz6addd812016-02-02 17:17:23 -07002128 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2129 const int32_t tex_width = 32;
2130 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002131
Tony Barboureb254902015-07-15 12:50:33 -06002132 VkImageCreateInfo image_create_info = {};
2133 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002134 image_create_info.pNext = NULL;
2135 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2136 image_create_info.format = tex_format;
2137 image_create_info.extent.width = tex_width;
2138 image_create_info.extent.height = tex_height;
2139 image_create_info.extent.depth = 1;
2140 image_create_info.mipLevels = 1;
2141 image_create_info.arrayLayers = 1;
2142 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2143 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2144 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2145 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002146
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002147 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002148 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002149 mem_alloc.pNext = NULL;
2150 mem_alloc.allocationSize = 0;
2151 // Introduce failure, do NOT set memProps to
2152 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
2153 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002154
Chia-I Wuf7458c52015-10-26 21:10:41 +08002155 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002156 ASSERT_VK_SUCCESS(err);
2157
Karl Schultz6addd812016-02-02 17:17:23 -07002158 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002159
Mark Lobodzinski23065352015-05-29 09:32:35 -05002160 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002161
Karl Schultz6addd812016-02-02 17:17:23 -07002162 pass =
2163 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0,
2164 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
2165 if (!pass) { // If we can't find any unmappable memory this test doesn't
2166 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002167 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002168 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002169 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002170
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002171 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002172 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002173 ASSERT_VK_SUCCESS(err);
2174
2175 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002176 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002177 ASSERT_VK_SUCCESS(err);
2178
2179 // Map memory as if to initialize the image
2180 void *mappedAddress = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07002181 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0,
2182 &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002183
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002184 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002185
Chia-I Wuf7458c52015-10-26 21:10:41 +08002186 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002187 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002188}
2189
Karl Schultz6addd812016-02-02 17:17:23 -07002190TEST_F(VkLayerTest, RebindMemory) {
2191 VkResult err;
2192 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002193
Karl Schultz6addd812016-02-02 17:17:23 -07002194 m_errorMonitor->SetDesiredFailureMsg(
2195 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002196 "which has already been bound to mem object");
2197
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002198 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002199
2200 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002201 VkImage image;
2202 VkDeviceMemory mem1;
2203 VkDeviceMemory mem2;
2204 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002205
Karl Schultz6addd812016-02-02 17:17:23 -07002206 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2207 const int32_t tex_width = 32;
2208 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002209
Tony Barboureb254902015-07-15 12:50:33 -06002210 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002211 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2212 image_create_info.pNext = NULL;
2213 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2214 image_create_info.format = tex_format;
2215 image_create_info.extent.width = tex_width;
2216 image_create_info.extent.height = tex_height;
2217 image_create_info.extent.depth = 1;
2218 image_create_info.mipLevels = 1;
2219 image_create_info.arrayLayers = 1;
2220 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2221 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2222 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2223 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002224
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002225 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002226 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2227 mem_alloc.pNext = NULL;
2228 mem_alloc.allocationSize = 0;
2229 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002230
Karl Schultz6addd812016-02-02 17:17:23 -07002231 // Introduce failure, do NOT set memProps to
2232 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002233 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002234 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002235 ASSERT_VK_SUCCESS(err);
2236
Karl Schultz6addd812016-02-02 17:17:23 -07002237 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002238
2239 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002240 pass =
2241 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002242 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002243
2244 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002245 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002246 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002247 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002248 ASSERT_VK_SUCCESS(err);
2249
2250 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002251 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002252 ASSERT_VK_SUCCESS(err);
2253
Karl Schultz6addd812016-02-02 17:17:23 -07002254 // Introduce validation failure, try to bind a different memory object to
2255 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002256 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002257
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002258 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002259
Chia-I Wuf7458c52015-10-26 21:10:41 +08002260 vkDestroyImage(m_device->device(), image, NULL);
2261 vkFreeMemory(m_device->device(), mem1, NULL);
2262 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002263}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002264
Karl Schultz6addd812016-02-02 17:17:23 -07002265TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002266 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002267
Karl Schultz6addd812016-02-02 17:17:23 -07002268 m_errorMonitor->SetDesiredFailureMsg(
2269 VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2270 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002271
2272 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002273 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2274 fenceInfo.pNext = NULL;
2275 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002276
Tony Barbour300a6082015-04-07 13:44:53 -06002277 ASSERT_NO_FATAL_FAILURE(InitState());
2278 ASSERT_NO_FATAL_FAILURE(InitViewport());
2279 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2280
Tony Barbourfe3351b2015-07-28 10:17:20 -06002281 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002282 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
2283 m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002284 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002285
2286 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002287
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002288 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002289 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2290 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002291 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002292 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002293 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002294 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002295 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002296 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002297 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002298
2299 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002300 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002301
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002302 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002303}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002304// This is a positive test. We used to expect error in this case but spec now
2305// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002306TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002307 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002308 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002309 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002310 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2311 fenceInfo.pNext = NULL;
2312
Tony Barbour0b4d9562015-04-09 10:48:04 -06002313 ASSERT_NO_FATAL_FAILURE(InitState());
2314 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002315 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002316 VkResult result = vkResetFences(m_device->device(), 1, fences);
2317 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002318
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002319 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002320}
Tobin Ehlis41376e12015-07-03 08:45:14 -06002321
Chris Forbese70b7d32016-06-15 15:49:12 +12002322#if 0
2323TEST_F(VkLayerTest, LongFenceChain)
2324{
2325 m_errorMonitor->ExpectSuccess();
2326
2327 ASSERT_NO_FATAL_FAILURE(InitState());
2328 VkResult err;
2329
2330 std::vector<VkFence> fences;
2331
2332 const int chainLength = 32768;
2333
2334 for (int i = 0; i < chainLength; i++) {
2335 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2336 VkFence fence;
2337 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2338 ASSERT_VK_SUCCESS(err);
2339
2340 fences.push_back(fence);
2341
2342 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2343 0, nullptr, 0, nullptr };
2344 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2345 ASSERT_VK_SUCCESS(err);
2346
2347 }
2348
2349 // BOOM, stack overflow.
2350 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
2351
2352 for (auto fence : fences)
2353 vkDestroyFence(m_device->device(), fence, nullptr);
2354
2355 m_errorMonitor->VerifyNotFound();
2356}
2357#endif
2358
Chris Forbes18127d12016-06-08 16:52:28 +12002359TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync)
2360{
2361 m_errorMonitor->ExpectSuccess();
2362
2363 ASSERT_NO_FATAL_FAILURE(InitState());
2364 VkResult err;
2365
2366 // Record (empty!) command buffer that can be submitted multiple times
2367 // simultaneously.
2368 VkCommandBufferBeginInfo cbbi = {
2369 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
2370 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr
2371 };
2372 m_commandBuffer->BeginCommandBuffer(&cbbi);
2373 m_commandBuffer->EndCommandBuffer();
2374
2375 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2376 VkFence fence;
2377 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2378 ASSERT_VK_SUCCESS(err);
2379
2380 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
2381 VkSemaphore s1, s2;
2382 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
2383 ASSERT_VK_SUCCESS(err);
2384 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
2385 ASSERT_VK_SUCCESS(err);
2386
2387 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
2388 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2389 1, &m_commandBuffer->handle(), 1, &s1 };
2390 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2391 ASSERT_VK_SUCCESS(err);
2392
2393 // Submit CB again, signaling s2.
2394 si.pSignalSemaphores = &s2;
2395 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
2396 ASSERT_VK_SUCCESS(err);
2397
2398 // Wait for fence.
2399 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2400 ASSERT_VK_SUCCESS(err);
2401
2402 // CB is still in flight from second submission, but semaphore s1 is no
2403 // longer in flight. delete it.
2404 vkDestroySemaphore(m_device->device(), s1, nullptr);
2405
2406 m_errorMonitor->VerifyNotFound();
2407
2408 // Force device idle and clean up remaining objects
2409 vkDeviceWaitIdle(m_device->device());
2410 vkDestroySemaphore(m_device->device(), s2, nullptr);
2411 vkDestroyFence(m_device->device(), fence, nullptr);
2412}
2413
Chris Forbes4e44c912016-06-16 10:20:00 +12002414TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling)
2415{
2416 m_errorMonitor->ExpectSuccess();
2417
2418 ASSERT_NO_FATAL_FAILURE(InitState());
2419 VkResult err;
2420
2421 // A fence created signaled
2422 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
2423 VkFence f1;
2424 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
2425 ASSERT_VK_SUCCESS(err);
2426
2427 // A fence created not
2428 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2429 VkFence f2;
2430 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
2431 ASSERT_VK_SUCCESS(err);
2432
2433 // Submit the unsignaled fence
2434 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2435 0, nullptr, 0, nullptr };
2436 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
2437
2438 // Wait on both fences, with signaled first.
2439 VkFence fences[] = { f1, f2 };
2440 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
2441
2442 // Should have both retired!
2443 vkDestroyFence(m_device->device(), f1, nullptr);
2444 vkDestroyFence(m_device->device(), f2, nullptr);
2445
2446 m_errorMonitor->VerifyNotFound();
2447}
2448
Tobin Ehlis41376e12015-07-03 08:45:14 -06002449TEST_F(VkLayerTest, InvalidUsageBits)
2450{
Tony Barbourf92621a2016-05-02 14:28:12 -06002451 TEST_DESCRIPTION(
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002452 "Specify wrong usage for image then create conflicting view of image "
Tony Barbourf92621a2016-05-02 14:28:12 -06002453 "Initialize buffer with wrong usage then perform copy expecting errors "
2454 "from both the image and the buffer (2 calls)");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002456 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002457
2458 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002459 VkImageObj image(m_device);
2460 // Initialize image with USAGE_INPUT_ATTACHMENT
Tobin Ehlis8b313c02016-05-25 15:01:52 -06002461 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT,
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002462 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
2463 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002464
Tony Barbourf92621a2016-05-02 14:28:12 -06002465 VkImageView dsv;
2466 VkImageViewCreateInfo dsvci = {};
2467 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2468 dsvci.image = image.handle();
2469 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2470 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2471 dsvci.subresourceRange.layerCount = 1;
2472 dsvci.subresourceRange.baseMipLevel = 0;
2473 dsvci.subresourceRange.levelCount = 1;
2474 dsvci.subresourceRange.aspectMask =
2475 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002476
Tony Barbourf92621a2016-05-02 14:28:12 -06002477 // Create a view with depth / stencil aspect for image with different usage
2478 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002479
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002480 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002481
2482 // Initialize buffer with TRANSFER_DST usage
2483 vk_testing::Buffer buffer;
2484 VkMemoryPropertyFlags reqs = 0;
2485 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2486 VkBufferImageCopy region = {};
2487 region.bufferRowLength = 128;
2488 region.bufferImageHeight = 128;
2489 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2490 region.imageSubresource.layerCount = 1;
2491 region.imageExtent.height = 16;
2492 region.imageExtent.width = 16;
2493 region.imageExtent.depth = 1;
2494
2495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2496 "Invalid usage flag for buffer ");
2497 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2498 // TRANSFER_DST
2499 BeginCommandBuffer();
2500 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2501 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2502 1, &region);
2503 m_errorMonitor->VerifyFound();
2504
2505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2506 "Invalid usage flag for image ");
2507 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2508 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2509 1, &region);
2510 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002511}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002512#endif // MEM_TRACKER_TESTS
2513
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002514#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002515
2516TEST_F(VkLayerTest, LeakAnObject) {
2517 VkResult err;
2518
2519 TEST_DESCRIPTION(
2520 "Create a fence and destroy its device without first destroying the fence.");
2521
2522 // Note that we have to create a new device since destroying the
2523 // framework's device causes Teardown() to fail and just calling Teardown
2524 // will destroy the errorMonitor.
2525
2526 m_errorMonitor->SetDesiredFailureMsg(
2527 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2528 "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object");
2529
2530 ASSERT_NO_FATAL_FAILURE(InitState());
2531
2532 const std::vector<VkQueueFamilyProperties> queue_props =
2533 m_device->queue_props;
2534 std::vector<VkDeviceQueueCreateInfo> queue_info;
2535 queue_info.reserve(queue_props.size());
2536 std::vector<std::vector<float>> queue_priorities;
2537 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2538 VkDeviceQueueCreateInfo qi = {};
2539 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2540 qi.pNext = NULL;
2541 qi.queueFamilyIndex = i;
2542 qi.queueCount = queue_props[i].queueCount;
2543 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2544 qi.pQueuePriorities = queue_priorities[i].data();
2545 queue_info.push_back(qi);
2546 }
2547
2548 std::vector<const char *> device_layer_names;
2549 std::vector<const char *> device_extension_names;
2550 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
2551 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
2552 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
2553 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
2554 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
2555 device_layer_names.push_back("VK_LAYER_LUNARG_image");
2556 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
2557
2558 // The sacrificial device object
2559 VkDevice testDevice;
2560 VkDeviceCreateInfo device_create_info = {};
2561 auto features = m_device->phy().features();
2562 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2563 device_create_info.pNext = NULL;
2564 device_create_info.queueCreateInfoCount = queue_info.size();
2565 device_create_info.pQueueCreateInfos = queue_info.data();
2566 device_create_info.enabledLayerCount = device_layer_names.size();
2567 device_create_info.ppEnabledLayerNames = device_layer_names.data();
2568 device_create_info.pEnabledFeatures = &features;
2569 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2570 ASSERT_VK_SUCCESS(err);
2571
2572 VkFence fence;
2573 VkFenceCreateInfo fence_create_info = {};
2574 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2575 fence_create_info.pNext = NULL;
2576 fence_create_info.flags = 0;
2577 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2578 ASSERT_VK_SUCCESS(err);
2579
2580 // Induce failure by not calling vkDestroyFence
2581 vkDestroyDevice(testDevice, NULL);
2582 m_errorMonitor->VerifyFound();
2583}
2584
2585TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2586
2587 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2588 "attempt to delete them from another.");
2589
2590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2591 "FreeCommandBuffers is attempting to free Command Buffer");
2592
2593 VkCommandPool command_pool_one;
2594 VkCommandPool command_pool_two;
2595
2596 VkCommandPoolCreateInfo pool_create_info{};
2597 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2598 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2599 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2600
2601 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2602 &command_pool_one);
2603
2604 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2605 &command_pool_two);
2606
2607 VkCommandBuffer command_buffer[9];
2608 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2609 command_buffer_allocate_info.sType =
2610 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2611 command_buffer_allocate_info.commandPool = command_pool_one;
2612 command_buffer_allocate_info.commandBufferCount = 9;
2613 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2614 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2615 command_buffer);
2616
2617 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4,
2618 &command_buffer[3]);
2619
2620 m_errorMonitor->VerifyFound();
2621
2622 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2623 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2624}
2625
2626TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2627 VkResult err;
2628
2629 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
2630 "attempt to delete them from another.");
2631
2632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2633 "FreeDescriptorSets is attempting to free descriptorSet");
2634
2635 ASSERT_NO_FATAL_FAILURE(InitState());
2636 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2637
2638 VkDescriptorPoolSize ds_type_count = {};
2639 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2640 ds_type_count.descriptorCount = 1;
2641
2642 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2643 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2644 ds_pool_ci.pNext = NULL;
2645 ds_pool_ci.flags = 0;
2646 ds_pool_ci.maxSets = 1;
2647 ds_pool_ci.poolSizeCount = 1;
2648 ds_pool_ci.pPoolSizes = &ds_type_count;
2649
2650 VkDescriptorPool ds_pool_one;
2651 err =
2652 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
2653 ASSERT_VK_SUCCESS(err);
2654
2655 // Create a second descriptor pool
2656 VkDescriptorPool ds_pool_two;
2657 err =
2658 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
2659 ASSERT_VK_SUCCESS(err);
2660
2661 VkDescriptorSetLayoutBinding dsl_binding = {};
2662 dsl_binding.binding = 0;
2663 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2664 dsl_binding.descriptorCount = 1;
2665 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2666 dsl_binding.pImmutableSamplers = NULL;
2667
2668 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2669 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2670 ds_layout_ci.pNext = NULL;
2671 ds_layout_ci.bindingCount = 1;
2672 ds_layout_ci.pBindings = &dsl_binding;
2673
2674 VkDescriptorSetLayout ds_layout;
2675 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2676 &ds_layout);
2677 ASSERT_VK_SUCCESS(err);
2678
2679 VkDescriptorSet descriptorSet;
2680 VkDescriptorSetAllocateInfo alloc_info = {};
2681 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2682 alloc_info.descriptorSetCount = 1;
2683 alloc_info.descriptorPool = ds_pool_one;
2684 alloc_info.pSetLayouts = &ds_layout;
2685 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2686 &descriptorSet);
2687 ASSERT_VK_SUCCESS(err);
2688
2689 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2690
2691 m_errorMonitor->VerifyFound();
2692
2693 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2694 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2695 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2696}
2697
2698TEST_F(VkLayerTest, CreateUnknownObject) {
2699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2700 "Invalid VkImage Object ");
2701
2702 TEST_DESCRIPTION(
2703 "Pass an invalid image object handle into a Vulkan API call.");
2704
2705 ASSERT_NO_FATAL_FAILURE(InitState());
2706
2707 // Pass bogus handle into GetImageMemoryRequirements
2708 VkMemoryRequirements mem_reqs;
2709 uint64_t fakeImageHandle = 0xCADECADE;
2710 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2711
2712 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2713
2714 m_errorMonitor->VerifyFound();
2715}
2716
Karl Schultz6addd812016-02-02 17:17:23 -07002717TEST_F(VkLayerTest, PipelineNotBound) {
2718 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002719
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002720 TEST_DESCRIPTION(
2721 "Pass in an invalid pipeline object handle into a Vulkan API call.");
2722
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002724 "Invalid VkPipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002725
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002726 ASSERT_NO_FATAL_FAILURE(InitState());
2727 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002728
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002729 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002730 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2731 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002732
2733 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002734 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2735 ds_pool_ci.pNext = NULL;
2736 ds_pool_ci.maxSets = 1;
2737 ds_pool_ci.poolSizeCount = 1;
2738 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002739
2740 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002741 err =
2742 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002743 ASSERT_VK_SUCCESS(err);
2744
2745 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002746 dsl_binding.binding = 0;
2747 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2748 dsl_binding.descriptorCount = 1;
2749 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2750 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002751
2752 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002753 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2754 ds_layout_ci.pNext = NULL;
2755 ds_layout_ci.bindingCount = 1;
2756 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002757
2758 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002759 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2760 &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002761 ASSERT_VK_SUCCESS(err);
2762
2763 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002764 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002765 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002766 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002767 alloc_info.descriptorPool = ds_pool;
2768 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002769 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2770 &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002771 ASSERT_VK_SUCCESS(err);
2772
2773 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002774 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2775 pipeline_layout_ci.pNext = NULL;
2776 pipeline_layout_ci.setLayoutCount = 1;
2777 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002778
2779 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002780 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2781 &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002782 ASSERT_VK_SUCCESS(err);
2783
Mark Youngad779052016-01-06 14:26:04 -07002784 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002785
2786 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002787 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
2788 VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002789
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002790 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002791
Chia-I Wuf7458c52015-10-26 21:10:41 +08002792 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2793 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2794 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002795}
Tobin Ehlis93d57e12016-06-20 11:32:13 -06002796#if 0 // Disabling this test for now, needs to be updated
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002797TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2798 VkResult err;
2799
2800 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2801 "during bind[Buffer|Image]Memory time");
2802
2803 m_errorMonitor->SetDesiredFailureMsg(
2804 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2805 "for this object type are not compatible with the memory");
2806
2807 ASSERT_NO_FATAL_FAILURE(InitState());
2808
2809 // Create an image, allocate memory, set a bad typeIndex and then try to
2810 // bind it
2811 VkImage image;
2812 VkDeviceMemory mem;
2813 VkMemoryRequirements mem_reqs;
2814 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2815 const int32_t tex_width = 32;
2816 const int32_t tex_height = 32;
2817
2818 VkImageCreateInfo image_create_info = {};
2819 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2820 image_create_info.pNext = NULL;
2821 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2822 image_create_info.format = tex_format;
2823 image_create_info.extent.width = tex_width;
2824 image_create_info.extent.height = tex_height;
2825 image_create_info.extent.depth = 1;
2826 image_create_info.mipLevels = 1;
2827 image_create_info.arrayLayers = 1;
2828 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2829 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2830 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2831 image_create_info.flags = 0;
2832
2833 VkMemoryAllocateInfo mem_alloc = {};
2834 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2835 mem_alloc.pNext = NULL;
2836 mem_alloc.allocationSize = 0;
2837 mem_alloc.memoryTypeIndex = 0;
2838
2839 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2840 ASSERT_VK_SUCCESS(err);
2841
2842 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2843 mem_alloc.allocationSize = mem_reqs.size;
Tobin Ehlis93d57e12016-06-20 11:32:13 -06002844 // TODO : This is not an ideal way to cause the error and triggers a segF
2845 // on at least one android driver when attempting to Allocate the memory.
2846 // That segF may or may not be a driver bug, but really what we want to do
2847 // here is find a device-supported memory type that is also not supported
2848 // for the particular image we're binding the memory too. If no such
2849 // type exists, then we can print a message and skip the test.
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002850 // Introduce Failure, select likely invalid TypeIndex
2851 mem_alloc.memoryTypeIndex = 31;
2852
2853 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2854 ASSERT_VK_SUCCESS(err);
2855
2856 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2857 (void)err;
2858
2859 m_errorMonitor->VerifyFound();
2860
2861 vkDestroyImage(m_device->device(), image, NULL);
2862 vkFreeMemory(m_device->device(), mem, NULL);
2863}
Tobin Ehlis93d57e12016-06-20 11:32:13 -06002864#endif
Karl Schultz6addd812016-02-02 17:17:23 -07002865TEST_F(VkLayerTest, BindInvalidMemory) {
2866 VkResult err;
2867 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002868
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002870 "Invalid VkDeviceMemory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002871
Tobin Ehlisec598302015-09-15 15:02:17 -06002872 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002873
2874 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002875 VkImage image;
2876 VkDeviceMemory mem;
2877 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002878
Karl Schultz6addd812016-02-02 17:17:23 -07002879 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2880 const int32_t tex_width = 32;
2881 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002882
2883 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002884 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2885 image_create_info.pNext = NULL;
2886 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2887 image_create_info.format = tex_format;
2888 image_create_info.extent.width = tex_width;
2889 image_create_info.extent.height = tex_height;
2890 image_create_info.extent.depth = 1;
2891 image_create_info.mipLevels = 1;
2892 image_create_info.arrayLayers = 1;
2893 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2894 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2895 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2896 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002897
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002898 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002899 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2900 mem_alloc.pNext = NULL;
2901 mem_alloc.allocationSize = 0;
2902 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002903
Chia-I Wuf7458c52015-10-26 21:10:41 +08002904 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002905 ASSERT_VK_SUCCESS(err);
2906
Karl Schultz6addd812016-02-02 17:17:23 -07002907 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002908
2909 mem_alloc.allocationSize = mem_reqs.size;
2910
Karl Schultz6addd812016-02-02 17:17:23 -07002911 pass =
2912 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002913 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002914
2915 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002916 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002917 ASSERT_VK_SUCCESS(err);
2918
2919 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002920 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002921
2922 // Try to bind free memory that has been freed
2923 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2924 // This may very well return an error.
2925 (void)err;
2926
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002927 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002928
Chia-I Wuf7458c52015-10-26 21:10:41 +08002929 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002930}
2931
Karl Schultz6addd812016-02-02 17:17:23 -07002932TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2933 VkResult err;
2934 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002935
Karl Schultz6addd812016-02-02 17:17:23 -07002936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2937 "Invalid VkImage Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002938
Tobin Ehlisec598302015-09-15 15:02:17 -06002939 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002940
Karl Schultz6addd812016-02-02 17:17:23 -07002941 // Create an image object, allocate memory, destroy the object and then try
2942 // to bind it
2943 VkImage image;
2944 VkDeviceMemory mem;
2945 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002946
Karl Schultz6addd812016-02-02 17:17:23 -07002947 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2948 const int32_t tex_width = 32;
2949 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002950
2951 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002952 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2953 image_create_info.pNext = NULL;
2954 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2955 image_create_info.format = tex_format;
2956 image_create_info.extent.width = tex_width;
2957 image_create_info.extent.height = tex_height;
2958 image_create_info.extent.depth = 1;
2959 image_create_info.mipLevels = 1;
2960 image_create_info.arrayLayers = 1;
2961 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2962 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2963 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2964 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002965
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002966 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002967 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2968 mem_alloc.pNext = NULL;
2969 mem_alloc.allocationSize = 0;
2970 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002971
Chia-I Wuf7458c52015-10-26 21:10:41 +08002972 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002973 ASSERT_VK_SUCCESS(err);
2974
Karl Schultz6addd812016-02-02 17:17:23 -07002975 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002976
2977 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002978 pass =
2979 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002980 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002981
2982 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002983 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002984 ASSERT_VK_SUCCESS(err);
2985
2986 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002987 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002988 ASSERT_VK_SUCCESS(err);
2989
2990 // Now Try to bind memory to this destroyed object
2991 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2992 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002993 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002994
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002995 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002996
Chia-I Wuf7458c52015-10-26 21:10:41 +08002997 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002998}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002999
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003000#endif // OBJ_TRACKER_TESTS
3001
Tobin Ehlis0788f522015-05-26 16:11:58 -06003002#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003003
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06003004// This is a positive test. No errors are expected.
3005TEST_F(VkLayerTest, StencilLoadOp) {
3006 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
3007 "CLEAR. stencil[Load|Store]Op used to be ignored.");
3008 VkResult result = VK_SUCCESS;
3009 VkImageFormatProperties formatProps;
3010 vkGetPhysicalDeviceImageFormatProperties(
3011 gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D,
3012 VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
3013 VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
3014 0, &formatProps);
3015 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
3016 return;
3017 }
3018
3019 ASSERT_NO_FATAL_FAILURE(InitState());
3020 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
3021 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
3022 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
3023 VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
3024 VkAttachmentDescription att = {};
3025 VkAttachmentReference ref = {};
3026 att.format = depth_stencil_fmt;
3027 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
3028 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
3029 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
3030 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
3031 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3032 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3033
3034 VkClearValue clear;
3035 clear.depthStencil.depth = 1.0;
3036 clear.depthStencil.stencil = 0;
3037 ref.attachment = 0;
3038 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3039
3040 VkSubpassDescription subpass = {};
3041 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
3042 subpass.flags = 0;
3043 subpass.inputAttachmentCount = 0;
3044 subpass.pInputAttachments = NULL;
3045 subpass.colorAttachmentCount = 0;
3046 subpass.pColorAttachments = NULL;
3047 subpass.pResolveAttachments = NULL;
3048 subpass.pDepthStencilAttachment = &ref;
3049 subpass.preserveAttachmentCount = 0;
3050 subpass.pPreserveAttachments = NULL;
3051
3052 VkRenderPass rp;
3053 VkRenderPassCreateInfo rp_info = {};
3054 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3055 rp_info.attachmentCount = 1;
3056 rp_info.pAttachments = &att;
3057 rp_info.subpassCount = 1;
3058 rp_info.pSubpasses = &subpass;
3059 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
3060 ASSERT_VK_SUCCESS(result);
3061
3062 VkImageView *depthView = m_depthStencil->BindInfo();
3063 VkFramebufferCreateInfo fb_info = {};
3064 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3065 fb_info.pNext = NULL;
3066 fb_info.renderPass = rp;
3067 fb_info.attachmentCount = 1;
3068 fb_info.pAttachments = depthView;
3069 fb_info.width = 100;
3070 fb_info.height = 100;
3071 fb_info.layers = 1;
3072 VkFramebuffer fb;
3073 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3074 ASSERT_VK_SUCCESS(result);
3075
3076
3077 VkRenderPassBeginInfo rpbinfo = {};
3078 rpbinfo.clearValueCount = 1;
3079 rpbinfo.pClearValues = &clear;
3080 rpbinfo.pNext = NULL;
3081 rpbinfo.renderPass = rp;
3082 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
3083 rpbinfo.renderArea.extent.width = 100;
3084 rpbinfo.renderArea.extent.height = 100;
3085 rpbinfo.renderArea.offset.x = 0;
3086 rpbinfo.renderArea.offset.y = 0;
3087 rpbinfo.framebuffer = fb;
3088
3089 VkFence fence = {};
3090 VkFenceCreateInfo fence_ci = {};
3091 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3092 fence_ci.pNext = nullptr;
3093 fence_ci.flags = 0;
3094 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
3095 ASSERT_VK_SUCCESS(result);
3096
3097
3098 m_commandBuffer->BeginCommandBuffer();
3099 m_commandBuffer->BeginRenderPass(rpbinfo);
3100 m_commandBuffer->EndRenderPass();
3101 m_commandBuffer->EndCommandBuffer();
3102 m_commandBuffer->QueueCommandBuffer(fence);
3103
3104 VkImageObj destImage(m_device);
3105 destImage.init(100, 100, depth_stencil_fmt,
3106 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
3107 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
3108 VK_IMAGE_TILING_OPTIMAL, 0);
3109 VkImageMemoryBarrier barrier = {};
3110 VkImageSubresourceRange range;
3111 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
3112 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT |
3113 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
3114 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT |
3115 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
3116 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3117 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
3118 barrier.image = m_depthStencil->handle();
3119 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3120 range.baseMipLevel = 0;
3121 range.levelCount = 1;
3122 range.baseArrayLayer = 0;
3123 range.layerCount = 1;
3124 barrier.subresourceRange = range;
3125 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3126 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
3127 cmdbuf.BeginCommandBuffer();
3128 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3129 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0,
3130 nullptr, 1, &barrier);
3131 barrier.srcAccessMask = 0;
3132 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3133 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
3134 barrier.image = destImage.handle();
3135 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT |
3136 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
3137 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3138 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0,
3139 nullptr, 1, &barrier);
3140 VkImageCopy cregion;
3141 cregion.srcSubresource.aspectMask =
3142 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3143 cregion.srcSubresource.mipLevel = 0;
3144 cregion.srcSubresource.baseArrayLayer = 0;
3145 cregion.srcSubresource.layerCount = 1;
3146 cregion.srcOffset.x = 0;
3147 cregion.srcOffset.y = 0;
3148 cregion.srcOffset.z = 0;
3149 cregion.dstSubresource.aspectMask =
3150 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3151 cregion.dstSubresource.mipLevel = 0;
3152 cregion.dstSubresource.baseArrayLayer = 0;
3153 cregion.dstSubresource.layerCount = 1;
3154 cregion.dstOffset.x = 0;
3155 cregion.dstOffset.y = 0;
3156 cregion.dstOffset.z = 0;
3157 cregion.extent.width = 100;
3158 cregion.extent.height = 100;
3159 cregion.extent.depth = 1;
3160 cmdbuf.CopyImage(m_depthStencil->handle(),
3161 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
3162 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
3163 cmdbuf.EndCommandBuffer();
3164
3165 VkSubmitInfo submit_info;
3166 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3167 submit_info.pNext = NULL;
3168 submit_info.waitSemaphoreCount = 0;
3169 submit_info.pWaitSemaphores = NULL;
3170 submit_info.pWaitDstStageMask = NULL;
3171 submit_info.commandBufferCount = 1;
3172 submit_info.pCommandBuffers = &cmdbuf.handle();
3173 submit_info.signalSemaphoreCount = 0;
3174 submit_info.pSignalSemaphores = NULL;
3175
3176 m_errorMonitor->ExpectSuccess();
3177 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3178 m_errorMonitor->VerifyNotFound();
3179
Mark Lobodzinskid0440da2016-06-17 15:10:03 -06003180 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06003181 vkDestroyFence(m_device->device(), fence, nullptr);
3182 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3183 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3184}
3185
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003186TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3187 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3188 "attachment reference of VK_ATTACHMENT_UNUSED");
3189
3190 ASSERT_NO_FATAL_FAILURE(InitState());
3191 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3192
3193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3194 "must not be VK_ATTACHMENT_UNUSED");
3195
3196 VkAttachmentReference color_attach = {};
3197 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3198 color_attach.attachment = 0;
3199 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3200 VkSubpassDescription subpass = {};
3201 subpass.colorAttachmentCount = 1;
3202 subpass.pColorAttachments = &color_attach;
3203 subpass.preserveAttachmentCount = 1;
3204 subpass.pPreserveAttachments = &preserve_attachment;
3205
3206 VkRenderPassCreateInfo rpci = {};
3207 rpci.subpassCount = 1;
3208 rpci.pSubpasses = &subpass;
3209 rpci.attachmentCount = 1;
3210 VkAttachmentDescription attach_desc = {};
3211 attach_desc.format = VK_FORMAT_UNDEFINED;
3212 rpci.pAttachments = &attach_desc;
3213 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3214 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003215 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003216
3217 m_errorMonitor->VerifyFound();
3218
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003219 if (result == VK_SUCCESS) {
3220 vkDestroyRenderPass(m_device->device(), rp, NULL);
3221 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003222}
3223
3224TEST_F(VkLayerTest, AttachmentUsageMismatch) {
3225 TEST_DESCRIPTION("Create a framebuffer where a subpass uses a color image "
3226 "in the depthStencil attachment point");
3227
3228 ASSERT_NO_FATAL_FAILURE(InitState());
3229 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3230
3231 m_errorMonitor->SetDesiredFailureMsg(
3232 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3233 "conflicts with the image's IMAGE_USAGE flags");
3234
3235 // Create a renderPass with a depth-stencil attachment created with
3236 // IMAGE_USAGE_COLOR_ATTACHMENT
3237 VkAttachmentReference attach = {};
3238 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3239 VkSubpassDescription subpass = {};
3240 // Add our color attachment to pDepthStencilAttachment
3241 subpass.pDepthStencilAttachment = &attach;
3242 VkRenderPassCreateInfo rpci = {};
3243 rpci.subpassCount = 1;
3244 rpci.pSubpasses = &subpass;
3245 rpci.attachmentCount = 1;
3246 VkAttachmentDescription attach_desc = {};
3247 attach_desc.format = VK_FORMAT_UNDEFINED;
3248 rpci.pAttachments = &attach_desc;
3249 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3250 VkRenderPass rp;
3251 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3252 ASSERT_VK_SUCCESS(err);
3253
3254 VkImageView imageView =
3255 m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3256 VkFramebufferCreateInfo fb_info = {};
3257 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3258 fb_info.pNext = NULL;
3259 fb_info.renderPass = rp;
3260 fb_info.attachmentCount = 1;
3261 fb_info.pAttachments = &imageView;
3262 fb_info.width = 100;
3263 fb_info.height = 100;
3264 fb_info.layers = 1;
3265
3266 VkFramebuffer fb;
3267 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3268
3269 m_errorMonitor->VerifyFound();
3270
3271 if (err == VK_SUCCESS) {
3272 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3273 }
3274 vkDestroyRenderPass(m_device->device(), rp, NULL);
3275}
3276
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003277// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05003278TEST_F(VkLayerTest, WaitEventThenSet) {
3279 TEST_DESCRIPTION(
3280 "Wait on a event then set it after the wait has been submitted.");
3281
Michael Lentine860b0fe2016-05-20 10:14:00 -05003282 m_errorMonitor->ExpectSuccess();
3283
3284 VkEvent event;
3285 VkEventCreateInfo event_create_info{};
3286 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3287 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
3288
3289 VkCommandPool command_pool;
3290 VkCommandPoolCreateInfo pool_create_info{};
3291 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3292 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3293 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3294 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3295 &command_pool);
3296
3297 VkCommandBuffer command_buffer;
3298 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3299 command_buffer_allocate_info.sType =
3300 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3301 command_buffer_allocate_info.commandPool = command_pool;
3302 command_buffer_allocate_info.commandBufferCount = 1;
3303 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3304 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3305 &command_buffer);
3306
3307 VkQueue queue = VK_NULL_HANDLE;
3308 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
Tony Barbourfe302c02016-06-06 13:05:19 -06003309 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05003310
3311 {
3312 VkCommandBufferBeginInfo begin_info{};
3313 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3314 vkBeginCommandBuffer(command_buffer, &begin_info);
3315
3316 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT,
3317 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
3318 nullptr, 0, nullptr);
3319 vkCmdResetEvent(command_buffer, event,
3320 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
3321 vkEndCommandBuffer(command_buffer);
3322 }
3323 {
3324 VkSubmitInfo submit_info{};
3325 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3326 submit_info.commandBufferCount = 1;
3327 submit_info.pCommandBuffers = &command_buffer;
3328 submit_info.signalSemaphoreCount = 0;
3329 submit_info.pSignalSemaphores = nullptr;
3330 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3331 }
3332 { vkSetEvent(m_device->device(), event); }
3333
3334 vkQueueWaitIdle(queue);
3335
3336 vkDestroyEvent(m_device->device(), event, nullptr);
3337 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
3338 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3339
3340 m_errorMonitor->VerifyNotFound();
3341}
Michael Lentine5627e692016-05-20 17:45:02 -05003342// This is a positive test. No errors should be generated.
3343TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
3344 TEST_DESCRIPTION(
3345 "Issue a query and copy from it on a second command buffer.");
3346
3347 if ((m_device->queue_props.empty()) ||
3348 (m_device->queue_props[0].queueCount < 2))
3349 return;
3350
3351 m_errorMonitor->ExpectSuccess();
3352
3353 VkQueryPool query_pool;
3354 VkQueryPoolCreateInfo query_pool_create_info{};
3355 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
3356 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
3357 query_pool_create_info.queryCount = 1;
3358 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr,
3359 &query_pool);
3360
3361 VkCommandPool command_pool;
3362 VkCommandPoolCreateInfo pool_create_info{};
3363 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3364 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3365 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3366 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3367 &command_pool);
3368
3369 VkCommandBuffer command_buffer[2];
3370 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3371 command_buffer_allocate_info.sType =
3372 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3373 command_buffer_allocate_info.commandPool = command_pool;
3374 command_buffer_allocate_info.commandBufferCount = 2;
3375 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3376 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3377 command_buffer);
3378
3379 VkQueue queue = VK_NULL_HANDLE;
3380 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3381 1, &queue);
3382
3383 uint32_t qfi = 0;
3384 VkBufferCreateInfo buff_create_info = {};
3385 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3386 buff_create_info.size = 1024;
3387 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
3388 buff_create_info.queueFamilyIndexCount = 1;
3389 buff_create_info.pQueueFamilyIndices = &qfi;
3390
3391 VkResult err;
3392 VkBuffer buffer;
3393 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
3394 ASSERT_VK_SUCCESS(err);
3395 VkMemoryAllocateInfo mem_alloc = {};
3396 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3397 mem_alloc.pNext = NULL;
3398 mem_alloc.allocationSize = 1024;
3399 mem_alloc.memoryTypeIndex = 0;
3400
3401 VkMemoryRequirements memReqs;
3402 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
3403 bool pass =
3404 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
3405 if (!pass) {
3406 vkDestroyBuffer(m_device->device(), buffer, NULL);
3407 return;
3408 }
3409
3410 VkDeviceMemory mem;
3411 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3412 ASSERT_VK_SUCCESS(err);
3413 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
3414 ASSERT_VK_SUCCESS(err);
3415
3416 {
3417 VkCommandBufferBeginInfo begin_info{};
3418 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3419 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3420
3421 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
3422 vkCmdWriteTimestamp(command_buffer[0],
3423 VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
3424
3425 vkEndCommandBuffer(command_buffer[0]);
3426
3427 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3428
3429 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer,
3430 0, 0, 0);
3431
3432 vkEndCommandBuffer(command_buffer[1]);
3433 }
3434 {
3435 VkSubmitInfo submit_info{};
3436 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3437 submit_info.commandBufferCount = 2;
3438 submit_info.pCommandBuffers = command_buffer;
3439 submit_info.signalSemaphoreCount = 0;
3440 submit_info.pSignalSemaphores = nullptr;
3441 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3442 }
3443
3444 vkQueueWaitIdle(queue);
3445
3446 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
3447 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
3448 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06003449 vkDestroyBuffer(m_device->device(), buffer, NULL);
3450 vkFreeMemory(m_device->device(), mem, NULL);
Michael Lentine5627e692016-05-20 17:45:02 -05003451
3452 m_errorMonitor->VerifyNotFound();
3453}
Michael Lentine860b0fe2016-05-20 10:14:00 -05003454
3455TEST_F(VkLayerTest, ResetEventThenSet) {
3456 TEST_DESCRIPTION(
3457 "Reset an event then set it after the reset has been submitted.");
3458
Michael Lentine860b0fe2016-05-20 10:14:00 -05003459 m_errorMonitor->ExpectSuccess();
3460
3461 VkEvent event;
3462 VkEventCreateInfo event_create_info{};
3463 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3464 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
3465
3466 VkCommandPool command_pool;
3467 VkCommandPoolCreateInfo pool_create_info{};
3468 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3469 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3470 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3471 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3472 &command_pool);
3473
3474 VkCommandBuffer command_buffer;
3475 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3476 command_buffer_allocate_info.sType =
3477 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3478 command_buffer_allocate_info.commandPool = command_pool;
3479 command_buffer_allocate_info.commandBufferCount = 1;
3480 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3481 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3482 &command_buffer);
3483
3484 VkQueue queue = VK_NULL_HANDLE;
3485 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
Tony Barbourfe302c02016-06-06 13:05:19 -06003486 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05003487
3488 {
3489 VkCommandBufferBeginInfo begin_info{};
3490 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3491 vkBeginCommandBuffer(command_buffer, &begin_info);
3492
3493 vkCmdResetEvent(command_buffer, event,
3494 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
3495 vkCmdWaitEvents(command_buffer, 1, &event,
3496 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3497 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
3498 nullptr, 0, nullptr);
3499 vkEndCommandBuffer(command_buffer);
3500 }
3501 {
3502 VkSubmitInfo submit_info{};
3503 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3504 submit_info.commandBufferCount = 1;
3505 submit_info.pCommandBuffers = &command_buffer;
3506 submit_info.signalSemaphoreCount = 0;
3507 submit_info.pSignalSemaphores = nullptr;
3508 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3509 }
3510 {
3511 m_errorMonitor->SetDesiredFailureMsg(
3512 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event "
3513 "0x1 that is already in use by a "
3514 "command buffer.");
3515 vkSetEvent(m_device->device(), event);
3516 m_errorMonitor->VerifyFound();
3517 }
3518
3519 vkQueueWaitIdle(queue);
3520
3521 vkDestroyEvent(m_device->device(), event, nullptr);
3522 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
3523 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3524}
3525
3526// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003527TEST_F(VkLayerTest, TwoFencesThreeFrames) {
3528 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
3529 "run through a Submit & WaitForFences cycle 3 times. This "
3530 "previously revealed a bug so running this positive test "
3531 "to prevent a regression.");
3532 m_errorMonitor->ExpectSuccess();
3533
3534 ASSERT_NO_FATAL_FAILURE(InitState());
3535 VkQueue queue = VK_NULL_HANDLE;
3536 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3537 0, &queue);
3538
3539 static const uint32_t NUM_OBJECTS = 2;
3540 static const uint32_t NUM_FRAMES = 3;
3541 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
3542 VkFence fences[NUM_OBJECTS] = {};
3543
3544 VkCommandPool cmd_pool;
3545 VkCommandPoolCreateInfo cmd_pool_ci = {};
3546 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3547 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
3548 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3549 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci,
3550 nullptr, &cmd_pool);
3551 ASSERT_VK_SUCCESS(err);
3552
3553 VkCommandBufferAllocateInfo cmd_buf_info = {};
3554 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3555 cmd_buf_info.commandPool = cmd_pool;
3556 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3557 cmd_buf_info.commandBufferCount = 1;
3558
3559 VkFenceCreateInfo fence_ci = {};
3560 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3561 fence_ci.pNext = nullptr;
3562 fence_ci.flags = 0;
3563
3564 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3565 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info,
3566 &cmd_buffers[i]);
3567 ASSERT_VK_SUCCESS(err);
3568 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
3569 ASSERT_VK_SUCCESS(err);
3570 }
3571
3572 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06003573 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
3574 // Create empty cmd buffer
3575 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3576 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003577
Tobin Ehlisf9025162016-05-26 06:55:21 -06003578 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
3579 ASSERT_VK_SUCCESS(err);
3580 err = vkEndCommandBuffer(cmd_buffers[obj]);
3581 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003582
Tobin Ehlisf9025162016-05-26 06:55:21 -06003583 VkSubmitInfo submit_info = {};
3584 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3585 submit_info.commandBufferCount = 1;
3586 submit_info.pCommandBuffers = &cmd_buffers[obj];
3587 // Submit cmd buffer and wait for fence
3588 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
3589 ASSERT_VK_SUCCESS(err);
3590 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE,
3591 UINT64_MAX);
3592 ASSERT_VK_SUCCESS(err);
3593 err = vkResetFences(m_device->device(), 1, &fences[obj]);
3594 ASSERT_VK_SUCCESS(err);
3595 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003596 }
3597 m_errorMonitor->VerifyNotFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06003598 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
3599 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3600 vkDestroyFence(m_device->device(), fences[i], nullptr);
3601 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003602}
3603// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003604TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
3605
3606 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3607 "submitted on separate queues followed by a QueueWaitIdle.");
3608
Dustin Graves48458142016-04-29 16:11:55 -06003609 if ((m_device->queue_props.empty()) ||
3610 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003611 return;
3612
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003613 m_errorMonitor->ExpectSuccess();
3614
3615 VkSemaphore semaphore;
3616 VkSemaphoreCreateInfo semaphore_create_info{};
3617 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3618 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3619 &semaphore);
3620
3621 VkCommandPool command_pool;
3622 VkCommandPoolCreateInfo pool_create_info{};
3623 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3624 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3625 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3626 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3627 &command_pool);
3628
3629 VkCommandBuffer command_buffer[2];
3630 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3631 command_buffer_allocate_info.sType =
3632 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3633 command_buffer_allocate_info.commandPool = command_pool;
3634 command_buffer_allocate_info.commandBufferCount = 2;
3635 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3636 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3637 command_buffer);
3638
3639 VkQueue queue = VK_NULL_HANDLE;
3640 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3641 1, &queue);
3642
3643 {
3644 VkCommandBufferBeginInfo begin_info{};
3645 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3646 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3647
3648 vkCmdPipelineBarrier(command_buffer[0],
3649 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3650 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3651 0, nullptr, 0, nullptr);
3652
3653 VkViewport viewport{};
3654 viewport.maxDepth = 1.0f;
3655 viewport.minDepth = 0.0f;
3656 viewport.width = 512;
3657 viewport.height = 512;
3658 viewport.x = 0;
3659 viewport.y = 0;
3660 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3661 vkEndCommandBuffer(command_buffer[0]);
3662 }
3663 {
3664 VkCommandBufferBeginInfo begin_info{};
3665 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3666 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3667
3668 VkViewport viewport{};
3669 viewport.maxDepth = 1.0f;
3670 viewport.minDepth = 0.0f;
3671 viewport.width = 512;
3672 viewport.height = 512;
3673 viewport.x = 0;
3674 viewport.y = 0;
3675 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3676 vkEndCommandBuffer(command_buffer[1]);
3677 }
3678 {
3679 VkSubmitInfo submit_info{};
3680 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3681 submit_info.commandBufferCount = 1;
3682 submit_info.pCommandBuffers = &command_buffer[0];
3683 submit_info.signalSemaphoreCount = 1;
3684 submit_info.pSignalSemaphores = &semaphore;
3685 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3686 }
3687 {
3688 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3689 VkSubmitInfo submit_info{};
3690 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3691 submit_info.commandBufferCount = 1;
3692 submit_info.pCommandBuffers = &command_buffer[1];
3693 submit_info.waitSemaphoreCount = 1;
3694 submit_info.pWaitSemaphores = &semaphore;
3695 submit_info.pWaitDstStageMask = flags;
3696 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3697 }
3698
3699 vkQueueWaitIdle(m_device->m_queue);
3700
3701 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3702 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3703 &command_buffer[0]);
3704 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3705
3706 m_errorMonitor->VerifyNotFound();
3707}
3708
3709// This is a positive test. No errors should be generated.
3710TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
3711
3712 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3713 "submitted on separate queues, the second having a fence"
3714 "followed by a QueueWaitIdle.");
3715
Dustin Graves48458142016-04-29 16:11:55 -06003716 if ((m_device->queue_props.empty()) ||
3717 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003718 return;
3719
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003720 m_errorMonitor->ExpectSuccess();
3721
3722 VkFence fence;
3723 VkFenceCreateInfo fence_create_info{};
3724 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3725 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3726
3727 VkSemaphore semaphore;
3728 VkSemaphoreCreateInfo semaphore_create_info{};
3729 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3730 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3731 &semaphore);
3732
3733 VkCommandPool command_pool;
3734 VkCommandPoolCreateInfo pool_create_info{};
3735 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3736 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3737 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3738 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3739 &command_pool);
3740
3741 VkCommandBuffer command_buffer[2];
3742 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3743 command_buffer_allocate_info.sType =
3744 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3745 command_buffer_allocate_info.commandPool = command_pool;
3746 command_buffer_allocate_info.commandBufferCount = 2;
3747 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3748 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3749 command_buffer);
3750
3751 VkQueue queue = VK_NULL_HANDLE;
3752 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3753 1, &queue);
3754
3755 {
3756 VkCommandBufferBeginInfo begin_info{};
3757 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3758 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3759
3760 vkCmdPipelineBarrier(command_buffer[0],
3761 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3762 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3763 0, nullptr, 0, nullptr);
3764
3765 VkViewport viewport{};
3766 viewport.maxDepth = 1.0f;
3767 viewport.minDepth = 0.0f;
3768 viewport.width = 512;
3769 viewport.height = 512;
3770 viewport.x = 0;
3771 viewport.y = 0;
3772 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3773 vkEndCommandBuffer(command_buffer[0]);
3774 }
3775 {
3776 VkCommandBufferBeginInfo begin_info{};
3777 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3778 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3779
3780 VkViewport viewport{};
3781 viewport.maxDepth = 1.0f;
3782 viewport.minDepth = 0.0f;
3783 viewport.width = 512;
3784 viewport.height = 512;
3785 viewport.x = 0;
3786 viewport.y = 0;
3787 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3788 vkEndCommandBuffer(command_buffer[1]);
3789 }
3790 {
3791 VkSubmitInfo submit_info{};
3792 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3793 submit_info.commandBufferCount = 1;
3794 submit_info.pCommandBuffers = &command_buffer[0];
3795 submit_info.signalSemaphoreCount = 1;
3796 submit_info.pSignalSemaphores = &semaphore;
3797 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3798 }
3799 {
3800 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3801 VkSubmitInfo submit_info{};
3802 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3803 submit_info.commandBufferCount = 1;
3804 submit_info.pCommandBuffers = &command_buffer[1];
3805 submit_info.waitSemaphoreCount = 1;
3806 submit_info.pWaitSemaphores = &semaphore;
3807 submit_info.pWaitDstStageMask = flags;
3808 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3809 }
3810
3811 vkQueueWaitIdle(m_device->m_queue);
3812
3813 vkDestroyFence(m_device->device(), fence, nullptr);
3814 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3815 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3816 &command_buffer[0]);
3817 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3818
3819 m_errorMonitor->VerifyNotFound();
3820}
3821
3822// This is a positive test. No errors should be generated.
3823TEST_F(VkLayerTest,
3824 TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
3825
3826 TEST_DESCRIPTION(
3827 "Two command buffers, each in a separate QueueSubmit call "
3828 "submitted on separate queues, the second having a fence"
3829 "followed by two consecutive WaitForFences calls on the same fence.");
3830
Dustin Graves48458142016-04-29 16:11:55 -06003831 if ((m_device->queue_props.empty()) ||
3832 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003833 return;
3834
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003835 m_errorMonitor->ExpectSuccess();
3836
3837 VkFence fence;
3838 VkFenceCreateInfo fence_create_info{};
3839 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3840 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3841
3842 VkSemaphore semaphore;
3843 VkSemaphoreCreateInfo semaphore_create_info{};
3844 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3845 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3846 &semaphore);
3847
3848 VkCommandPool command_pool;
3849 VkCommandPoolCreateInfo pool_create_info{};
3850 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3851 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3852 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3853 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3854 &command_pool);
3855
3856 VkCommandBuffer command_buffer[2];
3857 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3858 command_buffer_allocate_info.sType =
3859 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3860 command_buffer_allocate_info.commandPool = command_pool;
3861 command_buffer_allocate_info.commandBufferCount = 2;
3862 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3863 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3864 command_buffer);
3865
3866 VkQueue queue = VK_NULL_HANDLE;
3867 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3868 1, &queue);
3869
3870 {
3871 VkCommandBufferBeginInfo begin_info{};
3872 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3873 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3874
3875 vkCmdPipelineBarrier(command_buffer[0],
3876 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3877 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3878 0, nullptr, 0, nullptr);
3879
3880 VkViewport viewport{};
3881 viewport.maxDepth = 1.0f;
3882 viewport.minDepth = 0.0f;
3883 viewport.width = 512;
3884 viewport.height = 512;
3885 viewport.x = 0;
3886 viewport.y = 0;
3887 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3888 vkEndCommandBuffer(command_buffer[0]);
3889 }
3890 {
3891 VkCommandBufferBeginInfo begin_info{};
3892 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3893 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3894
3895 VkViewport viewport{};
3896 viewport.maxDepth = 1.0f;
3897 viewport.minDepth = 0.0f;
3898 viewport.width = 512;
3899 viewport.height = 512;
3900 viewport.x = 0;
3901 viewport.y = 0;
3902 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3903 vkEndCommandBuffer(command_buffer[1]);
3904 }
3905 {
3906 VkSubmitInfo submit_info{};
3907 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3908 submit_info.commandBufferCount = 1;
3909 submit_info.pCommandBuffers = &command_buffer[0];
3910 submit_info.signalSemaphoreCount = 1;
3911 submit_info.pSignalSemaphores = &semaphore;
3912 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3913 }
3914 {
3915 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3916 VkSubmitInfo submit_info{};
3917 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3918 submit_info.commandBufferCount = 1;
3919 submit_info.pCommandBuffers = &command_buffer[1];
3920 submit_info.waitSemaphoreCount = 1;
3921 submit_info.pWaitSemaphores = &semaphore;
3922 submit_info.pWaitDstStageMask = flags;
3923 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3924 }
3925
3926 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3927 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3928
3929 vkDestroyFence(m_device->device(), fence, nullptr);
3930 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3931 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3932 &command_buffer[0]);
3933 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3934
3935 m_errorMonitor->VerifyNotFound();
3936}
3937
3938// This is a positive test. No errors should be generated.
3939TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
3940
3941 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3942 "submitted on separate queues, the second having a fence, "
3943 "followed by a WaitForFences call.");
3944
Dustin Graves48458142016-04-29 16:11:55 -06003945 if ((m_device->queue_props.empty()) ||
3946 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003947 return;
3948
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003949 m_errorMonitor->ExpectSuccess();
3950
3951 VkFence fence;
3952 VkFenceCreateInfo fence_create_info{};
3953 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3954 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3955
3956 VkSemaphore semaphore;
3957 VkSemaphoreCreateInfo semaphore_create_info{};
3958 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3959 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3960 &semaphore);
3961
3962 VkCommandPool command_pool;
3963 VkCommandPoolCreateInfo pool_create_info{};
3964 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3965 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3966 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3967 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3968 &command_pool);
3969
3970 VkCommandBuffer command_buffer[2];
3971 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3972 command_buffer_allocate_info.sType =
3973 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3974 command_buffer_allocate_info.commandPool = command_pool;
3975 command_buffer_allocate_info.commandBufferCount = 2;
3976 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3977 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3978 command_buffer);
3979
3980 VkQueue queue = VK_NULL_HANDLE;
3981 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3982 1, &queue);
3983
3984
3985 {
3986 VkCommandBufferBeginInfo begin_info{};
3987 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3988 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3989
3990 vkCmdPipelineBarrier(command_buffer[0],
3991 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3992 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3993 0, nullptr, 0, nullptr);
3994
3995 VkViewport viewport{};
3996 viewport.maxDepth = 1.0f;
3997 viewport.minDepth = 0.0f;
3998 viewport.width = 512;
3999 viewport.height = 512;
4000 viewport.x = 0;
4001 viewport.y = 0;
4002 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4003 vkEndCommandBuffer(command_buffer[0]);
4004 }
4005 {
4006 VkCommandBufferBeginInfo begin_info{};
4007 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4008 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4009
4010 VkViewport viewport{};
4011 viewport.maxDepth = 1.0f;
4012 viewport.minDepth = 0.0f;
4013 viewport.width = 512;
4014 viewport.height = 512;
4015 viewport.x = 0;
4016 viewport.y = 0;
4017 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4018 vkEndCommandBuffer(command_buffer[1]);
4019 }
4020 {
4021 VkSubmitInfo submit_info{};
4022 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4023 submit_info.commandBufferCount = 1;
4024 submit_info.pCommandBuffers = &command_buffer[0];
4025 submit_info.signalSemaphoreCount = 1;
4026 submit_info.pSignalSemaphores = &semaphore;
4027 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
4028 }
4029 {
4030 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4031 VkSubmitInfo submit_info{};
4032 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4033 submit_info.commandBufferCount = 1;
4034 submit_info.pCommandBuffers = &command_buffer[1];
4035 submit_info.waitSemaphoreCount = 1;
4036 submit_info.pWaitSemaphores = &semaphore;
4037 submit_info.pWaitDstStageMask = flags;
4038 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4039 }
4040
4041 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4042
4043 vkDestroyFence(m_device->device(), fence, nullptr);
4044 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
4045 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4046 &command_buffer[0]);
4047 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4048
4049 m_errorMonitor->VerifyNotFound();
4050}
4051
4052// This is a positive test. No errors should be generated.
4053TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
4054
4055 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
4056 "on the same queue, sharing a signal/wait semaphore, the "
4057 "second having a fence, "
4058 "followed by a WaitForFences call.");
4059
4060 m_errorMonitor->ExpectSuccess();
4061
4062 VkFence fence;
4063 VkFenceCreateInfo fence_create_info{};
4064 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4065 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4066
4067 VkSemaphore semaphore;
4068 VkSemaphoreCreateInfo semaphore_create_info{};
4069 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
4070 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
4071 &semaphore);
4072
4073 VkCommandPool command_pool;
4074 VkCommandPoolCreateInfo pool_create_info{};
4075 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4076 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4077 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4078 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4079 &command_pool);
4080
4081 VkCommandBuffer command_buffer[2];
4082 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4083 command_buffer_allocate_info.sType =
4084 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4085 command_buffer_allocate_info.commandPool = command_pool;
4086 command_buffer_allocate_info.commandBufferCount = 2;
4087 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4088 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4089 command_buffer);
4090
4091 {
4092 VkCommandBufferBeginInfo begin_info{};
4093 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4094 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4095
4096 vkCmdPipelineBarrier(command_buffer[0],
4097 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4098 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4099 0, nullptr, 0, nullptr);
4100
4101 VkViewport viewport{};
4102 viewport.maxDepth = 1.0f;
4103 viewport.minDepth = 0.0f;
4104 viewport.width = 512;
4105 viewport.height = 512;
4106 viewport.x = 0;
4107 viewport.y = 0;
4108 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4109 vkEndCommandBuffer(command_buffer[0]);
4110 }
4111 {
4112 VkCommandBufferBeginInfo begin_info{};
4113 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4114 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4115
4116 VkViewport viewport{};
4117 viewport.maxDepth = 1.0f;
4118 viewport.minDepth = 0.0f;
4119 viewport.width = 512;
4120 viewport.height = 512;
4121 viewport.x = 0;
4122 viewport.y = 0;
4123 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4124 vkEndCommandBuffer(command_buffer[1]);
4125 }
4126 {
4127 VkSubmitInfo submit_info{};
4128 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4129 submit_info.commandBufferCount = 1;
4130 submit_info.pCommandBuffers = &command_buffer[0];
4131 submit_info.signalSemaphoreCount = 1;
4132 submit_info.pSignalSemaphores = &semaphore;
4133 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4134 }
4135 {
4136 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4137 VkSubmitInfo submit_info{};
4138 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4139 submit_info.commandBufferCount = 1;
4140 submit_info.pCommandBuffers = &command_buffer[1];
4141 submit_info.waitSemaphoreCount = 1;
4142 submit_info.pWaitSemaphores = &semaphore;
4143 submit_info.pWaitDstStageMask = flags;
4144 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4145 }
4146
4147 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4148
4149 vkDestroyFence(m_device->device(), fence, nullptr);
4150 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
4151 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4152 &command_buffer[0]);
4153 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4154
4155 m_errorMonitor->VerifyNotFound();
4156}
4157
4158// This is a positive test. No errors should be generated.
4159TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
4160
4161 TEST_DESCRIPTION(
4162 "Two command buffers, each in a separate QueueSubmit call "
4163 "on the same queue, no fences, followed by a third QueueSubmit with NO "
4164 "SubmitInfos but with a fence, followed by a WaitForFences call.");
4165
4166 m_errorMonitor->ExpectSuccess();
4167
4168 VkFence fence;
4169 VkFenceCreateInfo fence_create_info{};
4170 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4171 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4172
4173 VkCommandPool command_pool;
4174 VkCommandPoolCreateInfo pool_create_info{};
4175 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4176 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4177 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4178 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4179 &command_pool);
4180
4181 VkCommandBuffer command_buffer[2];
4182 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4183 command_buffer_allocate_info.sType =
4184 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4185 command_buffer_allocate_info.commandPool = command_pool;
4186 command_buffer_allocate_info.commandBufferCount = 2;
4187 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4188 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4189 command_buffer);
4190
4191 {
4192 VkCommandBufferBeginInfo begin_info{};
4193 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4194 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4195
4196 vkCmdPipelineBarrier(command_buffer[0],
4197 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4198 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4199 0, nullptr, 0, nullptr);
4200
4201 VkViewport viewport{};
4202 viewport.maxDepth = 1.0f;
4203 viewport.minDepth = 0.0f;
4204 viewport.width = 512;
4205 viewport.height = 512;
4206 viewport.x = 0;
4207 viewport.y = 0;
4208 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4209 vkEndCommandBuffer(command_buffer[0]);
4210 }
4211 {
4212 VkCommandBufferBeginInfo begin_info{};
4213 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4214 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4215
4216 VkViewport viewport{};
4217 viewport.maxDepth = 1.0f;
4218 viewport.minDepth = 0.0f;
4219 viewport.width = 512;
4220 viewport.height = 512;
4221 viewport.x = 0;
4222 viewport.y = 0;
4223 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4224 vkEndCommandBuffer(command_buffer[1]);
4225 }
4226 {
4227 VkSubmitInfo submit_info{};
4228 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4229 submit_info.commandBufferCount = 1;
4230 submit_info.pCommandBuffers = &command_buffer[0];
4231 submit_info.signalSemaphoreCount = 0;
4232 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
4233 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4234 }
4235 {
4236 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4237 VkSubmitInfo submit_info{};
4238 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4239 submit_info.commandBufferCount = 1;
4240 submit_info.pCommandBuffers = &command_buffer[1];
4241 submit_info.waitSemaphoreCount = 0;
4242 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
4243 submit_info.pWaitDstStageMask = flags;
4244 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4245 }
4246
4247 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
4248
4249 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4250
4251 vkDestroyFence(m_device->device(), fence, nullptr);
4252 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4253 &command_buffer[0]);
4254 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4255
4256 m_errorMonitor->VerifyNotFound();
4257}
4258
4259// This is a positive test. No errors should be generated.
4260TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
4261
4262 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
4263 "on the same queue, the second having a fence, followed "
4264 "by a WaitForFences call.");
4265
4266 m_errorMonitor->ExpectSuccess();
4267
4268 VkFence fence;
4269 VkFenceCreateInfo fence_create_info{};
4270 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4271 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4272
4273 VkCommandPool command_pool;
4274 VkCommandPoolCreateInfo pool_create_info{};
4275 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4276 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4277 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4278 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4279 &command_pool);
4280
4281 VkCommandBuffer command_buffer[2];
4282 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4283 command_buffer_allocate_info.sType =
4284 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4285 command_buffer_allocate_info.commandPool = command_pool;
4286 command_buffer_allocate_info.commandBufferCount = 2;
4287 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4288 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4289 command_buffer);
4290
4291 {
4292 VkCommandBufferBeginInfo begin_info{};
4293 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4294 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4295
4296 vkCmdPipelineBarrier(command_buffer[0],
4297 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4298 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4299 0, nullptr, 0, nullptr);
4300
4301 VkViewport viewport{};
4302 viewport.maxDepth = 1.0f;
4303 viewport.minDepth = 0.0f;
4304 viewport.width = 512;
4305 viewport.height = 512;
4306 viewport.x = 0;
4307 viewport.y = 0;
4308 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4309 vkEndCommandBuffer(command_buffer[0]);
4310 }
4311 {
4312 VkCommandBufferBeginInfo begin_info{};
4313 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4314 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4315
4316 VkViewport viewport{};
4317 viewport.maxDepth = 1.0f;
4318 viewport.minDepth = 0.0f;
4319 viewport.width = 512;
4320 viewport.height = 512;
4321 viewport.x = 0;
4322 viewport.y = 0;
4323 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4324 vkEndCommandBuffer(command_buffer[1]);
4325 }
4326 {
4327 VkSubmitInfo submit_info{};
4328 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4329 submit_info.commandBufferCount = 1;
4330 submit_info.pCommandBuffers = &command_buffer[0];
4331 submit_info.signalSemaphoreCount = 0;
4332 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
4333 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4334 }
4335 {
4336 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4337 VkSubmitInfo submit_info{};
4338 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4339 submit_info.commandBufferCount = 1;
4340 submit_info.pCommandBuffers = &command_buffer[1];
4341 submit_info.waitSemaphoreCount = 0;
4342 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
4343 submit_info.pWaitDstStageMask = flags;
4344 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4345 }
4346
4347 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4348
4349 vkDestroyFence(m_device->device(), fence, nullptr);
4350 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4351 &command_buffer[0]);
4352 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4353
4354 m_errorMonitor->VerifyNotFound();
4355}
4356
4357// This is a positive test. No errors should be generated.
4358TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
4359
4360 TEST_DESCRIPTION(
4361 "Two command buffers each in a separate SubmitInfo sent in a single "
4362 "QueueSubmit call followed by a WaitForFences call.");
4363
4364 m_errorMonitor->ExpectSuccess();
4365
4366 VkFence fence;
4367 VkFenceCreateInfo fence_create_info{};
4368 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4369 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4370
4371 VkSemaphore semaphore;
4372 VkSemaphoreCreateInfo semaphore_create_info{};
4373 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
4374 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
4375 &semaphore);
4376
4377 VkCommandPool command_pool;
4378 VkCommandPoolCreateInfo pool_create_info{};
4379 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4380 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4381 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4382 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4383 &command_pool);
4384
4385 VkCommandBuffer command_buffer[2];
4386 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4387 command_buffer_allocate_info.sType =
4388 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4389 command_buffer_allocate_info.commandPool = command_pool;
4390 command_buffer_allocate_info.commandBufferCount = 2;
4391 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4392 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4393 command_buffer);
4394
4395 {
4396 VkCommandBufferBeginInfo begin_info{};
4397 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4398 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4399
4400 vkCmdPipelineBarrier(command_buffer[0],
4401 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4402 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4403 0, nullptr, 0, nullptr);
4404
4405 VkViewport viewport{};
4406 viewport.maxDepth = 1.0f;
4407 viewport.minDepth = 0.0f;
4408 viewport.width = 512;
4409 viewport.height = 512;
4410 viewport.x = 0;
4411 viewport.y = 0;
4412 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4413 vkEndCommandBuffer(command_buffer[0]);
4414 }
4415 {
4416 VkCommandBufferBeginInfo begin_info{};
4417 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4418 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4419
4420 VkViewport viewport{};
4421 viewport.maxDepth = 1.0f;
4422 viewport.minDepth = 0.0f;
4423 viewport.width = 512;
4424 viewport.height = 512;
4425 viewport.x = 0;
4426 viewport.y = 0;
4427 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4428 vkEndCommandBuffer(command_buffer[1]);
4429 }
4430 {
4431 VkSubmitInfo submit_info[2];
4432 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4433
4434 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4435 submit_info[0].pNext = NULL;
4436 submit_info[0].commandBufferCount = 1;
4437 submit_info[0].pCommandBuffers = &command_buffer[0];
4438 submit_info[0].signalSemaphoreCount = 1;
4439 submit_info[0].pSignalSemaphores = &semaphore;
4440 submit_info[0].waitSemaphoreCount = 0;
4441 submit_info[0].pWaitSemaphores = NULL;
4442 submit_info[0].pWaitDstStageMask = 0;
4443
4444 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4445 submit_info[1].pNext = NULL;
4446 submit_info[1].commandBufferCount = 1;
4447 submit_info[1].pCommandBuffers = &command_buffer[1];
4448 submit_info[1].waitSemaphoreCount = 1;
4449 submit_info[1].pWaitSemaphores = &semaphore;
4450 submit_info[1].pWaitDstStageMask = flags;
4451 submit_info[1].signalSemaphoreCount = 0;
4452 submit_info[1].pSignalSemaphores = NULL;
4453 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
4454 }
4455
4456 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4457
4458 vkDestroyFence(m_device->device(), fence, nullptr);
4459 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4460 &command_buffer[0]);
4461 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06004462 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06004463
4464 m_errorMonitor->VerifyNotFound();
4465}
4466
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004467TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004468 TEST_DESCRIPTION(
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004469 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4470 "state is required but not correctly bound.");
4471
4472 // Dynamic depth bias
4473 m_errorMonitor->SetDesiredFailureMsg(
4474 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4475 "Dynamic depth bias state not set for this command buffer");
4476 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4477 BsoFailDepthBias);
4478 m_errorMonitor->VerifyFound();
4479}
4480
4481TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
4482 TEST_DESCRIPTION(
4483 "Run a simple draw calls to validate failure when Line Width dynamic "
4484 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004485
4486 // Dynamic line width
Karl Schultz6addd812016-02-02 17:17:23 -07004487 m_errorMonitor->SetDesiredFailureMsg(
4488 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004489 "Dynamic line width state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004490 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4491 BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004492 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004493}
4494
4495TEST_F(VkLayerTest, DynamicViewportNotBound) {
4496 TEST_DESCRIPTION(
4497 "Run a simple draw calls to validate failure when Viewport dynamic "
4498 "state is required but not correctly bound.");
4499
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004500 // Dynamic viewport state
Karl Schultz6addd812016-02-02 17:17:23 -07004501 m_errorMonitor->SetDesiredFailureMsg(
4502 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004503 "Dynamic viewport state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004504 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4505 BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004506 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004507}
4508
4509TEST_F(VkLayerTest, DynamicScissorNotBound) {
4510 TEST_DESCRIPTION(
4511 "Run a simple draw calls to validate failure when Scissor dynamic "
4512 "state is required but not correctly bound.");
4513
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004514 // Dynamic scissor state
Karl Schultz6addd812016-02-02 17:17:23 -07004515 m_errorMonitor->SetDesiredFailureMsg(
4516 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004517 "Dynamic scissor state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004518 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4519 BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004520 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004521}
4522
Tobin Ehlis21c88352016-05-26 06:15:45 -06004523TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) {
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004524 TEST_DESCRIPTION(
Tobin Ehlis21c88352016-05-26 06:15:45 -06004525 "Run a simple draw calls to validate failure when Blend Constants "
4526 "dynamic state is required but not correctly bound.");
4527 // Dynamic blend constant state
4528 m_errorMonitor->SetDesiredFailureMsg(
4529 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4530 "Dynamic blend constants state not set for this command buffer");
4531 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4532 BsoFailBlend);
4533 m_errorMonitor->VerifyFound();
4534}
4535
4536TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
4537 TEST_DESCRIPTION(
4538 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004539 "state is required but not correctly bound.");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004540 if (!m_device->phy().features().depthBounds) {
4541 printf("Device does not support depthBounds test; skipped.\n");
4542 return;
4543 }
4544 // Dynamic depth bounds
Karl Schultz6addd812016-02-02 17:17:23 -07004545 m_errorMonitor->SetDesiredFailureMsg(
4546 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004547 "Dynamic depth bounds state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004548 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4549 BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004550 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004551}
4552
4553TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
4554 TEST_DESCRIPTION(
4555 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4556 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004557 // Dynamic stencil read mask
Karl Schultz6addd812016-02-02 17:17:23 -07004558 m_errorMonitor->SetDesiredFailureMsg(
4559 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004560 "Dynamic stencil read mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004561 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4562 BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004563 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004564}
4565
4566TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
4567 TEST_DESCRIPTION(
4568 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4569 " state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004570 // Dynamic stencil write mask
Karl Schultz6addd812016-02-02 17:17:23 -07004571 m_errorMonitor->SetDesiredFailureMsg(
4572 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004573 "Dynamic stencil write mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004574 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4575 BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004576 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004577}
4578
4579TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
4580 TEST_DESCRIPTION(
4581 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4582 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004583 // Dynamic stencil reference
Karl Schultz6addd812016-02-02 17:17:23 -07004584 m_errorMonitor->SetDesiredFailureMsg(
4585 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004586 "Dynamic stencil reference state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004587 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4588 BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004589 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004590}
4591
Karl Schultz6addd812016-02-02 17:17:23 -07004592TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Karl Schultz6addd812016-02-02 17:17:23 -07004593 m_errorMonitor->SetDesiredFailureMsg(
4594 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4595 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4596 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004597
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004598 ASSERT_NO_FATAL_FAILURE(InitState());
4599 ASSERT_NO_FATAL_FAILURE(InitViewport());
4600 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4601
Karl Schultz6addd812016-02-02 17:17:23 -07004602 // We luck out b/c by default the framework creates CB w/ the
4603 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004604 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004605 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
4606 m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004607 EndCommandBuffer();
4608
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004609 // Bypass framework since it does the waits automatically
4610 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004611 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004612 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4613 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004614 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004615 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004616 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004617 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004618 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004619 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004620 submit_info.pSignalSemaphores = NULL;
4621
Chris Forbes40028e22016-06-13 09:59:34 +12004622 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004623 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004624
Karl Schultz6addd812016-02-02 17:17:23 -07004625 // Cause validation error by re-submitting cmd buffer that should only be
4626 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004627 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004628
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004629 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004630}
4631
Karl Schultz6addd812016-02-02 17:17:23 -07004632TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004633 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07004634 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004635
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004637 "Unable to allocate 1 descriptors of "
4638 "type "
4639 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004640
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004641 ASSERT_NO_FATAL_FAILURE(InitState());
4642 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004643
Karl Schultz6addd812016-02-02 17:17:23 -07004644 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4645 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004646 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004647 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
4648 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004649
4650 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004651 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4652 ds_pool_ci.pNext = NULL;
4653 ds_pool_ci.flags = 0;
4654 ds_pool_ci.maxSets = 1;
4655 ds_pool_ci.poolSizeCount = 1;
4656 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004657
4658 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004659 err =
4660 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004661 ASSERT_VK_SUCCESS(err);
4662
4663 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004664 dsl_binding.binding = 0;
4665 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4666 dsl_binding.descriptorCount = 1;
4667 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4668 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004669
4670 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004671 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4672 ds_layout_ci.pNext = NULL;
4673 ds_layout_ci.bindingCount = 1;
4674 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004675
4676 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004677 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4678 &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004679 ASSERT_VK_SUCCESS(err);
4680
4681 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004682 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004683 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004684 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004685 alloc_info.descriptorPool = ds_pool;
4686 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004687 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4688 &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004689
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004690 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004691
Chia-I Wuf7458c52015-10-26 21:10:41 +08004692 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4693 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004694}
4695
Karl Schultz6addd812016-02-02 17:17:23 -07004696TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4697 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004698
Karl Schultz6addd812016-02-02 17:17:23 -07004699 m_errorMonitor->SetDesiredFailureMsg(
4700 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4701 "It is invalid to call vkFreeDescriptorSets() with a pool created "
4702 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004703
Tobin Ehlise735c692015-10-08 13:13:50 -06004704 ASSERT_NO_FATAL_FAILURE(InitState());
4705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004706
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004707 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004708 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4709 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004710
4711 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004712 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4713 ds_pool_ci.pNext = NULL;
4714 ds_pool_ci.maxSets = 1;
4715 ds_pool_ci.poolSizeCount = 1;
4716 ds_pool_ci.flags = 0;
4717 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4718 // app can only call vkResetDescriptorPool on this pool.;
4719 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004720
4721 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004722 err =
4723 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004724 ASSERT_VK_SUCCESS(err);
4725
4726 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004727 dsl_binding.binding = 0;
4728 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4729 dsl_binding.descriptorCount = 1;
4730 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4731 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004732
4733 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004734 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4735 ds_layout_ci.pNext = NULL;
4736 ds_layout_ci.bindingCount = 1;
4737 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004738
4739 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004740 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4741 &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004742 ASSERT_VK_SUCCESS(err);
4743
4744 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004745 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004746 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004747 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004748 alloc_info.descriptorPool = ds_pool;
4749 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004750 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4751 &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004752 ASSERT_VK_SUCCESS(err);
4753
4754 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004755 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004756
Chia-I Wuf7458c52015-10-26 21:10:41 +08004757 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4758 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004759}
4760
Karl Schultz6addd812016-02-02 17:17:23 -07004761TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004762 // Attempt to clear Descriptor Pool with bad object.
4763 // ObjectTracker should catch this.
4764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4765 "Invalid VkDescriptorPool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004766 uint64_t fake_pool_handle = 0xbaad6001;
4767 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4768 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004769 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004770}
4771
Karl Schultz6addd812016-02-02 17:17:23 -07004772TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004773 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4774 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004775 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004776 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004777
4778 uint64_t fake_set_handle = 0xbaad6001;
4779 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004780 VkResult err;
4781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4782 "Invalid VkDescriptorSet Object 0xbaad6001");
4783
4784 ASSERT_NO_FATAL_FAILURE(InitState());
4785
4786 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4787 layout_bindings[0].binding = 0;
4788 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4789 layout_bindings[0].descriptorCount = 1;
4790 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4791 layout_bindings[0].pImmutableSamplers = NULL;
4792
4793 VkDescriptorSetLayout descriptor_set_layout;
4794 VkDescriptorSetLayoutCreateInfo dslci = {};
4795 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4796 dslci.pNext = NULL;
4797 dslci.bindingCount = 1;
4798 dslci.pBindings = layout_bindings;
4799 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004800 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004801
4802 VkPipelineLayout pipeline_layout;
4803 VkPipelineLayoutCreateInfo plci = {};
4804 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4805 plci.pNext = NULL;
4806 plci.setLayoutCount = 1;
4807 plci.pSetLayouts = &descriptor_set_layout;
4808 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004809 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004810
4811 BeginCommandBuffer();
4812 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004813 pipeline_layout, 0, 1, &bad_set, 0, NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004814 m_errorMonitor->VerifyFound();
4815 EndCommandBuffer();
4816 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4817 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004818}
4819
Karl Schultz6addd812016-02-02 17:17:23 -07004820TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004821 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4822 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004823 uint64_t fake_layout_handle = 0xbaad6001;
4824 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4826 "Invalid VkDescriptorSetLayout Object 0xbaad6001");
4827
4828 VkPipelineLayout pipeline_layout;
4829 VkPipelineLayoutCreateInfo plci = {};
4830 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4831 plci.pNext = NULL;
4832 plci.setLayoutCount = 1;
4833 plci.pSetLayouts = &bad_layout;
4834 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4835
4836 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004837}
4838
Mark Muellerd4914412016-06-13 17:52:06 -06004839TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
4840 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4841 "1) A uniform buffer update must have a valid buffer index."
4842 "2) When using an array of descriptors in a single WriteDescriptor,"
4843 " the descriptor types and stageflags must all be the same."
4844 "3) Immutable Sampler state must match across descriptors");
4845
4846 const char *invalid_BufferInfo_ErrorMessage =
4847 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
4848 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
4849 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
4850 const char *stateFlag_ErrorMessage =
Mark Mueller5c838ce2016-06-16 09:54:29 -06004851 "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06004852 const char *immutable_ErrorMessage =
Mark Mueller5c838ce2016-06-16 09:54:29 -06004853 "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06004854
Mark Muellerd4914412016-06-13 17:52:06 -06004855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
4856
4857 ASSERT_NO_FATAL_FAILURE(InitState());
4858 VkDescriptorPoolSize ds_type_count[4] = {};
4859 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4860 ds_type_count[0].descriptorCount = 1;
4861 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4862 ds_type_count[1].descriptorCount = 1;
4863 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4864 ds_type_count[2].descriptorCount = 1;
4865 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4866 ds_type_count[3].descriptorCount = 1;
4867
4868 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4869 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4870 ds_pool_ci.maxSets = 1;
4871 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4872 ds_pool_ci.pPoolSizes = ds_type_count;
4873
4874 VkDescriptorPool ds_pool;
4875 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4876 ASSERT_VK_SUCCESS(err);
4877
Mark Muellerb9896722016-06-16 09:54:29 -06004878 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004879 layout_binding[0].binding = 0;
4880 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4881 layout_binding[0].descriptorCount = 1;
4882 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4883 layout_binding[0].pImmutableSamplers = NULL;
4884
4885 layout_binding[1].binding = 1;
4886 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4887 layout_binding[1].descriptorCount = 1;
4888 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4889 layout_binding[1].pImmutableSamplers = NULL;
4890
4891 VkSamplerCreateInfo sampler_ci = {};
4892 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4893 sampler_ci.pNext = NULL;
4894 sampler_ci.magFilter = VK_FILTER_NEAREST;
4895 sampler_ci.minFilter = VK_FILTER_NEAREST;
4896 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4897 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4898 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4899 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4900 sampler_ci.mipLodBias = 1.0;
4901 sampler_ci.anisotropyEnable = VK_FALSE;
4902 sampler_ci.maxAnisotropy = 1;
4903 sampler_ci.compareEnable = VK_FALSE;
4904 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4905 sampler_ci.minLod = 1.0;
4906 sampler_ci.maxLod = 1.0;
4907 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4908 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4909 VkSampler sampler;
4910
4911 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4912 ASSERT_VK_SUCCESS(err);
4913
4914 layout_binding[2].binding = 2;
4915 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4916 layout_binding[2].descriptorCount = 1;
4917 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4918 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4919
Mark Muellerd4914412016-06-13 17:52:06 -06004920 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4921 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4922 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4923 ds_layout_ci.pBindings = layout_binding;
4924 VkDescriptorSetLayout ds_layout;
4925 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4926 ASSERT_VK_SUCCESS(err);
4927
4928 VkDescriptorSetAllocateInfo alloc_info = {};
4929 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4930 alloc_info.descriptorSetCount = 1;
4931 alloc_info.descriptorPool = ds_pool;
4932 alloc_info.pSetLayouts = &ds_layout;
4933 VkDescriptorSet descriptorSet;
4934 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4935 ASSERT_VK_SUCCESS(err);
4936
4937 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4938 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4939 pipeline_layout_ci.pNext = NULL;
4940 pipeline_layout_ci.setLayoutCount = 1;
4941 pipeline_layout_ci.pSetLayouts = &ds_layout;
4942
4943 VkPipelineLayout pipeline_layout;
4944 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4945 ASSERT_VK_SUCCESS(err);
4946
Mark Mueller5c838ce2016-06-16 09:54:29 -06004947 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004948 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4949 descriptor_write.dstSet = descriptorSet;
4950 descriptor_write.dstBinding = 0;
4951 descriptor_write.descriptorCount = 1;
4952 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4953
Mark Mueller5c838ce2016-06-16 09:54:29 -06004954 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004955 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4956 m_errorMonitor->VerifyFound();
4957
4958 // Create a buffer to update the descriptor with
4959 uint32_t qfi = 0;
4960 VkBufferCreateInfo buffCI = {};
4961 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4962 buffCI.size = 1024;
4963 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4964 buffCI.queueFamilyIndexCount = 1;
4965 buffCI.pQueueFamilyIndices = &qfi;
4966
4967 VkBuffer dyub;
4968 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4969 ASSERT_VK_SUCCESS(err);
4970 VkDescriptorBufferInfo buffInfo = {};
4971 buffInfo.buffer = dyub;
4972 buffInfo.offset = 0;
4973 buffInfo.range = 1024;
4974
4975 descriptor_write.pBufferInfo = &buffInfo;
4976 descriptor_write.descriptorCount = 2;
4977
Mark Mueller5c838ce2016-06-16 09:54:29 -06004978 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4980 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4981 m_errorMonitor->VerifyFound();
4982
Mark Mueller5c838ce2016-06-16 09:54:29 -06004983 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4984 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004985 descriptor_write.dstBinding = 1;
4986 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004987
4988
4989 // Make pImageInfo index non-null to avoid complaints of it missing
4990 VkDescriptorImageInfo imageInfo = {};
4991 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4992 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4994 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4995 m_errorMonitor->VerifyFound();
4996
Mark Muellerd4914412016-06-13 17:52:06 -06004997 vkDestroyBuffer(m_device->device(), dyub, NULL);
4998 vkDestroySampler(m_device->device(), sampler, NULL);
4999 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5000 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5001 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5002}
5003
Karl Schultz6addd812016-02-02 17:17:23 -07005004TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005005 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5006 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005007 // Create a valid cmd buffer
5008 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005009 uint64_t fake_pipeline_handle = 0xbaad6001;
5010 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5012 "Invalid VkPipeline Object 0xbaad6001");
5013 ASSERT_NO_FATAL_FAILURE(InitState());
5014 BeginCommandBuffer();
5015 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5016 VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
5017 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005018 // Now issue a draw call with no pipeline bound
5019 m_errorMonitor->SetDesiredFailureMsg(
5020 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5021 "At Draw/Dispatch time no valid VkPipeline is bound!");
Tony Barbourdf4c0042016-06-01 15:55:43 -06005022
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005023 BeginCommandBuffer();
5024 Draw(1, 0, 0, 0);
5025 m_errorMonitor->VerifyFound();
5026 // Finally same check once more but with Dispatch/Compute
5027 m_errorMonitor->SetDesiredFailureMsg(
5028 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5029 "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005030 BeginCommandBuffer();
5031 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5032 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005033}
5034
Karl Schultz6addd812016-02-02 17:17:23 -07005035TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
5036 // Create and update CommandBuffer then call QueueSubmit w/o calling End on
5037 // CommandBuffer
5038 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005039
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07005040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005041 " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005042
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005043 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005044 ASSERT_NO_FATAL_FAILURE(InitViewport());
5045 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005046 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005047 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5048 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005049
5050 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005051 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5052 ds_pool_ci.pNext = NULL;
5053 ds_pool_ci.maxSets = 1;
5054 ds_pool_ci.poolSizeCount = 1;
5055 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005056
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005057 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005058 err =
5059 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005060 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005061
Tony Barboureb254902015-07-15 12:50:33 -06005062 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005063 dsl_binding.binding = 0;
5064 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5065 dsl_binding.descriptorCount = 1;
5066 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5067 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005068
Tony Barboureb254902015-07-15 12:50:33 -06005069 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005070 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5071 ds_layout_ci.pNext = NULL;
5072 ds_layout_ci.bindingCount = 1;
5073 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005074 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005075 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5076 &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005077 ASSERT_VK_SUCCESS(err);
5078
5079 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005080 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005081 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005082 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005083 alloc_info.descriptorPool = ds_pool;
5084 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005085 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5086 &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005087 ASSERT_VK_SUCCESS(err);
5088
Tony Barboureb254902015-07-15 12:50:33 -06005089 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005090 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5091 pipeline_layout_ci.pNext = NULL;
5092 pipeline_layout_ci.setLayoutCount = 1;
5093 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005094
5095 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005096 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5097 &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005098 ASSERT_VK_SUCCESS(err);
5099
Karl Schultz6addd812016-02-02 17:17:23 -07005100 VkShaderObj vs(m_device, bindStateVertShaderText,
5101 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005102 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005103 // on more devices
5104 VkShaderObj fs(m_device, bindStateFragShaderText,
5105 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005106
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005107 VkPipelineObj pipe(m_device);
5108 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005109 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005110 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005111 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005112
5113 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005114 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5115 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5116 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5117 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5118 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005119
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005120 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005121
Chia-I Wuf7458c52015-10-26 21:10:41 +08005122 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5123 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5124 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005125}
5126
Karl Schultz6addd812016-02-02 17:17:23 -07005127TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005128 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005129 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005130
Karl Schultz6addd812016-02-02 17:17:23 -07005131 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005132 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5133 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005134
5135 ASSERT_NO_FATAL_FAILURE(InitState());
5136 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005137 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5138 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005139
5140 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005141 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5142 ds_pool_ci.pNext = NULL;
5143 ds_pool_ci.maxSets = 1;
5144 ds_pool_ci.poolSizeCount = 1;
5145 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005146
5147 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005148 err =
5149 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005150 ASSERT_VK_SUCCESS(err);
5151
5152 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005153 dsl_binding.binding = 0;
5154 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5155 dsl_binding.descriptorCount = 1;
5156 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5157 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005158
5159 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005160 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5161 ds_layout_ci.pNext = NULL;
5162 ds_layout_ci.bindingCount = 1;
5163 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005164 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005165 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5166 &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005167 ASSERT_VK_SUCCESS(err);
5168
5169 VkDescriptorSet descriptorSet;
5170 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005171 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005172 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005173 alloc_info.descriptorPool = ds_pool;
5174 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005175 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5176 &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005177 ASSERT_VK_SUCCESS(err);
5178
Karl Schultz6addd812016-02-02 17:17:23 -07005179 VkBufferView view =
5180 (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005181 VkWriteDescriptorSet descriptor_write;
5182 memset(&descriptor_write, 0, sizeof(descriptor_write));
5183 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5184 descriptor_write.dstSet = descriptorSet;
5185 descriptor_write.dstBinding = 0;
5186 descriptor_write.descriptorCount = 1;
5187 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5188 descriptor_write.pTexelBufferView = &view;
5189
5190 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5191
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005192 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005193
5194 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5195 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5196}
5197
Karl Schultz6addd812016-02-02 17:17:23 -07005198TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5199 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5200 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005201 // 1. No dynamicOffset supplied
5202 // 2. Too many dynamicOffsets supplied
5203 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005204 VkResult err;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005206 " requires 1 dynamicOffsets, but only "
5207 "0 dynamicOffsets are left in "
5208 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005209
5210 ASSERT_NO_FATAL_FAILURE(InitState());
5211 ASSERT_NO_FATAL_FAILURE(InitViewport());
5212 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5213
5214 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005215 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5216 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005217
5218 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005219 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5220 ds_pool_ci.pNext = NULL;
5221 ds_pool_ci.maxSets = 1;
5222 ds_pool_ci.poolSizeCount = 1;
5223 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005224
5225 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005226 err =
5227 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005228 ASSERT_VK_SUCCESS(err);
5229
5230 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005231 dsl_binding.binding = 0;
5232 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5233 dsl_binding.descriptorCount = 1;
5234 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5235 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005236
5237 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005238 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5239 ds_layout_ci.pNext = NULL;
5240 ds_layout_ci.bindingCount = 1;
5241 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005242 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005243 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5244 &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005245 ASSERT_VK_SUCCESS(err);
5246
5247 VkDescriptorSet descriptorSet;
5248 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005249 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005250 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005251 alloc_info.descriptorPool = ds_pool;
5252 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005253 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5254 &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005255 ASSERT_VK_SUCCESS(err);
5256
5257 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005258 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5259 pipeline_layout_ci.pNext = NULL;
5260 pipeline_layout_ci.setLayoutCount = 1;
5261 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005262
5263 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005264 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5265 &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005266 ASSERT_VK_SUCCESS(err);
5267
5268 // Create a buffer to update the descriptor with
5269 uint32_t qfi = 0;
5270 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005271 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5272 buffCI.size = 1024;
5273 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5274 buffCI.queueFamilyIndexCount = 1;
5275 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005276
5277 VkBuffer dyub;
5278 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5279 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005280 // Allocate memory and bind to buffer so we can make it to the appropriate
5281 // error
5282 VkMemoryAllocateInfo mem_alloc = {};
5283 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5284 mem_alloc.pNext = NULL;
5285 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005286 mem_alloc.memoryTypeIndex = 0;
5287
5288 VkMemoryRequirements memReqs;
5289 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
5290 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc,
5291 0);
5292 if (!pass) {
5293 vkDestroyBuffer(m_device->device(), dyub, NULL);
5294 return;
5295 }
5296
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005297 VkDeviceMemory mem;
5298 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5299 ASSERT_VK_SUCCESS(err);
5300 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5301 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005302 // Correctly update descriptor to avoid "NOT_UPDATED" error
5303 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005304 buffInfo.buffer = dyub;
5305 buffInfo.offset = 0;
5306 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005307
5308 VkWriteDescriptorSet descriptor_write;
5309 memset(&descriptor_write, 0, sizeof(descriptor_write));
5310 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5311 descriptor_write.dstSet = descriptorSet;
5312 descriptor_write.dstBinding = 0;
5313 descriptor_write.descriptorCount = 1;
5314 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5315 descriptor_write.pBufferInfo = &buffInfo;
5316
5317 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5318
5319 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005320 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5321 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5322 1, &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005323 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005324 uint32_t pDynOff[2] = {512, 756};
5325 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Karl Schultz6addd812016-02-02 17:17:23 -07005326 m_errorMonitor->SetDesiredFailureMsg(
5327 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07005328 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
Karl Schultz6addd812016-02-02 17:17:23 -07005329 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5330 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5331 1, &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005332 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005333 // Finally cause error due to dynamicOffset being too big
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5335 " dynamic offset 512 combined with "
5336 "offset 0 and range 1024 that "
5337 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005338 // Create PSO to be used for draw-time errors below
5339 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005340 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005341 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005342 "out gl_PerVertex { \n"
5343 " vec4 gl_Position;\n"
5344 "};\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005345 "void main(){\n"
5346 " gl_Position = vec4(1);\n"
5347 "}\n";
5348 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005349 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005350 "\n"
5351 "layout(location=0) out vec4 x;\n"
5352 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5353 "void main(){\n"
5354 " x = vec4(bar.y);\n"
5355 "}\n";
5356 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5357 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5358 VkPipelineObj pipe(m_device);
5359 pipe.AddShader(&vs);
5360 pipe.AddShader(&fs);
5361 pipe.AddColorAttachment();
5362 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5363
Karl Schultz6addd812016-02-02 17:17:23 -07005364 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5365 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5366 // This update should succeed, but offset size of 512 will overstep buffer
5367 // /w range 1024 & size 1024
5368 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5369 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5370 1, &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005371 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005372 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005373
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005374 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005375 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005376
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005377 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005378 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005379 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5380}
5381
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005382TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005383 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005384 ASSERT_NO_FATAL_FAILURE(InitState());
5385 ASSERT_NO_FATAL_FAILURE(InitViewport());
5386 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5387
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005388 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005389 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005390 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5391 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5392 pipeline_layout_ci.pushConstantRangeCount = 1;
5393 pipeline_layout_ci.pPushConstantRanges = &pc_range;
5394
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005395 //
5396 // Check for invalid push constant ranges in pipeline layouts.
5397 //
5398 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005399 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005400 char const *msg;
5401 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005402
Karl Schultzc81037d2016-05-12 08:11:23 -06005403 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
5404 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
5405 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5406 "vkCreatePipelineLayout() call has push constants index 0 with "
5407 "size 0."},
5408 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5409 "vkCreatePipelineLayout() call has push constants index 0 with "
5410 "size 1."},
5411 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
5412 "vkCreatePipelineLayout() call has push constants index 0 with "
5413 "size 1."},
5414 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
5415 "vkCreatePipelineLayout() call has push constants index 0 with "
5416 "size 0."},
5417 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5418 "vkCreatePipelineLayout() call has push constants index 0 with "
5419 "offset 1. Offset must"},
5420 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
5421 "vkCreatePipelineLayout() call has push constants index 0 "
5422 "with offset "},
5423 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
5424 "vkCreatePipelineLayout() call has push constants "
5425 "index 0 with offset "},
5426 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
5427 "vkCreatePipelineLayout() call has push constants index 0 "
5428 "with offset "},
5429 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
5430 "vkCreatePipelineLayout() call has push "
5431 "constants index 0 with offset "},
5432 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
5433 "vkCreatePipelineLayout() call has push "
5434 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005435 }};
5436
5437 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06005438 for (const auto &iter : range_tests) {
5439 pc_range = iter.range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5441 iter.msg);
5442 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5443 NULL, &pipeline_layout);
5444 m_errorMonitor->VerifyFound();
5445 if (VK_SUCCESS == err) {
5446 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5447 }
5448 }
5449
5450 // Check for invalid stage flag
5451 pc_range.offset = 0;
5452 pc_range.size = 16;
5453 pc_range.stageFlags = 0;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005454 m_errorMonitor->SetDesiredFailureMsg(
5455 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005456 "vkCreatePipelineLayout() call has no stageFlags set.");
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005457 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5458 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005459 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005460 if (VK_SUCCESS == err) {
5461 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5462 }
5463
5464 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06005465 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005466 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005467 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005468 char const *msg;
5469 };
5470
Karl Schultzc81037d2016-05-12 08:11:23 -06005471 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005472 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5473 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5474 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5475 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5476 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5477 "vkCreatePipelineLayout() call has push constants with overlapping "
5478 "ranges: 0:[0, 4), 1:[0, 4)"},
5479 {
5480 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5481 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5482 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5483 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5484 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
5485 "vkCreatePipelineLayout() call has push constants with "
5486 "overlapping "
5487 "ranges: 3:[12, 20), 4:[16, 20)",
5488 },
5489 {
5490 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5491 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5492 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5493 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5494 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5495 "vkCreatePipelineLayout() call has push constants with "
5496 "overlapping "
5497 "ranges: 0:[16, 20), 1:[12, 20)",
5498 },
5499 {
5500 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5501 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5502 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5503 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5504 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5505 "vkCreatePipelineLayout() call has push constants with "
5506 "overlapping "
5507 "ranges: 0:[16, 20), 3:[12, 20)",
5508 },
5509 {
5510 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5511 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
5512 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
5513 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
5514 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
5515 "vkCreatePipelineLayout() call has push constants with "
5516 "overlapping "
5517 "ranges: 0:[16, 20), 2:[4, 100)",
5518 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005519
Karl Schultzc81037d2016-05-12 08:11:23 -06005520 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005521 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06005522 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
5523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005524 iter.msg);
5525 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5526 NULL, &pipeline_layout);
5527 m_errorMonitor->VerifyFound();
5528 if (VK_SUCCESS == err) {
5529 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5530 }
5531 }
5532
5533 // Run some positive tests to make sure overlap checking in the layer is OK
Karl Schultzc81037d2016-05-12 08:11:23 -06005534 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos =
5535 {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5536 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5537 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5538 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
5539 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
5540 ""},
5541 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
5542 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
5543 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
5544 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
5545 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5546 ""}}};
5547 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005548 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
5549 m_errorMonitor->ExpectSuccess();
5550 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5551 NULL, &pipeline_layout);
5552 m_errorMonitor->VerifyNotFound();
5553 if (VK_SUCCESS == err) {
5554 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5555 }
5556 }
5557
5558 //
5559 // CmdPushConstants tests
5560 //
Karl Schultzc81037d2016-05-12 08:11:23 -06005561 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005562
5563 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzc81037d2016-05-12 08:11:23 -06005564 const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{
5565 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5566 "vkCmdPushConstants() call has push constants with size 0. Size "
5567 "must be greater than zero and a multiple of 4."},
5568 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5569 "vkCmdPushConstants() call has push constants with size 1. Size "
5570 "must be greater than zero and a multiple of 4."},
5571 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
5572 "vkCmdPushConstants() call has push constants with size 1. Size "
5573 "must be greater than zero and a multiple of 4."},
5574 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
5575 "vkCmdPushConstants() call has push constants with offset 1. "
5576 "Offset must be a multiple of 4."},
5577 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5578 "vkCmdPushConstants() call has push constants with offset 1. "
5579 "Offset must be a multiple of 4."},
5580 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
5581 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
5582 "0x1 not within flag-matching ranges in pipeline layout"},
5583 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
5584 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
5585 "0x1 not within flag-matching ranges in pipeline layout"},
5586 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
5587 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
5588 "0x1 not within flag-matching ranges in pipeline layout"},
5589 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
5590 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
5591 "0x1 not within flag-matching ranges in pipeline layout"},
5592 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
5593 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
5594 "any of the ranges in pipeline layout"},
5595 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
5596 0, 16},
5597 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
5598 "any of the ranges in pipeline layout"},
5599 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005600 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005601 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005602 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005603 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005604 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005605 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005606 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005607 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005608 "vkCmdPushConstants() call has push constants with offset "},
5609 }};
5610
5611 // Two ranges for testing robustness
Karl Schultzc81037d2016-05-12 08:11:23 -06005612 const VkPushConstantRange pc_range2[] = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005613 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06005614 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005615 };
Karl Schultzc81037d2016-05-12 08:11:23 -06005616 pipeline_layout_ci.pushConstantRangeCount =
5617 sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005618 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005619 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5620 &pipeline_layout);
5621 ASSERT_VK_SUCCESS(err);
5622 BeginCommandBuffer();
Karl Schultzc81037d2016-05-12 08:11:23 -06005623 for (const auto &iter : cmd_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5625 iter.msg);
5626 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
Karl Schultzc81037d2016-05-12 08:11:23 -06005627 iter.range.stageFlags, iter.range.offset,
5628 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005629 m_errorMonitor->VerifyFound();
5630 }
5631
5632 // Check for invalid stage flag
5633 m_errorMonitor->SetDesiredFailureMsg(
5634 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5635 "vkCmdPushConstants() call has no stageFlags set.");
5636 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0,
Karl Schultzc81037d2016-05-12 08:11:23 -06005637 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005638 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06005639 EndCommandBuffer();
5640 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
5641 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005642
Karl Schultzc81037d2016-05-12 08:11:23 -06005643 // overlapping range tests with cmd
5644 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
5645 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
5646 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
5647 "0x1 not within flag-matching ranges in pipeline layout"},
5648 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5649 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
5650 "0x1 not within flag-matching ranges in pipeline layout"},
5651 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
5652 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
5653 "0x1 not within flag-matching ranges in pipeline layout"},
5654 }};
5655 const VkPushConstantRange pc_range3[] = {
5656 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
5657 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
5658 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5659 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
5660 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
5661 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
5662 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
5663 };
5664 pipeline_layout_ci.pushConstantRangeCount =
5665 sizeof(pc_range3) / sizeof(VkPushConstantRange);
5666 pipeline_layout_ci.pPushConstantRanges = pc_range3;
5667 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5668 &pipeline_layout);
5669 ASSERT_VK_SUCCESS(err);
5670 BeginCommandBuffer();
5671 for (const auto &iter : cmd_overlap_tests) {
5672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5673 iter.msg);
5674 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
5675 iter.range.stageFlags, iter.range.offset,
5676 iter.range.size, dummy_values);
5677 m_errorMonitor->VerifyFound();
5678 }
5679 EndCommandBuffer();
5680 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
5681 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5682
5683 // positive overlapping range tests with cmd
5684 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
5685 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
5686 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
5687 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
5688 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
5689 }};
5690 const VkPushConstantRange pc_range4[] = {
5691 {VK_SHADER_STAGE_VERTEX_BIT, 0, 64},
5692 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
5693 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
5694 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5695 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
5696 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
5697 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
5698 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
5699 };
5700 pipeline_layout_ci.pushConstantRangeCount =
5701 sizeof(pc_range4) / sizeof(VkPushConstantRange);
5702 pipeline_layout_ci.pPushConstantRanges = pc_range4;
5703 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5704 &pipeline_layout);
5705 ASSERT_VK_SUCCESS(err);
5706 BeginCommandBuffer();
5707 for (const auto &iter : cmd_overlap_tests_pos) {
5708 m_errorMonitor->ExpectSuccess();
5709 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
5710 iter.range.stageFlags, iter.range.offset,
5711 iter.range.size, dummy_values);
5712 m_errorMonitor->VerifyNotFound();
5713 }
5714 EndCommandBuffer();
5715 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005716 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5717}
5718
Karl Schultz6addd812016-02-02 17:17:23 -07005719TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005720 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07005721 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005722
5723 ASSERT_NO_FATAL_FAILURE(InitState());
5724 ASSERT_NO_FATAL_FAILURE(InitViewport());
5725 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5726
5727 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
5728 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005729 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5730 ds_type_count[0].descriptorCount = 10;
5731 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5732 ds_type_count[1].descriptorCount = 2;
5733 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5734 ds_type_count[2].descriptorCount = 2;
5735 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
5736 ds_type_count[3].descriptorCount = 5;
5737 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
5738 // type
5739 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
5740 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
5741 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005742
5743 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005744 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5745 ds_pool_ci.pNext = NULL;
5746 ds_pool_ci.maxSets = 5;
5747 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
5748 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005749
5750 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005751 err =
5752 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005753 ASSERT_VK_SUCCESS(err);
5754
5755 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
5756 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005757 dsl_binding[0].binding = 0;
5758 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5759 dsl_binding[0].descriptorCount = 5;
5760 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
5761 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005762
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005763 // Create layout identical to set0 layout but w/ different stageFlags
5764 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005765 dsl_fs_stage_only.binding = 0;
5766 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5767 dsl_fs_stage_only.descriptorCount = 5;
5768 dsl_fs_stage_only.stageFlags =
5769 VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
5770 // bind time
5771 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005772 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005773 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5774 ds_layout_ci.pNext = NULL;
5775 ds_layout_ci.bindingCount = 1;
5776 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005777 static const uint32_t NUM_LAYOUTS = 4;
5778 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005779 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005780 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
5781 // layout for error case
5782 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5783 &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005784 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005785 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005786 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5787 &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005788 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005789 dsl_binding[0].binding = 0;
5790 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005791 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005792 dsl_binding[1].binding = 1;
5793 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5794 dsl_binding[1].descriptorCount = 2;
5795 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
5796 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005797 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005798 ds_layout_ci.bindingCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005799 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5800 &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005801 ASSERT_VK_SUCCESS(err);
5802 dsl_binding[0].binding = 0;
5803 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005804 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005805 ds_layout_ci.bindingCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07005806 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5807 &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005808 ASSERT_VK_SUCCESS(err);
5809 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005810 dsl_binding[0].descriptorCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005811 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5812 &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005813 ASSERT_VK_SUCCESS(err);
5814
5815 static const uint32_t NUM_SETS = 4;
5816 VkDescriptorSet descriptorSet[NUM_SETS] = {};
5817 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005818 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005819 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005820 alloc_info.descriptorPool = ds_pool;
5821 alloc_info.pSetLayouts = ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005822 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5823 descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005824 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005825 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005826 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005827 alloc_info.pSetLayouts = &ds_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005828 err =
5829 vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005830 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005831
5832 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005833 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5834 pipeline_layout_ci.pNext = NULL;
5835 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
5836 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005837
5838 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005839 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5840 &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005841 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005842 // Create pipelineLayout with only one setLayout
5843 pipeline_layout_ci.setLayoutCount = 1;
5844 VkPipelineLayout single_pipe_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005845 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5846 &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005847 ASSERT_VK_SUCCESS(err);
5848 // Create pipelineLayout with 2 descriptor setLayout at index 0
5849 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
5850 VkPipelineLayout pipe_layout_one_desc;
Karl Schultz6addd812016-02-02 17:17:23 -07005851 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5852 &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005853 ASSERT_VK_SUCCESS(err);
5854 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
5855 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
5856 VkPipelineLayout pipe_layout_five_samp;
Karl Schultz6addd812016-02-02 17:17:23 -07005857 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5858 &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005859 ASSERT_VK_SUCCESS(err);
5860 // Create pipelineLayout with UB type, but stageFlags for FS only
5861 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
5862 VkPipelineLayout pipe_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005863 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5864 &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005865 ASSERT_VK_SUCCESS(err);
5866 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
5867 VkDescriptorSetLayout pl_bad_s0[2] = {};
5868 pl_bad_s0[0] = ds_layout_fs_only;
5869 pl_bad_s0[1] = ds_layout[1];
5870 pipeline_layout_ci.setLayoutCount = 2;
5871 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
5872 VkPipelineLayout pipe_layout_bad_set0;
Karl Schultz6addd812016-02-02 17:17:23 -07005873 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5874 &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005875 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005876
5877 // Create a buffer to update the descriptor with
5878 uint32_t qfi = 0;
5879 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005880 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5881 buffCI.size = 1024;
5882 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5883 buffCI.queueFamilyIndexCount = 1;
5884 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005885
5886 VkBuffer dyub;
5887 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5888 ASSERT_VK_SUCCESS(err);
5889 // Correctly update descriptor to avoid "NOT_UPDATED" error
5890 static const uint32_t NUM_BUFFS = 5;
5891 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005892 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005893 buffInfo[i].buffer = dyub;
5894 buffInfo[i].offset = 0;
5895 buffInfo[i].range = 1024;
5896 }
Karl Schultz6addd812016-02-02 17:17:23 -07005897 VkImage image;
5898 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5899 const int32_t tex_width = 32;
5900 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005901 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005902 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5903 image_create_info.pNext = NULL;
5904 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5905 image_create_info.format = tex_format;
5906 image_create_info.extent.width = tex_width;
5907 image_create_info.extent.height = tex_height;
5908 image_create_info.extent.depth = 1;
5909 image_create_info.mipLevels = 1;
5910 image_create_info.arrayLayers = 1;
5911 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5912 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5913 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5914 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005915 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5916 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005917
Karl Schultz6addd812016-02-02 17:17:23 -07005918 VkMemoryRequirements memReqs;
5919 VkDeviceMemory imageMem;
5920 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005921 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005922 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5923 memAlloc.pNext = NULL;
5924 memAlloc.allocationSize = 0;
5925 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005926 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
5927 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07005928 pass =
5929 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005930 ASSERT_TRUE(pass);
5931 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
5932 ASSERT_VK_SUCCESS(err);
5933 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
5934 ASSERT_VK_SUCCESS(err);
5935
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005936 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005937 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5938 image_view_create_info.image = image;
5939 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5940 image_view_create_info.format = tex_format;
5941 image_view_create_info.subresourceRange.layerCount = 1;
5942 image_view_create_info.subresourceRange.baseMipLevel = 0;
5943 image_view_create_info.subresourceRange.levelCount = 1;
5944 image_view_create_info.subresourceRange.aspectMask =
5945 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005946
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005947 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07005948 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
5949 &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005950 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005951 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005952 imageInfo[0].imageView = view;
5953 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5954 imageInfo[1].imageView = view;
5955 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005956 imageInfo[2].imageView = view;
5957 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5958 imageInfo[3].imageView = view;
5959 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005960
5961 static const uint32_t NUM_SET_UPDATES = 3;
5962 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
5963 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5964 descriptor_write[0].dstSet = descriptorSet[0];
5965 descriptor_write[0].dstBinding = 0;
5966 descriptor_write[0].descriptorCount = 5;
5967 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5968 descriptor_write[0].pBufferInfo = buffInfo;
5969 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5970 descriptor_write[1].dstSet = descriptorSet[1];
5971 descriptor_write[1].dstBinding = 0;
5972 descriptor_write[1].descriptorCount = 2;
5973 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5974 descriptor_write[1].pImageInfo = imageInfo;
5975 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5976 descriptor_write[2].dstSet = descriptorSet[1];
5977 descriptor_write[2].dstBinding = 1;
5978 descriptor_write[2].descriptorCount = 2;
5979 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005980 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005981
5982 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005983
Tobin Ehlis88452832015-12-03 09:40:56 -07005984 // Create PSO to be used for draw-time errors below
5985 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005986 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005987 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005988 "out gl_PerVertex {\n"
5989 " vec4 gl_Position;\n"
5990 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005991 "void main(){\n"
5992 " gl_Position = vec4(1);\n"
5993 "}\n";
5994 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005995 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005996 "\n"
5997 "layout(location=0) out vec4 x;\n"
5998 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5999 "void main(){\n"
6000 " x = vec4(bar.y);\n"
6001 "}\n";
6002 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6003 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006004 VkPipelineObj pipe(m_device);
6005 pipe.AddShader(&vs);
6006 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006007 pipe.AddColorAttachment();
6008 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006009
6010 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006011
Karl Schultz6addd812016-02-02 17:17:23 -07006012 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6013 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6014 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6015 // of PSO
6016 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6017 // cmd_pipeline.c
6018 // due to the fact that cmd_alloc_dset_data() has not been called in
6019 // cmd_bind_graphics_pipeline()
6020 // TODO : Want to cause various binding incompatibility issues here to test
6021 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006022 // First cause various verify_layout_compatibility() fails
6023 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006024 // verify_set_layout_compatibility fail cases:
6025 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultz6addd812016-02-02 17:17:23 -07006026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6027 " due to: invalid VkPipelineLayout ");
6028 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6029 VK_PIPELINE_BIND_POINT_GRAPHICS,
6030 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1,
6031 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006032 m_errorMonitor->VerifyFound();
6033
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006034 // 2. layoutIndex exceeds # of layouts in layout
Karl Schultz6addd812016-02-02 17:17:23 -07006035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6036 " attempting to bind set to index 1");
6037 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6038 VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout,
6039 0, 2, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006040 m_errorMonitor->VerifyFound();
6041
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006042 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006043 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6044 // descriptors
6045 m_errorMonitor->SetDesiredFailureMsg(
6046 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06006047 " has 2 descriptors, but DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07006048 vkCmdBindDescriptorSets(
6049 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6050 pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006051 m_errorMonitor->VerifyFound();
6052
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006053 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6054 // 4. same # of descriptors but mismatch in type
Karl Schultz6addd812016-02-02 17:17:23 -07006055 m_errorMonitor->SetDesiredFailureMsg(
6056 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06006057 " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
Karl Schultz6addd812016-02-02 17:17:23 -07006058 vkCmdBindDescriptorSets(
6059 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6060 pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006061 m_errorMonitor->VerifyFound();
6062
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006063 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6064 // 5. same # of descriptors but mismatch in stageFlags
Karl Schultz6addd812016-02-02 17:17:23 -07006065 m_errorMonitor->SetDesiredFailureMsg(
6066 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06006067 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07006068 vkCmdBindDescriptorSets(
6069 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6070 pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006071 m_errorMonitor->VerifyFound();
6072
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006073 // Cause INFO messages due to disturbing previously bound Sets
6074 // First bind sets 0 & 1
Karl Schultz6addd812016-02-02 17:17:23 -07006075 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6076 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6077 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006078 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Karl Schultz6addd812016-02-02 17:17:23 -07006079 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006080 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006081 " previously bound as set #0 was disturbed ");
6082 vkCmdBindDescriptorSets(
6083 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6084 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006085 m_errorMonitor->VerifyFound();
6086
Karl Schultz6addd812016-02-02 17:17:23 -07006087 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6088 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6089 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006090 // 2. Disturb set after last bound set
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006092 " newly bound as set #0 so set #1 and "
6093 "any subsequent sets were disturbed ");
6094 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6095 VK_PIPELINE_BIND_POINT_GRAPHICS,
6096 pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006097 m_errorMonitor->VerifyFound();
6098
Tobin Ehlis88452832015-12-03 09:40:56 -07006099 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006100 // 1. Error due to not binding required set (we actually use same code as
6101 // above to disturb set0)
6102 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6103 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6104 2, &descriptorSet[0], 0, NULL);
6105 vkCmdBindDescriptorSets(
6106 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6107 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
6108 m_errorMonitor->SetDesiredFailureMsg(
6109 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6110 " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07006111 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006112 m_errorMonitor->VerifyFound();
6113
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006114 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006115 // 2. Error due to bound set not being compatible with PSO's
6116 // VkPipelineLayout (diff stageFlags in this case)
6117 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6118 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6119 2, &descriptorSet[0], 0, NULL);
6120 m_errorMonitor->SetDesiredFailureMsg(
6121 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6122 " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006123 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006124 m_errorMonitor->VerifyFound();
6125
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006126 // Remaining clean-up
6127 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006128 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006129 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6130 }
6131 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06006132 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
6133 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006134 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006135 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6136 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006137 vkFreeMemory(m_device->device(), imageMem, NULL);
6138 vkDestroyImage(m_device->device(), image, NULL);
6139 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006140}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006141
Karl Schultz6addd812016-02-02 17:17:23 -07006142TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006143
Karl Schultz6addd812016-02-02 17:17:23 -07006144 m_errorMonitor->SetDesiredFailureMsg(
6145 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006146 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006147
6148 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006149 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006150 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006151 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006152
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006153 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006154}
6155
Karl Schultz6addd812016-02-02 17:17:23 -07006156TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6157 VkResult err;
6158 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006159
Karl Schultz6addd812016-02-02 17:17:23 -07006160 m_errorMonitor->SetDesiredFailureMsg(
6161 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006162 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006163
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006164 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006165
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006166 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006167 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006168 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006169 cmd.commandPool = m_commandPool;
6170 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006171 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006172
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006173 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006174 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006175
6176 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006177 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006178 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006179 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006180 cmd_buf_info.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07006181 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
6182 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006183 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006184
6185 // The error should be caught by validation of the BeginCommandBuffer call
6186 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6187
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006188 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006189 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006190}
6191
Karl Schultz6addd812016-02-02 17:17:23 -07006192TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006193 // Cause error due to Begin while recording CB
6194 // Then cause 2 errors for attempting to reset CB w/o having
6195 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6196 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006198 "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006199
6200 ASSERT_NO_FATAL_FAILURE(InitState());
6201
6202 // Calls AllocateCommandBuffers
6203 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6204
Karl Schultz6addd812016-02-02 17:17:23 -07006205 // Force the failure by setting the Renderpass and Framebuffer fields with
6206 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006207 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006208 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006209 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6210 cmd_buf_info.pNext = NULL;
6211 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006212 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006213
6214 // Begin CB to transition to recording state
6215 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6216 // Can't re-begin. This should trigger error
6217 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006218 m_errorMonitor->VerifyFound();
6219
Karl Schultz6addd812016-02-02 17:17:23 -07006220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6221 "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006222 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6223 // Reset attempt will trigger error due to incorrect CommandPool state
6224 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006225 m_errorMonitor->VerifyFound();
6226
Karl Schultz6addd812016-02-02 17:17:23 -07006227 m_errorMonitor->SetDesiredFailureMsg(
6228 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6229 " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006230 // Transition CB to RECORDED state
6231 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6232 // Now attempting to Begin will implicitly reset, which triggers error
6233 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006234 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006235}
6236
Karl Schultz6addd812016-02-02 17:17:23 -07006237TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006238 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006239 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006240
Karl Schultz6addd812016-02-02 17:17:23 -07006241 m_errorMonitor->SetDesiredFailureMsg(
6242 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006243 "Invalid Pipeline CreateInfo State: Vtx Shader required");
6244
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006245 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006247
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006248 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006249 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6250 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006251
6252 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006253 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6254 ds_pool_ci.pNext = NULL;
6255 ds_pool_ci.maxSets = 1;
6256 ds_pool_ci.poolSizeCount = 1;
6257 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006258
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006259 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006260 err =
6261 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006262 ASSERT_VK_SUCCESS(err);
6263
Tony Barboureb254902015-07-15 12:50:33 -06006264 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006265 dsl_binding.binding = 0;
6266 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6267 dsl_binding.descriptorCount = 1;
6268 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6269 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006270
Tony Barboureb254902015-07-15 12:50:33 -06006271 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006272 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6273 ds_layout_ci.pNext = NULL;
6274 ds_layout_ci.bindingCount = 1;
6275 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006276
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006277 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006278 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6279 &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006280 ASSERT_VK_SUCCESS(err);
6281
6282 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006283 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006284 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006285 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006286 alloc_info.descriptorPool = ds_pool;
6287 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006288 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6289 &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006290 ASSERT_VK_SUCCESS(err);
6291
Tony Barboureb254902015-07-15 12:50:33 -06006292 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006293 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6294 pipeline_layout_ci.setLayoutCount = 1;
6295 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006296
6297 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006298 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6299 &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006300 ASSERT_VK_SUCCESS(err);
6301
Tobin Ehlise68360f2015-10-01 11:15:13 -06006302 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006303 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006304
6305 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006306 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6307 vp_state_ci.scissorCount = 1;
6308 vp_state_ci.pScissors = &sc;
6309 vp_state_ci.viewportCount = 1;
6310 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006311
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006312 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6313 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6314 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6315 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6316 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6317 rs_state_ci.depthClampEnable = VK_FALSE;
6318 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6319 rs_state_ci.depthBiasEnable = VK_FALSE;
6320
Tony Barboureb254902015-07-15 12:50:33 -06006321 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006322 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6323 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006324 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006325 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6326 gp_ci.layout = pipeline_layout;
6327 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006328
6329 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006330 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6331 pc_ci.initialDataSize = 0;
6332 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006333
6334 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006335 VkPipelineCache pipelineCache;
6336
Karl Schultz6addd812016-02-02 17:17:23 -07006337 err =
6338 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006339 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006340 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6341 &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006342
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006343 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006344
Chia-I Wuf7458c52015-10-26 21:10:41 +08006345 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6346 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6347 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6348 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006349}
Tobin Ehlis912df022015-09-17 08:46:18 -06006350/*// TODO : This test should be good, but needs Tess support in compiler to run
6351TEST_F(VkLayerTest, InvalidPatchControlPoints)
6352{
6353 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006354 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006355
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006357 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6358primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006359
Tobin Ehlis912df022015-09-17 08:46:18 -06006360 ASSERT_NO_FATAL_FAILURE(InitState());
6361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006362
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006363 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006364 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006365 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006366
6367 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6368 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6369 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006370 ds_pool_ci.poolSizeCount = 1;
6371 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006372
6373 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006374 err = vkCreateDescriptorPool(m_device->device(),
6375VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006376 ASSERT_VK_SUCCESS(err);
6377
6378 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006379 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006380 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006381 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006382 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6383 dsl_binding.pImmutableSamplers = NULL;
6384
6385 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006386 ds_layout_ci.sType =
6387VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006388 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006389 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006390 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006391
6392 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006393 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6394&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006395 ASSERT_VK_SUCCESS(err);
6396
6397 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006398 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6399VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006400 ASSERT_VK_SUCCESS(err);
6401
6402 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006403 pipeline_layout_ci.sType =
6404VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006405 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006406 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006407 pipeline_layout_ci.pSetLayouts = &ds_layout;
6408
6409 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006410 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6411&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006412 ASSERT_VK_SUCCESS(err);
6413
6414 VkPipelineShaderStageCreateInfo shaderStages[3];
6415 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6416
Karl Schultz6addd812016-02-02 17:17:23 -07006417 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6418this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006419 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006420 VkShaderObj
6421tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6422this);
6423 VkShaderObj
6424te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6425this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006426
Karl Schultz6addd812016-02-02 17:17:23 -07006427 shaderStages[0].sType =
6428VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006429 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006430 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006431 shaderStages[1].sType =
6432VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006433 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006434 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006435 shaderStages[2].sType =
6436VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006437 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006438 shaderStages[2].shader = te.handle();
6439
6440 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006441 iaCI.sType =
6442VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006443 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006444
6445 VkPipelineTessellationStateCreateInfo tsCI = {};
6446 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6447 tsCI.patchControlPoints = 0; // This will cause an error
6448
6449 VkGraphicsPipelineCreateInfo gp_ci = {};
6450 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6451 gp_ci.pNext = NULL;
6452 gp_ci.stageCount = 3;
6453 gp_ci.pStages = shaderStages;
6454 gp_ci.pVertexInputState = NULL;
6455 gp_ci.pInputAssemblyState = &iaCI;
6456 gp_ci.pTessellationState = &tsCI;
6457 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006458 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006459 gp_ci.pMultisampleState = NULL;
6460 gp_ci.pDepthStencilState = NULL;
6461 gp_ci.pColorBlendState = NULL;
6462 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6463 gp_ci.layout = pipeline_layout;
6464 gp_ci.renderPass = renderPass();
6465
6466 VkPipelineCacheCreateInfo pc_ci = {};
6467 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6468 pc_ci.pNext = NULL;
6469 pc_ci.initialSize = 0;
6470 pc_ci.initialData = 0;
6471 pc_ci.maxSize = 0;
6472
6473 VkPipeline pipeline;
6474 VkPipelineCache pipelineCache;
6475
Karl Schultz6addd812016-02-02 17:17:23 -07006476 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
6477&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06006478 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006479 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6480&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06006481
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006482 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006483
Chia-I Wuf7458c52015-10-26 21:10:41 +08006484 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6485 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6486 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6487 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06006488}
6489*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06006490// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07006491TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07006492 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006493
Karl Schultz6addd812016-02-02 17:17:23 -07006494 m_errorMonitor->SetDesiredFailureMsg(
6495 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006496 "Gfx Pipeline viewport count (1) must match scissor count (0).");
6497
Tobin Ehlise68360f2015-10-01 11:15:13 -06006498 ASSERT_NO_FATAL_FAILURE(InitState());
6499 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006500
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006501 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006502 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6503 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006504
6505 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006506 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6507 ds_pool_ci.maxSets = 1;
6508 ds_pool_ci.poolSizeCount = 1;
6509 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006510
6511 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006512 err =
6513 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006514 ASSERT_VK_SUCCESS(err);
6515
6516 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006517 dsl_binding.binding = 0;
6518 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6519 dsl_binding.descriptorCount = 1;
6520 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006521
6522 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006523 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6524 ds_layout_ci.bindingCount = 1;
6525 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006526
6527 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006528 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6529 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006530 ASSERT_VK_SUCCESS(err);
6531
6532 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006533 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006534 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006535 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006536 alloc_info.descriptorPool = ds_pool;
6537 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006538 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6539 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006540 ASSERT_VK_SUCCESS(err);
6541
6542 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006543 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6544 pipeline_layout_ci.setLayoutCount = 1;
6545 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006546
6547 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006548 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6549 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006550 ASSERT_VK_SUCCESS(err);
6551
6552 VkViewport vp = {}; // Just need dummy vp to point to
6553
6554 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006555 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6556 vp_state_ci.scissorCount = 0;
6557 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
6558 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006559
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006560 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6561 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6562 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6563 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6564 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6565 rs_state_ci.depthClampEnable = VK_FALSE;
6566 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6567 rs_state_ci.depthBiasEnable = VK_FALSE;
6568
Cody Northropeb3a6c12015-10-05 14:44:45 -06006569 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006570 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006571
Karl Schultz6addd812016-02-02 17:17:23 -07006572 VkShaderObj vs(m_device, bindStateVertShaderText,
6573 VK_SHADER_STAGE_VERTEX_BIT, this);
6574 VkShaderObj fs(m_device, bindStateFragShaderText,
6575 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006576 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006577 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006578 shaderStages[0] = vs.GetStageCreateInfo();
6579 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006580
6581 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006582 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6583 gp_ci.stageCount = 2;
6584 gp_ci.pStages = shaderStages;
6585 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006586 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006587 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6588 gp_ci.layout = pipeline_layout;
6589 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006590
6591 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006592 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006593
6594 VkPipeline pipeline;
6595 VkPipelineCache pipelineCache;
6596
Karl Schultz6addd812016-02-02 17:17:23 -07006597 err =
6598 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006599 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006600 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6601 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006602
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006603 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006604
Chia-I Wuf7458c52015-10-26 21:10:41 +08006605 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6606 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6607 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6608 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006609}
Karl Schultz6addd812016-02-02 17:17:23 -07006610// Don't set viewport state in PSO. This is an error b/c we always need this
6611// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06006612// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07006613TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06006614 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006615 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006616
Karl Schultz6addd812016-02-02 17:17:23 -07006617 m_errorMonitor->SetDesiredFailureMsg(
6618 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006619 "Gfx Pipeline pViewportState is null. Even if ");
6620
Tobin Ehlise68360f2015-10-01 11:15:13 -06006621 ASSERT_NO_FATAL_FAILURE(InitState());
6622 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006623
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006624 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006625 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6626 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006627
6628 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006629 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6630 ds_pool_ci.maxSets = 1;
6631 ds_pool_ci.poolSizeCount = 1;
6632 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006633
6634 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006635 err =
6636 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006637 ASSERT_VK_SUCCESS(err);
6638
6639 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006640 dsl_binding.binding = 0;
6641 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6642 dsl_binding.descriptorCount = 1;
6643 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006644
6645 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006646 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6647 ds_layout_ci.bindingCount = 1;
6648 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006649
6650 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006651 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6652 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006653 ASSERT_VK_SUCCESS(err);
6654
6655 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006656 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006657 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006658 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006659 alloc_info.descriptorPool = ds_pool;
6660 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006661 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6662 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006663 ASSERT_VK_SUCCESS(err);
6664
6665 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006666 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6667 pipeline_layout_ci.setLayoutCount = 1;
6668 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006669
6670 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006671 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6672 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006673 ASSERT_VK_SUCCESS(err);
6674
6675 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6676 // Set scissor as dynamic to avoid second error
6677 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006678 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6679 dyn_state_ci.dynamicStateCount = 1;
6680 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006681
Cody Northropeb3a6c12015-10-05 14:44:45 -06006682 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006683 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006684
Karl Schultz6addd812016-02-02 17:17:23 -07006685 VkShaderObj vs(m_device, bindStateVertShaderText,
6686 VK_SHADER_STAGE_VERTEX_BIT, this);
6687 VkShaderObj fs(m_device, bindStateFragShaderText,
6688 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006689 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006690 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006691 shaderStages[0] = vs.GetStageCreateInfo();
6692 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006693
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006694
6695 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6696 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6697 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6698 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6699 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6700 rs_state_ci.depthClampEnable = VK_FALSE;
6701 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6702 rs_state_ci.depthBiasEnable = VK_FALSE;
6703
Tobin Ehlise68360f2015-10-01 11:15:13 -06006704 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006705 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6706 gp_ci.stageCount = 2;
6707 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006708 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006709 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
6710 // should cause validation error
6711 gp_ci.pDynamicState = &dyn_state_ci;
6712 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6713 gp_ci.layout = pipeline_layout;
6714 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006715
6716 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006717 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006718
6719 VkPipeline pipeline;
6720 VkPipelineCache pipelineCache;
6721
Karl Schultz6addd812016-02-02 17:17:23 -07006722 err =
6723 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006724 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006725 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6726 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006727
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006728 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006729
Chia-I Wuf7458c52015-10-26 21:10:41 +08006730 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6731 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6732 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6733 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006734}
6735// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07006736// Then run second test where dynamic scissor count doesn't match PSO scissor
6737// count
6738TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
6739 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006740
Karl Schultz6addd812016-02-02 17:17:23 -07006741 m_errorMonitor->SetDesiredFailureMsg(
6742 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006743 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
6744
Tobin Ehlise68360f2015-10-01 11:15:13 -06006745 ASSERT_NO_FATAL_FAILURE(InitState());
6746 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006747
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006748 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006749 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6750 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006751
6752 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006753 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6754 ds_pool_ci.maxSets = 1;
6755 ds_pool_ci.poolSizeCount = 1;
6756 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006757
6758 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006759 err =
6760 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006761 ASSERT_VK_SUCCESS(err);
6762
6763 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006764 dsl_binding.binding = 0;
6765 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6766 dsl_binding.descriptorCount = 1;
6767 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006768
6769 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006770 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6771 ds_layout_ci.bindingCount = 1;
6772 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006773
6774 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006775 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6776 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006777 ASSERT_VK_SUCCESS(err);
6778
6779 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006780 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006781 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006782 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006783 alloc_info.descriptorPool = ds_pool;
6784 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006785 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6786 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006787 ASSERT_VK_SUCCESS(err);
6788
6789 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006790 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6791 pipeline_layout_ci.setLayoutCount = 1;
6792 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006793
6794 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006795 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6796 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006797 ASSERT_VK_SUCCESS(err);
6798
6799 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006800 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6801 vp_state_ci.viewportCount = 1;
6802 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
6803 vp_state_ci.scissorCount = 1;
6804 vp_state_ci.pScissors =
6805 NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06006806
6807 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6808 // Set scissor as dynamic to avoid that error
6809 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006810 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6811 dyn_state_ci.dynamicStateCount = 1;
6812 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006813
Cody Northropeb3a6c12015-10-05 14:44:45 -06006814 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006815 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006816
Karl Schultz6addd812016-02-02 17:17:23 -07006817 VkShaderObj vs(m_device, bindStateVertShaderText,
6818 VK_SHADER_STAGE_VERTEX_BIT, this);
6819 VkShaderObj fs(m_device, bindStateFragShaderText,
6820 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006821 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006822 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006823 shaderStages[0] = vs.GetStageCreateInfo();
6824 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006825
Cody Northropf6622dc2015-10-06 10:33:21 -06006826 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6827 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6828 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006829 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006830 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006831 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006832 vi_ci.pVertexAttributeDescriptions = nullptr;
6833
6834 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6835 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6836 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6837
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006838 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006839 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06006840 rs_ci.pNext = nullptr;
6841
Mark Youngc89c6312016-03-31 16:03:20 -06006842 VkPipelineColorBlendAttachmentState att = {};
6843 att.blendEnable = VK_FALSE;
6844 att.colorWriteMask = 0xf;
6845
Cody Northropf6622dc2015-10-06 10:33:21 -06006846 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6847 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6848 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006849 cb_ci.attachmentCount = 1;
6850 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06006851
Tobin Ehlise68360f2015-10-01 11:15:13 -06006852 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006853 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6854 gp_ci.stageCount = 2;
6855 gp_ci.pStages = shaderStages;
6856 gp_ci.pVertexInputState = &vi_ci;
6857 gp_ci.pInputAssemblyState = &ia_ci;
6858 gp_ci.pViewportState = &vp_state_ci;
6859 gp_ci.pRasterizationState = &rs_ci;
6860 gp_ci.pColorBlendState = &cb_ci;
6861 gp_ci.pDynamicState = &dyn_state_ci;
6862 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6863 gp_ci.layout = pipeline_layout;
6864 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006865
6866 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006867 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006868
6869 VkPipeline pipeline;
6870 VkPipelineCache pipelineCache;
6871
Karl Schultz6addd812016-02-02 17:17:23 -07006872 err =
6873 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006874 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006875 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6876 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006877
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006878 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006879
Tobin Ehlisd332f282015-10-02 11:00:56 -06006880 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07006881 // First need to successfully create the PSO from above by setting
6882 // pViewports
6883 m_errorMonitor->SetDesiredFailureMsg(
6884 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6885 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO "
6886 "scissorCount is 1. These counts must match.");
6887
6888 VkViewport vp = {}; // Just need dummy vp to point to
6889 vp_state_ci.pViewports = &vp;
6890 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6891 &gp_ci, NULL, &pipeline);
6892 ASSERT_VK_SUCCESS(err);
6893 BeginCommandBuffer();
6894 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6895 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
6896 VkRect2D scissors[2] = {}; // don't care about data
6897 // Count of 2 doesn't match PSO count of 1
6898 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
6899 Draw(1, 0, 0, 0);
6900
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006901 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006902
6903 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6904 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6905 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6906 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006907 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006908}
6909// Create PSO w/o non-zero scissorCount but no scissor data
6910// Then run second test where dynamic viewportCount doesn't match PSO
6911// viewportCount
6912TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
6913 VkResult err;
6914
6915 m_errorMonitor->SetDesiredFailureMsg(
6916 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6917 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
6918
6919 ASSERT_NO_FATAL_FAILURE(InitState());
6920 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6921
6922 VkDescriptorPoolSize ds_type_count = {};
6923 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6924 ds_type_count.descriptorCount = 1;
6925
6926 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6927 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6928 ds_pool_ci.maxSets = 1;
6929 ds_pool_ci.poolSizeCount = 1;
6930 ds_pool_ci.pPoolSizes = &ds_type_count;
6931
6932 VkDescriptorPool ds_pool;
6933 err =
6934 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6935 ASSERT_VK_SUCCESS(err);
6936
6937 VkDescriptorSetLayoutBinding dsl_binding = {};
6938 dsl_binding.binding = 0;
6939 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6940 dsl_binding.descriptorCount = 1;
6941 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6942
6943 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6944 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6945 ds_layout_ci.bindingCount = 1;
6946 ds_layout_ci.pBindings = &dsl_binding;
6947
6948 VkDescriptorSetLayout ds_layout;
6949 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6950 &ds_layout);
6951 ASSERT_VK_SUCCESS(err);
6952
6953 VkDescriptorSet descriptorSet;
6954 VkDescriptorSetAllocateInfo alloc_info = {};
6955 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6956 alloc_info.descriptorSetCount = 1;
6957 alloc_info.descriptorPool = ds_pool;
6958 alloc_info.pSetLayouts = &ds_layout;
6959 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6960 &descriptorSet);
6961 ASSERT_VK_SUCCESS(err);
6962
6963 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6964 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6965 pipeline_layout_ci.setLayoutCount = 1;
6966 pipeline_layout_ci.pSetLayouts = &ds_layout;
6967
6968 VkPipelineLayout pipeline_layout;
6969 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6970 &pipeline_layout);
6971 ASSERT_VK_SUCCESS(err);
6972
6973 VkPipelineViewportStateCreateInfo vp_state_ci = {};
6974 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6975 vp_state_ci.scissorCount = 1;
6976 vp_state_ci.pScissors =
6977 NULL; // Null scissor w/ count of 1 should cause error
6978 vp_state_ci.viewportCount = 1;
6979 vp_state_ci.pViewports =
6980 NULL; // vp is dynamic (below) so this won't cause error
6981
6982 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
6983 // Set scissor as dynamic to avoid that error
6984 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
6985 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6986 dyn_state_ci.dynamicStateCount = 1;
6987 dyn_state_ci.pDynamicStates = &vp_state;
6988
6989 VkPipelineShaderStageCreateInfo shaderStages[2];
6990 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6991
6992 VkShaderObj vs(m_device, bindStateVertShaderText,
6993 VK_SHADER_STAGE_VERTEX_BIT, this);
6994 VkShaderObj fs(m_device, bindStateFragShaderText,
6995 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006996 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006997 // but add it to be able to run on more devices
6998 shaderStages[0] = vs.GetStageCreateInfo();
6999 shaderStages[1] = fs.GetStageCreateInfo();
7000
7001 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7002 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7003 vi_ci.pNext = nullptr;
7004 vi_ci.vertexBindingDescriptionCount = 0;
7005 vi_ci.pVertexBindingDescriptions = nullptr;
7006 vi_ci.vertexAttributeDescriptionCount = 0;
7007 vi_ci.pVertexAttributeDescriptions = nullptr;
7008
7009 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7010 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7011 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7012
7013 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7014 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7015 rs_ci.pNext = nullptr;
7016
Mark Youngc89c6312016-03-31 16:03:20 -06007017 VkPipelineColorBlendAttachmentState att = {};
7018 att.blendEnable = VK_FALSE;
7019 att.colorWriteMask = 0xf;
7020
Karl Schultz6addd812016-02-02 17:17:23 -07007021 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7022 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7023 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007024 cb_ci.attachmentCount = 1;
7025 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007026
7027 VkGraphicsPipelineCreateInfo gp_ci = {};
7028 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7029 gp_ci.stageCount = 2;
7030 gp_ci.pStages = shaderStages;
7031 gp_ci.pVertexInputState = &vi_ci;
7032 gp_ci.pInputAssemblyState = &ia_ci;
7033 gp_ci.pViewportState = &vp_state_ci;
7034 gp_ci.pRasterizationState = &rs_ci;
7035 gp_ci.pColorBlendState = &cb_ci;
7036 gp_ci.pDynamicState = &dyn_state_ci;
7037 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7038 gp_ci.layout = pipeline_layout;
7039 gp_ci.renderPass = renderPass();
7040
7041 VkPipelineCacheCreateInfo pc_ci = {};
7042 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7043
7044 VkPipeline pipeline;
7045 VkPipelineCache pipelineCache;
7046
7047 err =
7048 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7049 ASSERT_VK_SUCCESS(err);
7050 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7051 &gp_ci, NULL, &pipeline);
7052
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007053 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007054
7055 // Now hit second fail case where we set scissor w/ different count than PSO
7056 // First need to successfully create the PSO from above by setting
7057 // pViewports
7058 m_errorMonitor->SetDesiredFailureMsg(
7059 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7060 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO "
7061 "viewportCount is 1. These counts must match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007062
Tobin Ehlisd332f282015-10-02 11:00:56 -06007063 VkRect2D sc = {}; // Just need dummy vp to point to
7064 vp_state_ci.pScissors = &sc;
Karl Schultz6addd812016-02-02 17:17:23 -07007065 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7066 &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007067 ASSERT_VK_SUCCESS(err);
7068 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007069 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7070 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007071 VkViewport viewports[2] = {}; // don't care about data
7072 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07007073 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007074 Draw(1, 0, 0, 0);
7075
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007076 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007077
Chia-I Wuf7458c52015-10-26 21:10:41 +08007078 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7079 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7080 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7081 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007082 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007083}
7084
Mark Young7394fdd2016-03-31 14:56:43 -06007085TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7086 VkResult err;
7087
7088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06007089 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007090
7091 ASSERT_NO_FATAL_FAILURE(InitState());
7092 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7093
7094 VkDescriptorPoolSize ds_type_count = {};
7095 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7096 ds_type_count.descriptorCount = 1;
7097
7098 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7099 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7100 ds_pool_ci.maxSets = 1;
7101 ds_pool_ci.poolSizeCount = 1;
7102 ds_pool_ci.pPoolSizes = &ds_type_count;
7103
7104 VkDescriptorPool ds_pool;
7105 err =
7106 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7107 ASSERT_VK_SUCCESS(err);
7108
7109 VkDescriptorSetLayoutBinding dsl_binding = {};
7110 dsl_binding.binding = 0;
7111 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7112 dsl_binding.descriptorCount = 1;
7113 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7114
7115 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7116 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7117 ds_layout_ci.bindingCount = 1;
7118 ds_layout_ci.pBindings = &dsl_binding;
7119
7120 VkDescriptorSetLayout ds_layout;
7121 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7122 &ds_layout);
7123 ASSERT_VK_SUCCESS(err);
7124
7125 VkDescriptorSet descriptorSet;
7126 VkDescriptorSetAllocateInfo alloc_info = {};
7127 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7128 alloc_info.descriptorSetCount = 1;
7129 alloc_info.descriptorPool = ds_pool;
7130 alloc_info.pSetLayouts = &ds_layout;
7131 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7132 &descriptorSet);
7133 ASSERT_VK_SUCCESS(err);
7134
7135 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7136 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7137 pipeline_layout_ci.setLayoutCount = 1;
7138 pipeline_layout_ci.pSetLayouts = &ds_layout;
7139
7140 VkPipelineLayout pipeline_layout;
7141 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7142 &pipeline_layout);
7143 ASSERT_VK_SUCCESS(err);
7144
7145 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7146 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7147 vp_state_ci.scissorCount = 1;
7148 vp_state_ci.pScissors = NULL;
7149 vp_state_ci.viewportCount = 1;
7150 vp_state_ci.pViewports = NULL;
7151
7152 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT,
7153 VK_DYNAMIC_STATE_SCISSOR,
7154 VK_DYNAMIC_STATE_LINE_WIDTH};
7155 // Set scissor as dynamic to avoid that error
7156 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7157 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7158 dyn_state_ci.dynamicStateCount = 2;
7159 dyn_state_ci.pDynamicStates = dynamic_states;
7160
7161 VkPipelineShaderStageCreateInfo shaderStages[2];
7162 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7163
7164 VkShaderObj vs(m_device, bindStateVertShaderText,
7165 VK_SHADER_STAGE_VERTEX_BIT, this);
7166 VkShaderObj fs(m_device, bindStateFragShaderText,
7167 VK_SHADER_STAGE_FRAGMENT_BIT,
7168 this); // TODO - We shouldn't need a fragment shader
7169 // but add it to be able to run on more devices
7170 shaderStages[0] = vs.GetStageCreateInfo();
7171 shaderStages[1] = fs.GetStageCreateInfo();
7172
7173 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7174 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7175 vi_ci.pNext = nullptr;
7176 vi_ci.vertexBindingDescriptionCount = 0;
7177 vi_ci.pVertexBindingDescriptions = nullptr;
7178 vi_ci.vertexAttributeDescriptionCount = 0;
7179 vi_ci.pVertexAttributeDescriptions = nullptr;
7180
7181 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7182 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7183 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7184
7185 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7186 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7187 rs_ci.pNext = nullptr;
7188
Mark Young47107952016-05-02 15:59:55 -06007189 // Check too low (line width of -1.0f).
7190 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007191
7192 VkPipelineColorBlendAttachmentState att = {};
7193 att.blendEnable = VK_FALSE;
7194 att.colorWriteMask = 0xf;
7195
7196 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7197 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7198 cb_ci.pNext = nullptr;
7199 cb_ci.attachmentCount = 1;
7200 cb_ci.pAttachments = &att;
7201
7202 VkGraphicsPipelineCreateInfo gp_ci = {};
7203 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7204 gp_ci.stageCount = 2;
7205 gp_ci.pStages = shaderStages;
7206 gp_ci.pVertexInputState = &vi_ci;
7207 gp_ci.pInputAssemblyState = &ia_ci;
7208 gp_ci.pViewportState = &vp_state_ci;
7209 gp_ci.pRasterizationState = &rs_ci;
7210 gp_ci.pColorBlendState = &cb_ci;
7211 gp_ci.pDynamicState = &dyn_state_ci;
7212 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7213 gp_ci.layout = pipeline_layout;
7214 gp_ci.renderPass = renderPass();
7215
7216 VkPipelineCacheCreateInfo pc_ci = {};
7217 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7218
7219 VkPipeline pipeline;
7220 VkPipelineCache pipelineCache;
7221
7222 err =
7223 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7224 ASSERT_VK_SUCCESS(err);
7225 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7226 &gp_ci, NULL, &pipeline);
7227
7228 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007229 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007230
7231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7232 "Attempt to set lineWidth to 65536");
7233
7234 // Check too high (line width of 65536.0f).
7235 rs_ci.lineWidth = 65536.0f;
7236
7237 err =
7238 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7239 ASSERT_VK_SUCCESS(err);
7240 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7241 &gp_ci, NULL, &pipeline);
7242
7243 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007244 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007245
7246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06007247 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007248
7249 dyn_state_ci.dynamicStateCount = 3;
7250
7251 rs_ci.lineWidth = 1.0f;
7252
7253 err =
7254 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7255 ASSERT_VK_SUCCESS(err);
7256 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7257 &gp_ci, NULL, &pipeline);
7258 BeginCommandBuffer();
7259 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7260 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
7261
7262 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007263 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007264 m_errorMonitor->VerifyFound();
7265
7266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7267 "Attempt to set lineWidth to 65536");
7268
7269 // Check too high with dynamic setting.
7270 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7271 m_errorMonitor->VerifyFound();
7272 EndCommandBuffer();
7273
7274 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7275 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7276 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7277 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007278 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007279}
7280
Karl Schultz6addd812016-02-02 17:17:23 -07007281TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007282 // Bind a NULL RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007283 m_errorMonitor->SetDesiredFailureMsg(
7284 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007285 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007286
7287 ASSERT_NO_FATAL_FAILURE(InitState());
7288 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007289
Tony Barbourfe3351b2015-07-28 10:17:20 -06007290 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007291 // Don't care about RenderPass handle b/c error should be flagged before
7292 // that
7293 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL,
7294 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007295
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007296 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007297}
7298
Karl Schultz6addd812016-02-02 17:17:23 -07007299TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007300 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007301 m_errorMonitor->SetDesiredFailureMsg(
7302 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007303 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007304
7305 ASSERT_NO_FATAL_FAILURE(InitState());
7306 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007307
Tony Barbourfe3351b2015-07-28 10:17:20 -06007308 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007309 // Just create a dummy Renderpass that's non-NULL so we can get to the
7310 // proper error
Chris Forbes38ae7c42016-06-21 20:51:44 +12007311 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo,
Karl Schultz6addd812016-02-02 17:17:23 -07007312 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007313
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007314 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007315}
7316
Chris Forbes2eeabe32016-06-21 20:52:34 +12007317TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
7318 m_errorMonitor->ExpectSuccess();
7319
7320 ASSERT_NO_FATAL_FAILURE(InitState());
7321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7322
7323 BeginCommandBuffer(); // framework implicitly begins the renderpass.
7324 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit.
7325
7326 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo,
7327 VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
7328 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7329 m_errorMonitor->VerifyNotFound();
7330 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo,
7331 VK_SUBPASS_CONTENTS_INLINE);
7332 m_errorMonitor->VerifyNotFound();
7333 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7334 m_errorMonitor->VerifyNotFound();
7335
7336 m_commandBuffer->EndCommandBuffer();
7337 m_errorMonitor->VerifyNotFound();
7338}
7339
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007340TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7341 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7342 "the number of renderPass attachments that use loadOp"
7343 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7344
7345 ASSERT_NO_FATAL_FAILURE(InitState());
7346 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7347
7348 // Create a renderPass with a single attachment that uses loadOp CLEAR
7349 VkAttachmentReference attach = {};
7350 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7351 VkSubpassDescription subpass = {};
7352 subpass.inputAttachmentCount = 1;
7353 subpass.pInputAttachments = &attach;
7354 VkRenderPassCreateInfo rpci = {};
7355 rpci.subpassCount = 1;
7356 rpci.pSubpasses = &subpass;
7357 rpci.attachmentCount = 1;
7358 VkAttachmentDescription attach_desc = {};
7359 attach_desc.format = VK_FORMAT_UNDEFINED;
7360 // Set loadOp to CLEAR
7361 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7362 rpci.pAttachments = &attach_desc;
7363 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7364 VkRenderPass rp;
7365 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7366
7367 VkCommandBufferInheritanceInfo hinfo = {};
7368 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7369 hinfo.renderPass = VK_NULL_HANDLE;
7370 hinfo.subpass = 0;
7371 hinfo.framebuffer = VK_NULL_HANDLE;
7372 hinfo.occlusionQueryEnable = VK_FALSE;
7373 hinfo.queryFlags = 0;
7374 hinfo.pipelineStatistics = 0;
7375 VkCommandBufferBeginInfo info = {};
7376 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7377 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7378 info.pInheritanceInfo = &hinfo;
7379
7380 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7381 VkRenderPassBeginInfo rp_begin = {};
7382 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7383 rp_begin.pNext = NULL;
7384 rp_begin.renderPass = renderPass();
7385 rp_begin.framebuffer = framebuffer();
7386 rp_begin.clearValueCount = 0; // Should be 1
7387
7388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7389 " has a clearValueCount of 0 but the "
7390 "actual number of attachments in "
7391 "renderPass ");
7392
7393 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
7394 VK_SUBPASS_CONTENTS_INLINE);
7395
7396 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007397
7398 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007399}
7400
Cody Northrop3bb4d962016-05-09 16:15:57 -06007401TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7402
7403 TEST_DESCRIPTION("End a command buffer with an active render pass");
7404
7405 m_errorMonitor->SetDesiredFailureMsg(
7406 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7407 "It is invalid to issue this call inside an active render pass");
7408
7409 ASSERT_NO_FATAL_FAILURE(InitState());
7410 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7411
7412 // The framework's BeginCommandBuffer calls CreateRenderPass
7413 BeginCommandBuffer();
7414
7415 // Call directly into vkEndCommandBuffer instead of the
7416 // the framework's EndCommandBuffer, which inserts a
7417 // vkEndRenderPass
7418 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7419
7420 m_errorMonitor->VerifyFound();
7421
7422 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7423 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
7424}
7425
Karl Schultz6addd812016-02-02 17:17:23 -07007426TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007427 // Call CmdFillBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07007428 m_errorMonitor->SetDesiredFailureMsg(
7429 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007430 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007431
7432 ASSERT_NO_FATAL_FAILURE(InitState());
7433 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007434
7435 // Renderpass is started here
7436 BeginCommandBuffer();
7437
7438 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007439 vk_testing::Buffer dstBuffer;
7440 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007441
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007442 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007443
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007444 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007445}
7446
Karl Schultz6addd812016-02-02 17:17:23 -07007447TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007448 // Call CmdUpdateBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07007449 m_errorMonitor->SetDesiredFailureMsg(
7450 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007451 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007452
7453 ASSERT_NO_FATAL_FAILURE(InitState());
7454 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007455
7456 // Renderpass is started here
7457 BeginCommandBuffer();
7458
7459 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007460 vk_testing::Buffer dstBuffer;
7461 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007462
Karl Schultz6addd812016-02-02 17:17:23 -07007463 VkDeviceSize dstOffset = 0;
7464 VkDeviceSize dataSize = 1024;
7465 const uint32_t *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007466
Karl Schultz6addd812016-02-02 17:17:23 -07007467 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
7468 dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007469
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007470 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007471}
7472
Karl Schultz6addd812016-02-02 17:17:23 -07007473TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007474 // Call CmdClearColorImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007475 m_errorMonitor->SetDesiredFailureMsg(
7476 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007477 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007478
7479 ASSERT_NO_FATAL_FAILURE(InitState());
7480 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007481
7482 // Renderpass is started here
7483 BeginCommandBuffer();
7484
Michael Lentine0a369f62016-02-03 16:51:46 -06007485 VkClearColorValue clear_color;
7486 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007487 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7488 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7489 const int32_t tex_width = 32;
7490 const int32_t tex_height = 32;
7491 VkImageCreateInfo image_create_info = {};
7492 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7493 image_create_info.pNext = NULL;
7494 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7495 image_create_info.format = tex_format;
7496 image_create_info.extent.width = tex_width;
7497 image_create_info.extent.height = tex_height;
7498 image_create_info.extent.depth = 1;
7499 image_create_info.mipLevels = 1;
7500 image_create_info.arrayLayers = 1;
7501 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7502 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7503 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007504
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007505 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07007506 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
7507 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007508
Karl Schultz6addd812016-02-02 17:17:23 -07007509 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
7510 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007511
Karl Schultz6addd812016-02-02 17:17:23 -07007512 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7513 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007514
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007515 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007516}
7517
Karl Schultz6addd812016-02-02 17:17:23 -07007518TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007519 // Call CmdClearDepthStencilImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007520 m_errorMonitor->SetDesiredFailureMsg(
7521 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007522 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007523
7524 ASSERT_NO_FATAL_FAILURE(InitState());
7525 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007526
7527 // Renderpass is started here
7528 BeginCommandBuffer();
7529
7530 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007531 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007532 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7533 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7534 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7535 image_create_info.extent.width = 64;
7536 image_create_info.extent.height = 64;
7537 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7538 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007539
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007540 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07007541 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
7542 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007543
Karl Schultz6addd812016-02-02 17:17:23 -07007544 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
7545 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007546
Karl Schultz6addd812016-02-02 17:17:23 -07007547 vkCmdClearDepthStencilImage(
7548 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7549 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
7550 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007551
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007552 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007553}
7554
Karl Schultz6addd812016-02-02 17:17:23 -07007555TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007556 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007557 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007558
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007560 "vkCmdClearAttachments: This call "
7561 "must be issued inside an active "
7562 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007563
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007564 ASSERT_NO_FATAL_FAILURE(InitState());
7565 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007566
7567 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007568 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007569 ASSERT_VK_SUCCESS(err);
7570
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007571 VkClearAttachment color_attachment;
7572 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7573 color_attachment.clearValue.color.float32[0] = 0;
7574 color_attachment.clearValue.color.float32[1] = 0;
7575 color_attachment.clearValue.color.float32[2] = 0;
7576 color_attachment.clearValue.color.float32[3] = 0;
7577 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007578 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
7579 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
7580 &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007581
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007582 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007583}
7584
Karl Schultz9e66a292016-04-21 15:57:51 -06007585TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
7586 // Try to add a buffer memory barrier with no buffer.
7587 m_errorMonitor->SetDesiredFailureMsg(
7588 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7589 "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE");
7590
7591 ASSERT_NO_FATAL_FAILURE(InitState());
7592 BeginCommandBuffer();
7593
7594 VkBufferMemoryBarrier buf_barrier = {};
7595 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7596 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7597 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7598 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7599 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7600 buf_barrier.buffer = VK_NULL_HANDLE;
7601 buf_barrier.offset = 0;
7602 buf_barrier.size = VK_WHOLE_SIZE;
7603 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7604 VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
7605 0, 0, nullptr, 1, &buf_barrier, 0, nullptr);
7606
7607 m_errorMonitor->VerifyFound();
7608}
7609
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007610TEST_F(VkLayerTest, InvalidBarriers) {
7611 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
7612
7613 m_errorMonitor->SetDesiredFailureMsg(
7614 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
7615
7616 ASSERT_NO_FATAL_FAILURE(InitState());
7617 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7618
7619 VkMemoryBarrier mem_barrier = {};
7620 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
7621 mem_barrier.pNext = NULL;
7622 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7623 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7624 BeginCommandBuffer();
7625 // BeginCommandBuffer() starts a render pass
7626 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7627 VK_PIPELINE_STAGE_HOST_BIT,
7628 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
7629 &mem_barrier, 0, nullptr, 0, nullptr);
7630 m_errorMonitor->VerifyFound();
7631
7632 m_errorMonitor->SetDesiredFailureMsg(
7633 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7634 "Image Layout cannot be transitioned to UNDEFINED");
7635 VkImageObj image(m_device);
7636 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
7637 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
7638 ASSERT_TRUE(image.initialized());
7639 VkImageMemoryBarrier img_barrier = {};
7640 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
7641 img_barrier.pNext = NULL;
7642 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7643 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7644 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7645 // New layout can't be UNDEFINED
7646 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
7647 img_barrier.image = image.handle();
7648 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7649 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7650 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7651 img_barrier.subresourceRange.baseArrayLayer = 0;
7652 img_barrier.subresourceRange.baseMipLevel = 0;
7653 img_barrier.subresourceRange.layerCount = 1;
7654 img_barrier.subresourceRange.levelCount = 1;
7655 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7656 VK_PIPELINE_STAGE_HOST_BIT,
7657 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7658 nullptr, 1, &img_barrier);
7659 m_errorMonitor->VerifyFound();
7660 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7661
7662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7663 "Subresource must have the sum of the "
7664 "baseArrayLayer");
7665 // baseArrayLayer + layerCount must be <= image's arrayLayers
7666 img_barrier.subresourceRange.baseArrayLayer = 1;
7667 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7668 VK_PIPELINE_STAGE_HOST_BIT,
7669 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7670 nullptr, 1, &img_barrier);
7671 m_errorMonitor->VerifyFound();
7672 img_barrier.subresourceRange.baseArrayLayer = 0;
7673
7674 m_errorMonitor->SetDesiredFailureMsg(
7675 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7676 "Subresource must have the sum of the baseMipLevel");
7677 // baseMipLevel + levelCount must be <= image's mipLevels
7678 img_barrier.subresourceRange.baseMipLevel = 1;
7679 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7680 VK_PIPELINE_STAGE_HOST_BIT,
7681 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7682 nullptr, 1, &img_barrier);
7683 m_errorMonitor->VerifyFound();
7684 img_barrier.subresourceRange.baseMipLevel = 0;
7685
7686 m_errorMonitor->SetDesiredFailureMsg(
7687 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7688 "Buffer Barriers cannot be used during a render pass");
7689 vk_testing::Buffer buffer;
7690 buffer.init(*m_device, 256);
7691 VkBufferMemoryBarrier buf_barrier = {};
7692 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7693 buf_barrier.pNext = NULL;
7694 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7695 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7696 buf_barrier.buffer = buffer.handle();
7697 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7698 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7699 buf_barrier.offset = 0;
7700 buf_barrier.size = VK_WHOLE_SIZE;
7701 // Can't send buffer barrier during a render pass
7702 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7703 VK_PIPELINE_STAGE_HOST_BIT,
7704 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7705 &buf_barrier, 0, nullptr);
7706 m_errorMonitor->VerifyFound();
7707 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7708
7709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7710 "which is not less than total size");
7711 buf_barrier.offset = 257;
7712 // Offset greater than total size
7713 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7714 VK_PIPELINE_STAGE_HOST_BIT,
7715 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7716 &buf_barrier, 0, nullptr);
7717 m_errorMonitor->VerifyFound();
7718 buf_barrier.offset = 0;
7719
7720 m_errorMonitor->SetDesiredFailureMsg(
7721 VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
7722 buf_barrier.size = 257;
7723 // Size greater than total size
7724 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7725 VK_PIPELINE_STAGE_HOST_BIT,
7726 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7727 &buf_barrier, 0, nullptr);
7728 m_errorMonitor->VerifyFound();
7729 buf_barrier.size = VK_WHOLE_SIZE;
7730
7731 m_errorMonitor->SetDesiredFailureMsg(
7732 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7733 "Image is a depth and stencil format and thus must "
7734 "have both VK_IMAGE_ASPECT_DEPTH_BIT and "
7735 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
7736 VkDepthStencilObj ds_image(m_device);
7737 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
7738 ASSERT_TRUE(ds_image.initialized());
7739 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7740 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
7741 img_barrier.image = ds_image.handle();
7742 // Leave aspectMask at COLOR on purpose
7743 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7744 VK_PIPELINE_STAGE_HOST_BIT,
7745 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7746 nullptr, 1, &img_barrier);
7747 m_errorMonitor->VerifyFound();
7748}
7749
Karl Schultz6addd812016-02-02 17:17:23 -07007750TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007751 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007752 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007753
Karl Schultz6addd812016-02-02 17:17:23 -07007754 m_errorMonitor->SetDesiredFailureMsg(
7755 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007756 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
7757
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007758 ASSERT_NO_FATAL_FAILURE(InitState());
7759 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007760 uint32_t qfi = 0;
7761 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007762 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7763 buffCI.size = 1024;
7764 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7765 buffCI.queueFamilyIndexCount = 1;
7766 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007767
7768 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007769 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007770 ASSERT_VK_SUCCESS(err);
7771
7772 BeginCommandBuffer();
7773 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007774 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7775 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007776 // Should error before calling to driver so don't care about actual data
Karl Schultz6addd812016-02-02 17:17:23 -07007777 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
7778 VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007779
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007780 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007781
Chia-I Wuf7458c52015-10-26 21:10:41 +08007782 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007783}
7784
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007785TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
7786 // Create an out-of-range queueFamilyIndex
7787 m_errorMonitor->SetDesiredFailureMsg(
7788 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesde628532016-04-21 16:30:17 -06007789 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
7790 "of the indices specified when the device was created, via the "
7791 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007792
7793 ASSERT_NO_FATAL_FAILURE(InitState());
7794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7795 VkBufferCreateInfo buffCI = {};
7796 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7797 buffCI.size = 1024;
7798 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7799 buffCI.queueFamilyIndexCount = 1;
7800 // Introduce failure by specifying invalid queue_family_index
7801 uint32_t qfi = 777;
7802 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06007803 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007804
7805 VkBuffer ib;
7806 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
7807
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007808 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007809 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007810}
7811
Karl Schultz6addd812016-02-02 17:17:23 -07007812TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
7813 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
7814 // secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007815
Karl Schultz6addd812016-02-02 17:17:23 -07007816 m_errorMonitor->SetDesiredFailureMsg(
7817 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007818 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007819
7820 ASSERT_NO_FATAL_FAILURE(InitState());
7821 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007822
7823 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007824 // ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007825 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
7826 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007827
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007828 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007829}
7830
Tobin Ehlis17826bd2016-05-25 11:12:50 -06007831TEST_F(VkLayerTest, DSUsageBitsErrors) {
7832 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
7833 "that do not have correct usage bits sets.");
7834 VkResult err;
7835
7836 ASSERT_NO_FATAL_FAILURE(InitState());
7837 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
7838 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7839 ds_type_count[i].type = VkDescriptorType(i);
7840 ds_type_count[i].descriptorCount = 1;
7841 }
7842 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7843 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7844 ds_pool_ci.pNext = NULL;
7845 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7846 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7847 ds_pool_ci.pPoolSizes = ds_type_count;
7848
7849 VkDescriptorPool ds_pool;
7850 err =
7851 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7852 ASSERT_VK_SUCCESS(err);
7853
7854 // Create 10 layouts where each has a single descriptor of different type
7855 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] =
7856 {};
7857 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7858 dsl_binding[i].binding = 0;
7859 dsl_binding[i].descriptorType = VkDescriptorType(i);
7860 dsl_binding[i].descriptorCount = 1;
7861 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
7862 dsl_binding[i].pImmutableSamplers = NULL;
7863 }
7864
7865 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7866 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7867 ds_layout_ci.pNext = NULL;
7868 ds_layout_ci.bindingCount = 1;
7869 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
7870 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7871 ds_layout_ci.pBindings = dsl_binding + i;
7872 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci,
7873 NULL, ds_layouts + i);
7874 ASSERT_VK_SUCCESS(err);
7875 }
7876 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
7877 VkDescriptorSetAllocateInfo alloc_info = {};
7878 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7879 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7880 alloc_info.descriptorPool = ds_pool;
7881 alloc_info.pSetLayouts = ds_layouts;
7882 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7883 descriptor_sets);
7884 ASSERT_VK_SUCCESS(err);
7885
7886 // Create a buffer & bufferView to be used for invalid updates
7887 VkBufferCreateInfo buff_ci = {};
7888 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7889 // This usage is not valid for any descriptor type
7890 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
7891 buff_ci.size = 256;
7892 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7893 VkBuffer buffer;
7894 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7895 ASSERT_VK_SUCCESS(err);
7896
7897 VkBufferViewCreateInfo buff_view_ci = {};
7898 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7899 buff_view_ci.buffer = buffer;
7900 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7901 buff_view_ci.range = VK_WHOLE_SIZE;
7902 VkBufferView buff_view;
7903 err =
7904 vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
7905 ASSERT_VK_SUCCESS(err);
7906
7907 // Create an image to be used for invalid updates
7908 VkImageCreateInfo image_ci = {};
7909 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7910 image_ci.imageType = VK_IMAGE_TYPE_2D;
7911 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
7912 image_ci.extent.width = 64;
7913 image_ci.extent.height = 64;
7914 image_ci.extent.depth = 1;
7915 image_ci.mipLevels = 1;
7916 image_ci.arrayLayers = 1;
7917 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
7918 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
7919 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
7920 // This usage is not valid for any descriptor type
7921 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
7922 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7923 VkImage image;
7924 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
7925 ASSERT_VK_SUCCESS(err);
7926 // Bind memory to image
7927 VkMemoryRequirements mem_reqs;
7928 VkDeviceMemory image_mem;
7929 bool pass;
7930 VkMemoryAllocateInfo mem_alloc = {};
7931 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7932 mem_alloc.pNext = NULL;
7933 mem_alloc.allocationSize = 0;
7934 mem_alloc.memoryTypeIndex = 0;
7935 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
7936 mem_alloc.allocationSize = mem_reqs.size;
7937 pass =
7938 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
7939 ASSERT_TRUE(pass);
7940 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
7941 ASSERT_VK_SUCCESS(err);
7942 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
7943 ASSERT_VK_SUCCESS(err);
7944 // Now create view for image
7945 VkImageViewCreateInfo image_view_ci = {};
7946 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7947 image_view_ci.image = image;
7948 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
7949 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
7950 image_view_ci.subresourceRange.layerCount = 1;
7951 image_view_ci.subresourceRange.baseArrayLayer = 0;
7952 image_view_ci.subresourceRange.levelCount = 1;
7953 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7954 VkImageView image_view;
7955 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL,
7956 &image_view);
7957 ASSERT_VK_SUCCESS(err);
7958
7959 VkDescriptorBufferInfo buff_info = {};
7960 buff_info.buffer = buffer;
7961 VkDescriptorImageInfo img_info = {};
7962 img_info.imageView = image_view;
7963 VkWriteDescriptorSet descriptor_write = {};
7964 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7965 descriptor_write.dstBinding = 0;
7966 descriptor_write.descriptorCount = 1;
7967 descriptor_write.pTexelBufferView = &buff_view;
7968 descriptor_write.pBufferInfo = &buff_info;
7969 descriptor_write.pImageInfo = &img_info;
7970
7971 // These error messages align with VkDescriptorType struct
7972 const char *error_msgs[] = {
7973 "", // placeholder, no error for SAMPLER descriptor
7974 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
7975 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
7976 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
7977 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
7978 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
7979 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
7980 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
7981 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
7982 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
7983 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
7984 // Start loop at 1 as SAMPLER desc type has no usage bit error
7985 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7986 descriptor_write.descriptorType = VkDescriptorType(i);
7987 descriptor_write.dstSet = descriptor_sets[i];
7988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7989 error_msgs[i]);
7990
7991 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0,
7992 NULL);
7993
7994 m_errorMonitor->VerifyFound();
7995 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
7996 }
7997 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
7998 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007999 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008000 vkDestroyImageView(m_device->device(), image_view, NULL);
8001 vkDestroyBuffer(m_device->device(), buffer, NULL);
8002 vkDestroyBufferView(m_device->device(), buff_view, NULL);
8003 vkFreeDescriptorSets(m_device->device(), ds_pool,
8004 VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
8005 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8006}
8007
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008008TEST_F(VkLayerTest, DSAspectBitsErrors) {
8009 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8010 // are set, but could expand this test to hit more cases.
8011 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8012 "that do not have correct aspect bits sets.");
8013 VkResult err;
8014
8015 ASSERT_NO_FATAL_FAILURE(InitState());
8016 VkDescriptorPoolSize ds_type_count = {};
8017 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8018 ds_type_count.descriptorCount = 1;
8019
8020 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8021 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8022 ds_pool_ci.pNext = NULL;
8023 ds_pool_ci.maxSets = 5;
8024 ds_pool_ci.poolSizeCount = 1;
8025 ds_pool_ci.pPoolSizes = &ds_type_count;
8026
8027 VkDescriptorPool ds_pool;
8028 err =
8029 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
8030 ASSERT_VK_SUCCESS(err);
8031
8032 VkDescriptorSetLayoutBinding dsl_binding = {};
8033 dsl_binding.binding = 0;
8034 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8035 dsl_binding.descriptorCount = 1;
8036 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8037 dsl_binding.pImmutableSamplers = NULL;
8038
8039 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8040 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8041 ds_layout_ci.pNext = NULL;
8042 ds_layout_ci.bindingCount = 1;
8043 ds_layout_ci.pBindings = &dsl_binding;
8044 VkDescriptorSetLayout ds_layout;
8045 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8046 &ds_layout);
8047 ASSERT_VK_SUCCESS(err);
8048
8049 VkDescriptorSet descriptor_set = {};
8050 VkDescriptorSetAllocateInfo alloc_info = {};
8051 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8052 alloc_info.descriptorSetCount = 1;
8053 alloc_info.descriptorPool = ds_pool;
8054 alloc_info.pSetLayouts = &ds_layout;
8055 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8056 &descriptor_set);
8057 ASSERT_VK_SUCCESS(err);
8058
8059 // Create an image to be used for invalid updates
8060 VkImageCreateInfo image_ci = {};
8061 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8062 image_ci.imageType = VK_IMAGE_TYPE_2D;
8063 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8064 image_ci.extent.width = 64;
8065 image_ci.extent.height = 64;
8066 image_ci.extent.depth = 1;
8067 image_ci.mipLevels = 1;
8068 image_ci.arrayLayers = 1;
8069 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8070 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8071 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8072 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8073 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8074 VkImage image;
8075 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8076 ASSERT_VK_SUCCESS(err);
8077 // Bind memory to image
8078 VkMemoryRequirements mem_reqs;
8079 VkDeviceMemory image_mem;
8080 bool pass;
8081 VkMemoryAllocateInfo mem_alloc = {};
8082 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8083 mem_alloc.pNext = NULL;
8084 mem_alloc.allocationSize = 0;
8085 mem_alloc.memoryTypeIndex = 0;
8086 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8087 mem_alloc.allocationSize = mem_reqs.size;
8088 pass =
8089 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
8090 ASSERT_TRUE(pass);
8091 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8092 ASSERT_VK_SUCCESS(err);
8093 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8094 ASSERT_VK_SUCCESS(err);
8095 // Now create view for image
8096 VkImageViewCreateInfo image_view_ci = {};
8097 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8098 image_view_ci.image = image;
8099 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8100 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8101 image_view_ci.subresourceRange.layerCount = 1;
8102 image_view_ci.subresourceRange.baseArrayLayer = 0;
8103 image_view_ci.subresourceRange.levelCount = 1;
8104 // Setting both depth & stencil aspect bits is illegal for descriptor
8105 image_view_ci.subresourceRange.aspectMask =
8106 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
8107
8108 VkImageView image_view;
8109 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL,
8110 &image_view);
8111 ASSERT_VK_SUCCESS(err);
8112
8113 VkDescriptorImageInfo img_info = {};
8114 img_info.imageView = image_view;
8115 VkWriteDescriptorSet descriptor_write = {};
8116 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8117 descriptor_write.dstBinding = 0;
8118 descriptor_write.descriptorCount = 1;
8119 descriptor_write.pTexelBufferView = NULL;
8120 descriptor_write.pBufferInfo = NULL;
8121 descriptor_write.pImageInfo = &img_info;
8122 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8123 descriptor_write.dstSet = descriptor_set;
8124 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8125 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
8126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8127 error_msg);
8128
8129 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8130
8131 m_errorMonitor->VerifyFound();
8132 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8133 vkDestroyImage(m_device->device(), image, NULL);
8134 vkFreeMemory(m_device->device(), image_mem, NULL);
8135 vkDestroyImageView(m_device->device(), image_view, NULL);
8136 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8137 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8138}
8139
Karl Schultz6addd812016-02-02 17:17:23 -07008140TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008141 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008142 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008143
Karl Schultz6addd812016-02-02 17:17:23 -07008144 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008145 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8146 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8147 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008148
Tobin Ehlis3b780662015-05-28 12:11:26 -06008149 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008150 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008151 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008152 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8153 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008154
8155 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008156 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8157 ds_pool_ci.pNext = NULL;
8158 ds_pool_ci.maxSets = 1;
8159 ds_pool_ci.poolSizeCount = 1;
8160 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008161
Tobin Ehlis3b780662015-05-28 12:11:26 -06008162 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008163 err =
8164 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008165 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008166 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008167 dsl_binding.binding = 0;
8168 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8169 dsl_binding.descriptorCount = 1;
8170 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8171 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008172
Tony Barboureb254902015-07-15 12:50:33 -06008173 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008174 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8175 ds_layout_ci.pNext = NULL;
8176 ds_layout_ci.bindingCount = 1;
8177 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008178
Tobin Ehlis3b780662015-05-28 12:11:26 -06008179 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008180 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8181 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008182 ASSERT_VK_SUCCESS(err);
8183
8184 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008185 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008186 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008187 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008188 alloc_info.descriptorPool = ds_pool;
8189 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008190 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8191 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008192 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008193
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008194 VkSamplerCreateInfo sampler_ci = {};
8195 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8196 sampler_ci.pNext = NULL;
8197 sampler_ci.magFilter = VK_FILTER_NEAREST;
8198 sampler_ci.minFilter = VK_FILTER_NEAREST;
8199 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8200 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8201 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8202 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8203 sampler_ci.mipLodBias = 1.0;
8204 sampler_ci.anisotropyEnable = VK_FALSE;
8205 sampler_ci.maxAnisotropy = 1;
8206 sampler_ci.compareEnable = VK_FALSE;
8207 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8208 sampler_ci.minLod = 1.0;
8209 sampler_ci.maxLod = 1.0;
8210 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8211 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8212 VkSampler sampler;
8213 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8214 ASSERT_VK_SUCCESS(err);
8215
8216 VkDescriptorImageInfo info = {};
8217 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008218
8219 VkWriteDescriptorSet descriptor_write;
8220 memset(&descriptor_write, 0, sizeof(descriptor_write));
8221 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008222 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008223 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008224 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008225 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008226 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008227
8228 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8229
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008230 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008231
Chia-I Wuf7458c52015-10-26 21:10:41 +08008232 vkDestroySampler(m_device->device(), sampler, NULL);
8233 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8234 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008235}
8236
Karl Schultz6addd812016-02-02 17:17:23 -07008237TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008238 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008239 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008240
Karl Schultz6addd812016-02-02 17:17:23 -07008241 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008242 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8243 " binding #0 with 1 total descriptors but update of 1 descriptors "
8244 "starting at binding offset of 0 combined with update array element "
8245 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008246
Tobin Ehlis3b780662015-05-28 12:11:26 -06008247 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008248 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008249 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008250 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8251 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008252
8253 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008254 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8255 ds_pool_ci.pNext = NULL;
8256 ds_pool_ci.maxSets = 1;
8257 ds_pool_ci.poolSizeCount = 1;
8258 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008259
Tobin Ehlis3b780662015-05-28 12:11:26 -06008260 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008261 err =
8262 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008263 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008264
Tony Barboureb254902015-07-15 12:50:33 -06008265 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008266 dsl_binding.binding = 0;
8267 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8268 dsl_binding.descriptorCount = 1;
8269 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8270 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008271
8272 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008273 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8274 ds_layout_ci.pNext = NULL;
8275 ds_layout_ci.bindingCount = 1;
8276 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008277
Tobin Ehlis3b780662015-05-28 12:11:26 -06008278 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008279 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8280 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008281 ASSERT_VK_SUCCESS(err);
8282
8283 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008284 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008285 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008286 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008287 alloc_info.descriptorPool = ds_pool;
8288 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008289 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8290 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008291 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008292
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008293 // Correctly update descriptor to avoid "NOT_UPDATED" error
8294 VkDescriptorBufferInfo buff_info = {};
8295 buff_info.buffer =
8296 VkBuffer(0); // Don't care about buffer handle for this test
8297 buff_info.offset = 0;
8298 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008299
8300 VkWriteDescriptorSet descriptor_write;
8301 memset(&descriptor_write, 0, sizeof(descriptor_write));
8302 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008303 descriptor_write.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008304 descriptor_write.dstArrayElement =
8305 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008306 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008307 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8308 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008309
8310 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8311
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008312 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008313
Chia-I Wuf7458c52015-10-26 21:10:41 +08008314 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8315 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008316}
8317
Karl Schultz6addd812016-02-02 17:17:23 -07008318TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8319 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8320 // index 2
8321 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008322
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8324 " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008325
Tobin Ehlis3b780662015-05-28 12:11:26 -06008326 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008327 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008328 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008329 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8330 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008331
8332 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008333 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8334 ds_pool_ci.pNext = NULL;
8335 ds_pool_ci.maxSets = 1;
8336 ds_pool_ci.poolSizeCount = 1;
8337 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008338
Tobin Ehlis3b780662015-05-28 12:11:26 -06008339 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008340 err =
8341 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008342 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008343
Tony Barboureb254902015-07-15 12:50:33 -06008344 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008345 dsl_binding.binding = 0;
8346 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8347 dsl_binding.descriptorCount = 1;
8348 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8349 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008350
8351 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008352 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8353 ds_layout_ci.pNext = NULL;
8354 ds_layout_ci.bindingCount = 1;
8355 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008356 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008357 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8358 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008359 ASSERT_VK_SUCCESS(err);
8360
8361 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008362 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008363 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008364 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008365 alloc_info.descriptorPool = ds_pool;
8366 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008367 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8368 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008369 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008370
Tony Barboureb254902015-07-15 12:50:33 -06008371 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008372 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8373 sampler_ci.pNext = NULL;
8374 sampler_ci.magFilter = VK_FILTER_NEAREST;
8375 sampler_ci.minFilter = VK_FILTER_NEAREST;
8376 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8377 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8378 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8379 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8380 sampler_ci.mipLodBias = 1.0;
8381 sampler_ci.anisotropyEnable = VK_FALSE;
8382 sampler_ci.maxAnisotropy = 1;
8383 sampler_ci.compareEnable = VK_FALSE;
8384 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8385 sampler_ci.minLod = 1.0;
8386 sampler_ci.maxLod = 1.0;
8387 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8388 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06008389
Tobin Ehlis3b780662015-05-28 12:11:26 -06008390 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008391 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008392 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008393
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008394 VkDescriptorImageInfo info = {};
8395 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008396
8397 VkWriteDescriptorSet descriptor_write;
8398 memset(&descriptor_write, 0, sizeof(descriptor_write));
8399 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008400 descriptor_write.dstSet = descriptorSet;
8401 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008402 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008403 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008404 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008405 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008406
8407 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8408
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008409 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008410
Chia-I Wuf7458c52015-10-26 21:10:41 +08008411 vkDestroySampler(m_device->device(), sampler, NULL);
8412 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8413 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008414}
8415
Karl Schultz6addd812016-02-02 17:17:23 -07008416TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
8417 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
8418 // types
8419 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008420
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis660bcdc2016-05-17 10:39:46 -06008422 ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008423
Tobin Ehlis3b780662015-05-28 12:11:26 -06008424 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008425
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008426 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008427 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8428 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008429
8430 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008431 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8432 ds_pool_ci.pNext = NULL;
8433 ds_pool_ci.maxSets = 1;
8434 ds_pool_ci.poolSizeCount = 1;
8435 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008436
Tobin Ehlis3b780662015-05-28 12:11:26 -06008437 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008438 err =
8439 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008440 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008441 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008442 dsl_binding.binding = 0;
8443 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8444 dsl_binding.descriptorCount = 1;
8445 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8446 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008447
Tony Barboureb254902015-07-15 12:50:33 -06008448 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008449 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8450 ds_layout_ci.pNext = NULL;
8451 ds_layout_ci.bindingCount = 1;
8452 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008453
Tobin Ehlis3b780662015-05-28 12:11:26 -06008454 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008455 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8456 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008457 ASSERT_VK_SUCCESS(err);
8458
8459 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008460 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008461 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008462 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008463 alloc_info.descriptorPool = ds_pool;
8464 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008465 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8466 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008467 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008468
Tony Barboureb254902015-07-15 12:50:33 -06008469 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008470 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8471 sampler_ci.pNext = NULL;
8472 sampler_ci.magFilter = VK_FILTER_NEAREST;
8473 sampler_ci.minFilter = VK_FILTER_NEAREST;
8474 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8475 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8476 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8477 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8478 sampler_ci.mipLodBias = 1.0;
8479 sampler_ci.anisotropyEnable = VK_FALSE;
8480 sampler_ci.maxAnisotropy = 1;
8481 sampler_ci.compareEnable = VK_FALSE;
8482 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8483 sampler_ci.minLod = 1.0;
8484 sampler_ci.maxLod = 1.0;
8485 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8486 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008487 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008488 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008489 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008490
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008491 VkDescriptorImageInfo info = {};
8492 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008493
8494 VkWriteDescriptorSet descriptor_write;
8495 memset(&descriptor_write, 0, sizeof(descriptor_write));
Karl Schultz6addd812016-02-02 17:17:23 -07008496 descriptor_write.sType =
8497 (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008498 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008499 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008500 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008501 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008502 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008503
8504 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8505
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008506 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008507
Chia-I Wuf7458c52015-10-26 21:10:41 +08008508 vkDestroySampler(m_device->device(), sampler, NULL);
8509 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8510 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008511}
8512
Karl Schultz6addd812016-02-02 17:17:23 -07008513TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008514 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07008515 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008516
Karl Schultz6addd812016-02-02 17:17:23 -07008517 m_errorMonitor->SetDesiredFailureMsg(
8518 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008519 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008520
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008521 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008522 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
8523 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008524 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008525 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
8526 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008527
8528 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008529 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8530 ds_pool_ci.pNext = NULL;
8531 ds_pool_ci.maxSets = 1;
8532 ds_pool_ci.poolSizeCount = 1;
8533 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008534
8535 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008536 err =
8537 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008538 ASSERT_VK_SUCCESS(err);
8539
8540 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008541 dsl_binding.binding = 0;
8542 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8543 dsl_binding.descriptorCount = 1;
8544 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8545 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008546
8547 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008548 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8549 ds_layout_ci.pNext = NULL;
8550 ds_layout_ci.bindingCount = 1;
8551 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008552 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008553 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8554 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008555 ASSERT_VK_SUCCESS(err);
8556
8557 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008558 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008559 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008560 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008561 alloc_info.descriptorPool = ds_pool;
8562 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008563 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8564 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008565 ASSERT_VK_SUCCESS(err);
8566
Karl Schultz6addd812016-02-02 17:17:23 -07008567 VkSampler sampler =
8568 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008569
8570 VkDescriptorImageInfo descriptor_info;
8571 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8572 descriptor_info.sampler = sampler;
8573
8574 VkWriteDescriptorSet descriptor_write;
8575 memset(&descriptor_write, 0, sizeof(descriptor_write));
8576 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008577 descriptor_write.dstSet = descriptorSet;
8578 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008579 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008580 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8581 descriptor_write.pImageInfo = &descriptor_info;
8582
8583 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8584
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008585 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008586
Chia-I Wuf7458c52015-10-26 21:10:41 +08008587 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8588 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008589}
8590
Karl Schultz6addd812016-02-02 17:17:23 -07008591TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
8592 // Create a single combined Image/Sampler descriptor and send it an invalid
8593 // imageView
8594 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008595
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8597 "Attempted write update to combined "
8598 "image sampler descriptor failed due "
Tobin Ehlis63c4b8a2016-05-09 10:29:34 -06008599 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008600
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008601 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008602 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008603 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8604 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008605
8606 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008607 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8608 ds_pool_ci.pNext = NULL;
8609 ds_pool_ci.maxSets = 1;
8610 ds_pool_ci.poolSizeCount = 1;
8611 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008612
8613 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008614 err =
8615 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008616 ASSERT_VK_SUCCESS(err);
8617
8618 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008619 dsl_binding.binding = 0;
8620 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8621 dsl_binding.descriptorCount = 1;
8622 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8623 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008624
8625 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008626 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8627 ds_layout_ci.pNext = NULL;
8628 ds_layout_ci.bindingCount = 1;
8629 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008630 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008631 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8632 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008633 ASSERT_VK_SUCCESS(err);
8634
8635 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008636 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008637 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008638 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008639 alloc_info.descriptorPool = ds_pool;
8640 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008641 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8642 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008643 ASSERT_VK_SUCCESS(err);
8644
8645 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008646 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8647 sampler_ci.pNext = NULL;
8648 sampler_ci.magFilter = VK_FILTER_NEAREST;
8649 sampler_ci.minFilter = VK_FILTER_NEAREST;
8650 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8651 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8652 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8653 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8654 sampler_ci.mipLodBias = 1.0;
8655 sampler_ci.anisotropyEnable = VK_FALSE;
8656 sampler_ci.maxAnisotropy = 1;
8657 sampler_ci.compareEnable = VK_FALSE;
8658 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8659 sampler_ci.minLod = 1.0;
8660 sampler_ci.maxLod = 1.0;
8661 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8662 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008663
8664 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008665 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008666 ASSERT_VK_SUCCESS(err);
8667
Karl Schultz6addd812016-02-02 17:17:23 -07008668 VkImageView view =
8669 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008670
8671 VkDescriptorImageInfo descriptor_info;
8672 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8673 descriptor_info.sampler = sampler;
8674 descriptor_info.imageView = view;
8675
8676 VkWriteDescriptorSet descriptor_write;
8677 memset(&descriptor_write, 0, sizeof(descriptor_write));
8678 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008679 descriptor_write.dstSet = descriptorSet;
8680 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008681 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008682 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8683 descriptor_write.pImageInfo = &descriptor_info;
8684
8685 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8686
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008687 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008688
Chia-I Wuf7458c52015-10-26 21:10:41 +08008689 vkDestroySampler(m_device->device(), sampler, NULL);
8690 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8691 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008692}
8693
Karl Schultz6addd812016-02-02 17:17:23 -07008694TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
8695 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
8696 // into the other
8697 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008698
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8700 " binding #1 with type "
8701 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
8702 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008703
Tobin Ehlis04356f92015-10-27 16:35:27 -06008704 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008705 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008706 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008707 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8708 ds_type_count[0].descriptorCount = 1;
8709 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8710 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008711
8712 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008713 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8714 ds_pool_ci.pNext = NULL;
8715 ds_pool_ci.maxSets = 1;
8716 ds_pool_ci.poolSizeCount = 2;
8717 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008718
8719 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008720 err =
8721 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008722 ASSERT_VK_SUCCESS(err);
8723 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008724 dsl_binding[0].binding = 0;
8725 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8726 dsl_binding[0].descriptorCount = 1;
8727 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8728 dsl_binding[0].pImmutableSamplers = NULL;
8729 dsl_binding[1].binding = 1;
8730 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8731 dsl_binding[1].descriptorCount = 1;
8732 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8733 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008734
8735 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008736 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8737 ds_layout_ci.pNext = NULL;
8738 ds_layout_ci.bindingCount = 2;
8739 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008740
8741 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008742 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8743 &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008744 ASSERT_VK_SUCCESS(err);
8745
8746 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008747 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008748 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008749 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008750 alloc_info.descriptorPool = ds_pool;
8751 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008752 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8753 &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008754 ASSERT_VK_SUCCESS(err);
8755
8756 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008757 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8758 sampler_ci.pNext = NULL;
8759 sampler_ci.magFilter = VK_FILTER_NEAREST;
8760 sampler_ci.minFilter = VK_FILTER_NEAREST;
8761 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8762 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8763 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8764 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8765 sampler_ci.mipLodBias = 1.0;
8766 sampler_ci.anisotropyEnable = VK_FALSE;
8767 sampler_ci.maxAnisotropy = 1;
8768 sampler_ci.compareEnable = VK_FALSE;
8769 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8770 sampler_ci.minLod = 1.0;
8771 sampler_ci.maxLod = 1.0;
8772 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8773 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008774
8775 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008776 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008777 ASSERT_VK_SUCCESS(err);
8778
8779 VkDescriptorImageInfo info = {};
8780 info.sampler = sampler;
8781
8782 VkWriteDescriptorSet descriptor_write;
8783 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
8784 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008785 descriptor_write.dstSet = descriptorSet;
8786 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08008787 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008788 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8789 descriptor_write.pImageInfo = &info;
8790 // This write update should succeed
8791 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8792 // Now perform a copy update that fails due to type mismatch
8793 VkCopyDescriptorSet copy_ds_update;
8794 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8795 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8796 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06008797 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008798 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008799 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08008800 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06008801 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8802
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008803 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06008804 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07008805 m_errorMonitor->SetDesiredFailureMsg(
8806 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008807 " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -06008808 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8809 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8810 copy_ds_update.srcSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008811 copy_ds_update.srcBinding =
8812 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008813 copy_ds_update.dstSet = descriptorSet;
8814 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06008815 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06008816 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8817
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008818 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008819
Tobin Ehlis04356f92015-10-27 16:35:27 -06008820 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07008821 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008822 VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
8823 "update array offset of 0 and update of "
8824 "5 descriptors oversteps total number "
8825 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008826
Tobin Ehlis04356f92015-10-27 16:35:27 -06008827 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8828 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8829 copy_ds_update.srcSet = descriptorSet;
8830 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008831 copy_ds_update.dstSet = descriptorSet;
8832 copy_ds_update.dstBinding = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008833 copy_ds_update.descriptorCount =
8834 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06008835 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8836
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008837 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06008838
Chia-I Wuf7458c52015-10-26 21:10:41 +08008839 vkDestroySampler(m_device->device(), sampler, NULL);
8840 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8841 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008842}
8843
Karl Schultz6addd812016-02-02 17:17:23 -07008844TEST_F(VkLayerTest, NumSamplesMismatch) {
8845 // Create CommandBuffer where MSAA samples doesn't match RenderPass
8846 // sampleCount
8847 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008848
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008850 "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008851
Tobin Ehlis3b780662015-05-28 12:11:26 -06008852 ASSERT_NO_FATAL_FAILURE(InitState());
8853 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008854 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06008855 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008856 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008857
8858 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008859 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8860 ds_pool_ci.pNext = NULL;
8861 ds_pool_ci.maxSets = 1;
8862 ds_pool_ci.poolSizeCount = 1;
8863 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008864
Tobin Ehlis3b780662015-05-28 12:11:26 -06008865 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008866 err =
8867 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008868 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008869
Tony Barboureb254902015-07-15 12:50:33 -06008870 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08008871 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06008872 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08008873 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008874 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8875 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008876
Tony Barboureb254902015-07-15 12:50:33 -06008877 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8878 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8879 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008880 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008881 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008882
Tobin Ehlis3b780662015-05-28 12:11:26 -06008883 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008884 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8885 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008886 ASSERT_VK_SUCCESS(err);
8887
8888 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008889 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008890 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008891 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008892 alloc_info.descriptorPool = ds_pool;
8893 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008894 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8895 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008896 ASSERT_VK_SUCCESS(err);
8897
Tony Barboureb254902015-07-15 12:50:33 -06008898 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008899 pipe_ms_state_ci.sType =
8900 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8901 pipe_ms_state_ci.pNext = NULL;
8902 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8903 pipe_ms_state_ci.sampleShadingEnable = 0;
8904 pipe_ms_state_ci.minSampleShading = 1.0;
8905 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008906
Tony Barboureb254902015-07-15 12:50:33 -06008907 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008908 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8909 pipeline_layout_ci.pNext = NULL;
8910 pipeline_layout_ci.setLayoutCount = 1;
8911 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008912
8913 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008914 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8915 &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008916 ASSERT_VK_SUCCESS(err);
8917
Karl Schultz6addd812016-02-02 17:17:23 -07008918 VkShaderObj vs(m_device, bindStateVertShaderText,
8919 VK_SHADER_STAGE_VERTEX_BIT, this);
8920 VkShaderObj fs(m_device, bindStateFragShaderText,
8921 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06008922 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07008923 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008924 VkPipelineObj pipe(m_device);
8925 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008926 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06008927 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008928 pipe.SetMSAA(&pipe_ms_state_ci);
8929 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06008930
Tony Barbourfe3351b2015-07-28 10:17:20 -06008931 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008932 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8933 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06008934
Mark Young29927482016-05-04 14:38:51 -06008935 // Render triangle (the error should trigger on the attempt to draw).
8936 Draw(3, 1, 0, 0);
8937
8938 // Finalize recording of the command buffer
8939 EndCommandBuffer();
8940
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008941 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008942
Chia-I Wuf7458c52015-10-26 21:10:41 +08008943 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8944 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8945 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008946}
Mark Young29927482016-05-04 14:38:51 -06008947
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06008948TEST_F(VkLayerTest, RenderPassIncompatible) {
8949 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
8950 "Initial case is drawing with an active renderpass that's "
8951 "not compatible with the bound PSO's creation renderpass");
8952 VkResult err;
8953
8954 ASSERT_NO_FATAL_FAILURE(InitState());
8955 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8956
8957 VkDescriptorSetLayoutBinding dsl_binding = {};
8958 dsl_binding.binding = 0;
8959 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8960 dsl_binding.descriptorCount = 1;
8961 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8962 dsl_binding.pImmutableSamplers = NULL;
8963
8964 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8965 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8966 ds_layout_ci.pNext = NULL;
8967 ds_layout_ci.bindingCount = 1;
8968 ds_layout_ci.pBindings = &dsl_binding;
8969
8970 VkDescriptorSetLayout ds_layout;
8971 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8972 &ds_layout);
8973 ASSERT_VK_SUCCESS(err);
8974
8975 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8976 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8977 pipeline_layout_ci.pNext = NULL;
8978 pipeline_layout_ci.setLayoutCount = 1;
8979 pipeline_layout_ci.pSetLayouts = &ds_layout;
8980
8981 VkPipelineLayout pipeline_layout;
8982 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8983 &pipeline_layout);
8984 ASSERT_VK_SUCCESS(err);
8985
8986 VkShaderObj vs(m_device, bindStateVertShaderText,
8987 VK_SHADER_STAGE_VERTEX_BIT, this);
8988 VkShaderObj fs(m_device, bindStateFragShaderText,
8989 VK_SHADER_STAGE_FRAGMENT_BIT,
8990 this); // We shouldn't need a fragment shader
8991 // but add it to be able to run on more devices
8992 // Create a renderpass that will be incompatible with default renderpass
8993 VkAttachmentReference attach = {};
8994 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8995 VkAttachmentReference color_att = {};
8996 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8997 VkSubpassDescription subpass = {};
8998 subpass.inputAttachmentCount = 1;
8999 subpass.pInputAttachments = &attach;
9000 subpass.colorAttachmentCount = 1;
9001 subpass.pColorAttachments = &color_att;
9002 VkRenderPassCreateInfo rpci = {};
9003 rpci.subpassCount = 1;
9004 rpci.pSubpasses = &subpass;
9005 rpci.attachmentCount = 1;
9006 VkAttachmentDescription attach_desc = {};
9007 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009008 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9009 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009010 rpci.pAttachments = &attach_desc;
9011 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9012 VkRenderPass rp;
9013 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9014 VkPipelineObj pipe(m_device);
9015 pipe.AddShader(&vs);
9016 pipe.AddShader(&fs);
9017 pipe.AddColorAttachment();
9018 VkViewport view_port = {};
9019 m_viewports.push_back(view_port);
9020 pipe.SetViewport(m_viewports);
9021 VkRect2D rect = {};
9022 m_scissors.push_back(rect);
9023 pipe.SetScissor(m_scissors);
9024 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9025
9026 VkCommandBufferInheritanceInfo cbii = {};
9027 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9028 cbii.renderPass = rp;
9029 cbii.subpass = 0;
9030 VkCommandBufferBeginInfo cbbi = {};
9031 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9032 cbbi.pInheritanceInfo = &cbii;
9033 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9034 VkRenderPassBeginInfo rpbi = {};
9035 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9036 rpbi.framebuffer = m_framebuffer;
9037 rpbi.renderPass = rp;
9038 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi,
9039 VK_SUBPASS_CONTENTS_INLINE);
9040 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9041 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
9042
9043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9044 " is incompatible w/ gfx pipeline ");
9045 // Render triangle (the error should trigger on the attempt to draw).
9046 Draw(3, 1, 0, 0);
9047
9048 // Finalize recording of the command buffer
9049 EndCommandBuffer();
9050
9051 m_errorMonitor->VerifyFound();
9052
9053 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9054 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9055 vkDestroyRenderPass(m_device->device(), rp, NULL);
9056}
9057
Mark Youngc89c6312016-03-31 16:03:20 -06009058TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9059 // Create Pipeline where the number of blend attachments doesn't match the
9060 // number of color attachments. In this case, we don't add any color
9061 // blend attachments even though we have a color attachment.
9062 VkResult err;
9063
9064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young29927482016-05-04 14:38:51 -06009065 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009066
9067 ASSERT_NO_FATAL_FAILURE(InitState());
9068 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9069 VkDescriptorPoolSize ds_type_count = {};
9070 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9071 ds_type_count.descriptorCount = 1;
9072
9073 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9074 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9075 ds_pool_ci.pNext = NULL;
9076 ds_pool_ci.maxSets = 1;
9077 ds_pool_ci.poolSizeCount = 1;
9078 ds_pool_ci.pPoolSizes = &ds_type_count;
9079
9080 VkDescriptorPool ds_pool;
9081 err =
9082 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9083 ASSERT_VK_SUCCESS(err);
9084
9085 VkDescriptorSetLayoutBinding dsl_binding = {};
9086 dsl_binding.binding = 0;
9087 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9088 dsl_binding.descriptorCount = 1;
9089 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9090 dsl_binding.pImmutableSamplers = NULL;
9091
9092 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9093 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9094 ds_layout_ci.pNext = NULL;
9095 ds_layout_ci.bindingCount = 1;
9096 ds_layout_ci.pBindings = &dsl_binding;
9097
9098 VkDescriptorSetLayout ds_layout;
9099 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9100 &ds_layout);
9101 ASSERT_VK_SUCCESS(err);
9102
9103 VkDescriptorSet descriptorSet;
9104 VkDescriptorSetAllocateInfo alloc_info = {};
9105 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9106 alloc_info.descriptorSetCount = 1;
9107 alloc_info.descriptorPool = ds_pool;
9108 alloc_info.pSetLayouts = &ds_layout;
9109 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9110 &descriptorSet);
9111 ASSERT_VK_SUCCESS(err);
9112
9113 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
9114 pipe_ms_state_ci.sType =
9115 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9116 pipe_ms_state_ci.pNext = NULL;
9117 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9118 pipe_ms_state_ci.sampleShadingEnable = 0;
9119 pipe_ms_state_ci.minSampleShading = 1.0;
9120 pipe_ms_state_ci.pSampleMask = NULL;
9121
9122 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9123 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9124 pipeline_layout_ci.pNext = NULL;
9125 pipeline_layout_ci.setLayoutCount = 1;
9126 pipeline_layout_ci.pSetLayouts = &ds_layout;
9127
9128 VkPipelineLayout pipeline_layout;
9129 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9130 &pipeline_layout);
9131 ASSERT_VK_SUCCESS(err);
9132
9133 VkShaderObj vs(m_device, bindStateVertShaderText,
9134 VK_SHADER_STAGE_VERTEX_BIT, this);
9135 VkShaderObj fs(m_device, bindStateFragShaderText,
9136 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06009137 this); // We shouldn't need a fragment shader
Mark Youngc89c6312016-03-31 16:03:20 -06009138 // but add it to be able to run on more devices
9139 VkPipelineObj pipe(m_device);
9140 pipe.AddShader(&vs);
9141 pipe.AddShader(&fs);
9142 pipe.SetMSAA(&pipe_ms_state_ci);
9143 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9144
9145 BeginCommandBuffer();
9146 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9147 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
9148
Mark Young29927482016-05-04 14:38:51 -06009149 // Render triangle (the error should trigger on the attempt to draw).
9150 Draw(3, 1, 0, 0);
9151
9152 // Finalize recording of the command buffer
9153 EndCommandBuffer();
9154
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009155 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009156
9157 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9158 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9159 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9160}
Mark Young29927482016-05-04 14:38:51 -06009161
Mark Muellerd4914412016-06-13 17:52:06 -06009162TEST_F(VkLayerTest, MissingClearAttachment) {
9163 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9164 "structure passed to vkCmdClearAttachments");
9165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9166 "vkCmdClearAttachments() attachment index 1 not found in attachment "
9167 "reference array of active subpass 0");
9168
9169 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9170 m_errorMonitor->VerifyFound();
9171}
9172
Karl Schultz6addd812016-02-02 17:17:23 -07009173TEST_F(VkLayerTest, ClearCmdNoDraw) {
9174 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9175 // to issuing a Draw
9176 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009177
Karl Schultz6addd812016-02-02 17:17:23 -07009178 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbour7e56d302016-03-02 15:12:01 -07009179 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009180 "vkCmdClearAttachments() issued on CB object ");
9181
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009182 ASSERT_NO_FATAL_FAILURE(InitState());
9183 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009184
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009185 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009186 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9187 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009188
9189 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009190 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9191 ds_pool_ci.pNext = NULL;
9192 ds_pool_ci.maxSets = 1;
9193 ds_pool_ci.poolSizeCount = 1;
9194 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009195
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009196 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009197 err =
9198 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009199 ASSERT_VK_SUCCESS(err);
9200
Tony Barboureb254902015-07-15 12:50:33 -06009201 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009202 dsl_binding.binding = 0;
9203 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9204 dsl_binding.descriptorCount = 1;
9205 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9206 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009207
Tony Barboureb254902015-07-15 12:50:33 -06009208 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009209 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9210 ds_layout_ci.pNext = NULL;
9211 ds_layout_ci.bindingCount = 1;
9212 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009213
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009214 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009215 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9216 &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009217 ASSERT_VK_SUCCESS(err);
9218
9219 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009220 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009221 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009222 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009223 alloc_info.descriptorPool = ds_pool;
9224 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009225 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9226 &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009227 ASSERT_VK_SUCCESS(err);
9228
Tony Barboureb254902015-07-15 12:50:33 -06009229 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009230 pipe_ms_state_ci.sType =
9231 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9232 pipe_ms_state_ci.pNext = NULL;
9233 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9234 pipe_ms_state_ci.sampleShadingEnable = 0;
9235 pipe_ms_state_ci.minSampleShading = 1.0;
9236 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009237
Tony Barboureb254902015-07-15 12:50:33 -06009238 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009239 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9240 pipeline_layout_ci.pNext = NULL;
9241 pipeline_layout_ci.setLayoutCount = 1;
9242 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009243
9244 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009245 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9246 &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009247 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009248
Karl Schultz6addd812016-02-02 17:17:23 -07009249 VkShaderObj vs(m_device, bindStateVertShaderText,
9250 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009251 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009252 // on more devices
9253 VkShaderObj fs(m_device, bindStateFragShaderText,
9254 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009255
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009256 VkPipelineObj pipe(m_device);
9257 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009258 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009259 pipe.SetMSAA(&pipe_ms_state_ci);
9260 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009261
9262 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009263
Karl Schultz6addd812016-02-02 17:17:23 -07009264 // Main thing we care about for this test is that the VkImage obj we're
9265 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009266 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009267 VkClearAttachment color_attachment;
9268 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9269 color_attachment.clearValue.color.float32[0] = 1.0;
9270 color_attachment.clearValue.color.float32[1] = 1.0;
9271 color_attachment.clearValue.color.float32[2] = 1.0;
9272 color_attachment.clearValue.color.float32[3] = 1.0;
9273 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009274 VkClearRect clear_rect = {
9275 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009276
Karl Schultz6addd812016-02-02 17:17:23 -07009277 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
9278 &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009279
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009280 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009281
Chia-I Wuf7458c52015-10-26 21:10:41 +08009282 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9283 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9284 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009285}
9286
Karl Schultz6addd812016-02-02 17:17:23 -07009287TEST_F(VkLayerTest, VtxBufferBadIndex) {
9288 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009289
Karl Schultz6addd812016-02-02 17:17:23 -07009290 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009291 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07009292 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009293
Tobin Ehlis502480b2015-06-24 15:53:07 -06009294 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009295 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009297
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009298 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009299 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9300 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009301
9302 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009303 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9304 ds_pool_ci.pNext = NULL;
9305 ds_pool_ci.maxSets = 1;
9306 ds_pool_ci.poolSizeCount = 1;
9307 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009308
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009309 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009310 err =
9311 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009312 ASSERT_VK_SUCCESS(err);
9313
Tony Barboureb254902015-07-15 12:50:33 -06009314 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009315 dsl_binding.binding = 0;
9316 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9317 dsl_binding.descriptorCount = 1;
9318 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9319 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009320
Tony Barboureb254902015-07-15 12:50:33 -06009321 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009322 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9323 ds_layout_ci.pNext = NULL;
9324 ds_layout_ci.bindingCount = 1;
9325 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009326
Tobin Ehlis502480b2015-06-24 15:53:07 -06009327 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009328 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9329 &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009330 ASSERT_VK_SUCCESS(err);
9331
9332 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009333 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009334 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009335 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009336 alloc_info.descriptorPool = ds_pool;
9337 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009338 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9339 &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009340 ASSERT_VK_SUCCESS(err);
9341
Tony Barboureb254902015-07-15 12:50:33 -06009342 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009343 pipe_ms_state_ci.sType =
9344 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9345 pipe_ms_state_ci.pNext = NULL;
9346 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9347 pipe_ms_state_ci.sampleShadingEnable = 0;
9348 pipe_ms_state_ci.minSampleShading = 1.0;
9349 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009350
Tony Barboureb254902015-07-15 12:50:33 -06009351 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009352 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9353 pipeline_layout_ci.pNext = NULL;
9354 pipeline_layout_ci.setLayoutCount = 1;
9355 pipeline_layout_ci.pSetLayouts = &ds_layout;
9356 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009357
Karl Schultz6addd812016-02-02 17:17:23 -07009358 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9359 &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009360 ASSERT_VK_SUCCESS(err);
9361
Karl Schultz6addd812016-02-02 17:17:23 -07009362 VkShaderObj vs(m_device, bindStateVertShaderText,
9363 VK_SHADER_STAGE_VERTEX_BIT, this);
9364 VkShaderObj fs(m_device, bindStateFragShaderText,
9365 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06009366 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07009367 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009368 VkPipelineObj pipe(m_device);
9369 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009370 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009371 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009372 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009373 pipe.SetViewport(m_viewports);
9374 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009375 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009376
9377 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009378 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9379 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009380 // Don't care about actual data, just need to get to draw to flag error
9381 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz6addd812016-02-02 17:17:23 -07009382 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
9383 (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009384 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009385 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009386
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009387 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009388
Chia-I Wuf7458c52015-10-26 21:10:41 +08009389 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9390 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9391 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009392}
Mark Mueller979ba7b2016-06-22 19:40:33 -06009393
9394TEST_F(VkLayerTest, VertexBufferInvalid) {
9395 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer");
9396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9397 "Cannot submit cmd buffer using deleted buffer ");
9398
9399 ASSERT_NO_FATAL_FAILURE(InitState());
9400 ASSERT_NO_FATAL_FAILURE(InitViewport());
9401 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9402
9403 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
9404 pipe_ms_state_ci.sType =
9405 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9406 pipe_ms_state_ci.pNext = NULL;
9407 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9408 pipe_ms_state_ci.sampleShadingEnable = 0;
9409 pipe_ms_state_ci.minSampleShading = 1.0;
9410 pipe_ms_state_ci.pSampleMask = nullptr;
9411
9412 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9413 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9414 VkPipelineLayout pipeline_layout;
9415
9416 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
9417 ASSERT_VK_SUCCESS(err);
9418
9419 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9420 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9421 // but add it to be able to run on more devices
9422 VkPipelineObj pipe(m_device);
9423 pipe.AddShader(&vs);
9424 pipe.AddShader(&fs);
9425 pipe.AddColorAttachment();
9426 pipe.SetMSAA(&pipe_ms_state_ci);
9427 pipe.SetViewport(m_viewports);
9428 pipe.SetScissor(m_scissors);
9429 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9430
9431 BeginCommandBuffer();
9432 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
9433
9434 {
9435 // Create and bind a vertex buffer in a reduced scope, which will cause it to be deleted opon leaving this scope
9436 static const float vbo_data[3] = {1.f, 0.f, 1.f};
9437 cVertices draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
9438 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
9439 draw_verticies.AddVertexInputToPipe(pipe);
9440 }
9441
9442 Draw(1, 0, 0, 0);
9443
9444 EndCommandBuffer();
9445 QueueCommandBuffer(false);
9446 m_errorMonitor->VerifyFound();
9447
9448 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9449}
9450
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009451// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
9452TEST_F(VkLayerTest, InvalidImageLayout) {
9453 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
9454 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
9455 "images in the wrong layout when they're copied or transitioned.");
9456 // 3 in ValidateCmdBufImageLayouts
9457 // * -1 Attempt to submit cmd buf w/ deleted image
9458 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
9459 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
9460 m_errorMonitor->SetDesiredFailureMsg(
9461 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9462 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
9463
9464 ASSERT_NO_FATAL_FAILURE(InitState());
9465 // Create src & dst images to use for copy operations
9466 VkImage src_image;
9467 VkImage dst_image;
9468
9469 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9470 const int32_t tex_width = 32;
9471 const int32_t tex_height = 32;
9472
9473 VkImageCreateInfo image_create_info = {};
9474 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9475 image_create_info.pNext = NULL;
9476 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9477 image_create_info.format = tex_format;
9478 image_create_info.extent.width = tex_width;
9479 image_create_info.extent.height = tex_height;
9480 image_create_info.extent.depth = 1;
9481 image_create_info.mipLevels = 1;
9482 image_create_info.arrayLayers = 4;
9483 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9484 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9485 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
9486 image_create_info.flags = 0;
9487
9488 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
9489 ASSERT_VK_SUCCESS(err);
9490 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
9491 ASSERT_VK_SUCCESS(err);
9492
9493 BeginCommandBuffer();
9494 VkImageCopy copyRegion;
9495 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9496 copyRegion.srcSubresource.mipLevel = 0;
9497 copyRegion.srcSubresource.baseArrayLayer = 0;
9498 copyRegion.srcSubresource.layerCount = 1;
9499 copyRegion.srcOffset.x = 0;
9500 copyRegion.srcOffset.y = 0;
9501 copyRegion.srcOffset.z = 0;
9502 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9503 copyRegion.dstSubresource.mipLevel = 0;
9504 copyRegion.dstSubresource.baseArrayLayer = 0;
9505 copyRegion.dstSubresource.layerCount = 1;
9506 copyRegion.dstOffset.x = 0;
9507 copyRegion.dstOffset.y = 0;
9508 copyRegion.dstOffset.z = 0;
9509 copyRegion.extent.width = 1;
9510 copyRegion.extent.height = 1;
9511 copyRegion.extent.depth = 1;
9512 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9513 m_errorMonitor->VerifyFound();
9514 // Now cause error due to src image layout changing
9515 m_errorMonitor->SetDesiredFailureMsg(
9516 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9517 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9518 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9519 m_errorMonitor->VerifyFound();
9520 // Final src error is due to bad layout type
9521 m_errorMonitor->SetDesiredFailureMsg(
9522 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9523 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
9524 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9525 m_errorMonitor->VerifyFound();
9526 // Now verify same checks for dst
9527 m_errorMonitor->SetDesiredFailureMsg(
9528 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9529 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
9530 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9531 m_errorMonitor->VerifyFound();
9532 // Now cause error due to src image layout changing
9533 m_errorMonitor->SetDesiredFailureMsg(
9534 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9535 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9536 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9537 m_errorMonitor->VerifyFound();
9538 m_errorMonitor->SetDesiredFailureMsg(
9539 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9540 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
9541 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9542 m_errorMonitor->VerifyFound();
9543 // Now cause error due to bad image layout transition in PipelineBarrier
9544 VkImageMemoryBarrier image_barrier[1] = {};
9545 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9546 image_barrier[0].image = src_image;
9547 image_barrier[0].subresourceRange.layerCount = 2;
9548 image_barrier[0].subresourceRange.levelCount = 2;
9549 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9550 m_errorMonitor->SetDesiredFailureMsg(
9551 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9552 "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL.");
9553 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier);
9554 m_errorMonitor->VerifyFound();
9555
9556 // Finally some layout errors at RenderPass create time
9557 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
9558 VkAttachmentReference attach = {};
9559 // perf warning for GENERAL layout w/ non-DS input attachment
9560 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9561 VkSubpassDescription subpass = {};
9562 subpass.inputAttachmentCount = 1;
9563 subpass.pInputAttachments = &attach;
9564 VkRenderPassCreateInfo rpci = {};
9565 rpci.subpassCount = 1;
9566 rpci.pSubpasses = &subpass;
9567 rpci.attachmentCount = 1;
9568 VkAttachmentDescription attach_desc = {};
9569 attach_desc.format = VK_FORMAT_UNDEFINED;
9570 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -06009571 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009572 VkRenderPass rp;
9573 m_errorMonitor->SetDesiredFailureMsg(
9574 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9575 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
9576 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9577 m_errorMonitor->VerifyFound();
9578 // error w/ non-general layout
9579 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9580
9581 m_errorMonitor->SetDesiredFailureMsg(
9582 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9583 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
9584 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9585 m_errorMonitor->VerifyFound();
9586 subpass.inputAttachmentCount = 0;
9587 subpass.colorAttachmentCount = 1;
9588 subpass.pColorAttachments = &attach;
9589 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9590 // perf warning for GENERAL layout on color attachment
9591 m_errorMonitor->SetDesiredFailureMsg(
9592 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9593 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
9594 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9595 m_errorMonitor->VerifyFound();
9596 // error w/ non-color opt or GENERAL layout for color attachment
9597 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9598 m_errorMonitor->SetDesiredFailureMsg(
9599 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9600 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
9601 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9602 m_errorMonitor->VerifyFound();
9603 subpass.colorAttachmentCount = 0;
9604 subpass.pDepthStencilAttachment = &attach;
9605 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9606 // perf warning for GENERAL layout on DS attachment
9607 m_errorMonitor->SetDesiredFailureMsg(
9608 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9609 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
9610 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9611 m_errorMonitor->VerifyFound();
9612 // error w/ non-ds opt or GENERAL layout for color attachment
9613 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9614 m_errorMonitor->SetDesiredFailureMsg(
9615 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9616 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.");
9617 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9618 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -06009619 // For this error we need a valid renderpass so create default one
9620 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9621 attach.attachment = 0;
9622 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
9623 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
9624 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
9625 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
9626 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
9627 // Can't do a CLEAR load on READ_ONLY initialLayout
9628 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9629 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9630 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9632 " with invalid first layout "
9633 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
9634 "ONLY_OPTIMAL");
9635 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9636 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009637
9638 vkDestroyImage(m_device->device(), src_image, NULL);
9639 vkDestroyImage(m_device->device(), dst_image, NULL);
9640}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009641#endif // DRAW_STATE_TESTS
9642
Tobin Ehlis0788f522015-05-26 16:11:58 -06009643#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06009644#if GTEST_IS_THREADSAFE
9645struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009646 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009647 VkEvent event;
9648 bool bailout;
9649};
9650
Karl Schultz6addd812016-02-02 17:17:23 -07009651extern "C" void *AddToCommandBuffer(void *arg) {
9652 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009653
Karl Schultz6addd812016-02-02 17:17:23 -07009654 for (int i = 0; i < 10000; i++) {
9655 vkCmdSetEvent(data->commandBuffer, data->event,
9656 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009657 if (data->bailout) {
9658 break;
9659 }
9660 }
9661 return NULL;
9662}
9663
Karl Schultz6addd812016-02-02 17:17:23 -07009664TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009665 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009666
Karl Schultz6addd812016-02-02 17:17:23 -07009667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9668 "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009669
Mike Stroyanaccf7692015-05-12 16:00:45 -06009670 ASSERT_NO_FATAL_FAILURE(InitState());
9671 ASSERT_NO_FATAL_FAILURE(InitViewport());
9672 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9673
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009674 // Calls AllocateCommandBuffers
9675 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009676
9677 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009678 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009679
9680 VkEventCreateInfo event_info;
9681 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009682 VkResult err;
9683
9684 memset(&event_info, 0, sizeof(event_info));
9685 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9686
Chia-I Wuf7458c52015-10-26 21:10:41 +08009687 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009688 ASSERT_VK_SUCCESS(err);
9689
Mike Stroyanaccf7692015-05-12 16:00:45 -06009690 err = vkResetEvent(device(), event);
9691 ASSERT_VK_SUCCESS(err);
9692
9693 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009694 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009695 data.event = event;
9696 data.bailout = false;
9697 m_errorMonitor->SetBailout(&data.bailout);
9698 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009699 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009700 // Add many entries to command buffer from this thread at the same time.
9701 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009702
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009703 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009704 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009705
Mike Stroyan10b8cb72016-01-22 15:22:03 -07009706 m_errorMonitor->SetBailout(NULL);
9707
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009708 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009709
Chia-I Wuf7458c52015-10-26 21:10:41 +08009710 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009711}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009712#endif // GTEST_IS_THREADSAFE
9713#endif // THREADING_TESTS
9714
Chris Forbes9f7ff632015-05-25 11:13:08 +12009715#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07009716TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009718 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009719
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009720 ASSERT_NO_FATAL_FAILURE(InitState());
9721 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9722
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009723 VkShaderModule module;
9724 VkShaderModuleCreateInfo moduleCreateInfo;
9725 struct icd_spv_header spv;
9726
9727 spv.magic = ICD_SPV_MAGIC;
9728 spv.version = ICD_SPV_VERSION;
9729 spv.gen_magic = 0;
9730
9731 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9732 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009733 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009734 moduleCreateInfo.codeSize = 4;
9735 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009736 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009737
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009738 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009739}
9740
Karl Schultz6addd812016-02-02 17:17:23 -07009741TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009743 "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009744
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009745 ASSERT_NO_FATAL_FAILURE(InitState());
9746 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9747
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009748 VkShaderModule module;
9749 VkShaderModuleCreateInfo moduleCreateInfo;
9750 struct icd_spv_header spv;
9751
9752 spv.magic = ~ICD_SPV_MAGIC;
9753 spv.version = ICD_SPV_VERSION;
9754 spv.gen_magic = 0;
9755
9756 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9757 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009758 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009759 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9760 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009761 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009762
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009763 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009764}
9765
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009766#if 0
9767// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -07009768TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009770 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009771
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009772 ASSERT_NO_FATAL_FAILURE(InitState());
9773 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9774
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009775 VkShaderModule module;
9776 VkShaderModuleCreateInfo moduleCreateInfo;
9777 struct icd_spv_header spv;
9778
9779 spv.magic = ICD_SPV_MAGIC;
9780 spv.version = ~ICD_SPV_VERSION;
9781 spv.gen_magic = 0;
9782
9783 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9784 moduleCreateInfo.pNext = NULL;
9785
Karl Schultz6addd812016-02-02 17:17:23 -07009786 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009787 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9788 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009789 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009790
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009791 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009792}
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009793#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009794
Karl Schultz6addd812016-02-02 17:17:23 -07009795TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009797 "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009798
Chris Forbes9f7ff632015-05-25 11:13:08 +12009799 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009800 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009801
9802 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009803 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009804 "\n"
9805 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009806 "out gl_PerVertex {\n"
9807 " vec4 gl_Position;\n"
9808 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009809 "void main(){\n"
9810 " gl_Position = vec4(1);\n"
9811 " x = 0;\n"
9812 "}\n";
9813 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009814 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009815 "\n"
9816 "layout(location=0) out vec4 color;\n"
9817 "void main(){\n"
9818 " color = vec4(1);\n"
9819 "}\n";
9820
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009821 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9822 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009823
9824 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009825 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009826 pipe.AddShader(&vs);
9827 pipe.AddShader(&fs);
9828
Chris Forbes9f7ff632015-05-25 11:13:08 +12009829 VkDescriptorSetObj descriptorSet(m_device);
9830 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009831 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009832
Tony Barbour5781e8f2015-08-04 16:23:11 -06009833 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009834
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009835 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009836}
Chris Forbes9f7ff632015-05-25 11:13:08 +12009837
Karl Schultz6addd812016-02-02 17:17:23 -07009838TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009840 "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009841
Chris Forbes59cb88d2015-05-25 11:13:13 +12009842 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009843 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009844
9845 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009846 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009847 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009848 "out gl_PerVertex {\n"
9849 " vec4 gl_Position;\n"
9850 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009851 "void main(){\n"
9852 " gl_Position = vec4(1);\n"
9853 "}\n";
9854 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009855 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009856 "\n"
9857 "layout(location=0) in float x;\n"
9858 "layout(location=0) out vec4 color;\n"
9859 "void main(){\n"
9860 " color = vec4(x);\n"
9861 "}\n";
9862
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009863 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9864 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009865
9866 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009867 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009868 pipe.AddShader(&vs);
9869 pipe.AddShader(&fs);
9870
Chris Forbes59cb88d2015-05-25 11:13:13 +12009871 VkDescriptorSetObj descriptorSet(m_device);
9872 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009873 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009874
Tony Barbour5781e8f2015-08-04 16:23:11 -06009875 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009876
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009877 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009878}
9879
Karl Schultz6addd812016-02-02 17:17:23 -07009880TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009882 "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009883
9884 ASSERT_NO_FATAL_FAILURE(InitState());
9885 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9886
9887 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009888 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009889 "\n"
9890 "out gl_PerVertex {\n"
9891 " vec4 gl_Position;\n"
9892 "};\n"
9893 "void main(){\n"
9894 " gl_Position = vec4(1);\n"
9895 "}\n";
9896 char const *fsSource =
9897 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009898 "\n"
9899 "in block { layout(location=0) float x; } ins;\n"
9900 "layout(location=0) out vec4 color;\n"
9901 "void main(){\n"
9902 " color = vec4(ins.x);\n"
9903 "}\n";
9904
9905 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9906 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9907
9908 VkPipelineObj pipe(m_device);
9909 pipe.AddColorAttachment();
9910 pipe.AddShader(&vs);
9911 pipe.AddShader(&fs);
9912
9913 VkDescriptorSetObj descriptorSet(m_device);
9914 descriptorSet.AppendDummy();
9915 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9916
9917 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9918
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009919 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13009920}
9921
Karl Schultz6addd812016-02-02 17:17:23 -07009922TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes0036fd12016-01-26 14:19:49 +13009923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbese9928822016-02-17 14:44:52 +13009924 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz6addd812016-02-02 17:17:23 -07009925 "output arr[2] of float32' vs 'ptr to "
9926 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +13009927
9928 ASSERT_NO_FATAL_FAILURE(InitState());
9929 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9930
9931 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009932 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009933 "\n"
9934 "layout(location=0) out float x[2];\n"
9935 "out gl_PerVertex {\n"
9936 " vec4 gl_Position;\n"
9937 "};\n"
9938 "void main(){\n"
9939 " x[0] = 0; x[1] = 0;\n"
9940 " gl_Position = vec4(1);\n"
9941 "}\n";
9942 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009943 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009944 "\n"
9945 "layout(location=0) in float x[3];\n"
9946 "layout(location=0) out vec4 color;\n"
9947 "void main(){\n"
9948 " color = vec4(x[0] + x[1] + x[2]);\n"
9949 "}\n";
9950
9951 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9952 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9953
9954 VkPipelineObj pipe(m_device);
9955 pipe.AddColorAttachment();
9956 pipe.AddShader(&vs);
9957 pipe.AddShader(&fs);
9958
9959 VkDescriptorSetObj descriptorSet(m_device);
9960 descriptorSet.AppendDummy();
9961 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9962
9963 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9964
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009965 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +13009966}
9967
Karl Schultz6addd812016-02-02 17:17:23 -07009968TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009970 "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009971
Chris Forbesb56af562015-05-25 11:13:17 +12009972 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009973 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12009974
9975 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009976 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009977 "\n"
9978 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009979 "out gl_PerVertex {\n"
9980 " vec4 gl_Position;\n"
9981 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009982 "void main(){\n"
9983 " x = 0;\n"
9984 " gl_Position = vec4(1);\n"
9985 "}\n";
9986 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009987 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009988 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009989 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbesb56af562015-05-25 11:13:17 +12009990 "layout(location=0) out vec4 color;\n"
9991 "void main(){\n"
9992 " color = vec4(x);\n"
9993 "}\n";
9994
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009995 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9996 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12009997
9998 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009999 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120010000 pipe.AddShader(&vs);
10001 pipe.AddShader(&fs);
10002
Chris Forbesb56af562015-05-25 11:13:17 +120010003 VkDescriptorSetObj descriptorSet(m_device);
10004 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010005 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120010006
Tony Barbour5781e8f2015-08-04 16:23:11 -060010007 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120010008
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010009 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120010010}
10011
Karl Schultz6addd812016-02-02 17:17:23 -070010012TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +130010013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010014 "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130010015
10016 ASSERT_NO_FATAL_FAILURE(InitState());
10017 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10018
10019 char const *vsSource =
10020 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +130010021 "\n"
10022 "out block { layout(location=0) int x; } outs;\n"
10023 "out gl_PerVertex {\n"
10024 " vec4 gl_Position;\n"
10025 "};\n"
10026 "void main(){\n"
10027 " outs.x = 0;\n"
10028 " gl_Position = vec4(1);\n"
10029 "}\n";
10030 char const *fsSource =
10031 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +130010032 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010033 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbesa3e85f62016-01-15 14:53:11 +130010034 "layout(location=0) out vec4 color;\n"
10035 "void main(){\n"
10036 " color = vec4(ins.x);\n"
10037 "}\n";
10038
10039 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10040 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10041
10042 VkPipelineObj pipe(m_device);
10043 pipe.AddColorAttachment();
10044 pipe.AddShader(&vs);
10045 pipe.AddShader(&fs);
10046
10047 VkDescriptorSetObj descriptorSet(m_device);
10048 descriptorSet.AppendDummy();
10049 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10050
10051 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10052
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010053 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130010054}
10055
10056TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
10057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10058 "location 0.0 which is not written by vertex shader");
10059
10060 ASSERT_NO_FATAL_FAILURE(InitState());
10061 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10062
10063 char const *vsSource =
10064 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +130010065 "\n"
10066 "out block { layout(location=1) float x; } outs;\n"
10067 "out gl_PerVertex {\n"
10068 " vec4 gl_Position;\n"
10069 "};\n"
10070 "void main(){\n"
10071 " outs.x = 0;\n"
10072 " gl_Position = vec4(1);\n"
10073 "}\n";
10074 char const *fsSource =
10075 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +130010076 "\n"
10077 "in block { layout(location=0) float x; } ins;\n"
10078 "layout(location=0) out vec4 color;\n"
10079 "void main(){\n"
10080 " color = vec4(ins.x);\n"
10081 "}\n";
10082
10083 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10084 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10085
10086 VkPipelineObj pipe(m_device);
10087 pipe.AddColorAttachment();
10088 pipe.AddShader(&vs);
10089 pipe.AddShader(&fs);
10090
10091 VkDescriptorSetObj descriptorSet(m_device);
10092 descriptorSet.AppendDummy();
10093 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10094
10095 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10096
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010097 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130010098}
10099
10100TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
10101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10102 "location 0.1 which is not written by vertex shader");
10103
10104 ASSERT_NO_FATAL_FAILURE(InitState());
10105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10106
10107 char const *vsSource =
10108 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +130010109 "\n"
10110 "out block { layout(location=0, component=0) float x; } outs;\n"
10111 "out gl_PerVertex {\n"
10112 " vec4 gl_Position;\n"
10113 "};\n"
10114 "void main(){\n"
10115 " outs.x = 0;\n"
10116 " gl_Position = vec4(1);\n"
10117 "}\n";
10118 char const *fsSource =
10119 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +130010120 "\n"
10121 "in block { layout(location=0, component=1) float x; } ins;\n"
10122 "layout(location=0) out vec4 color;\n"
10123 "void main(){\n"
10124 " color = vec4(ins.x);\n"
10125 "}\n";
10126
10127 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10128 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10129
10130 VkPipelineObj pipe(m_device);
10131 pipe.AddColorAttachment();
10132 pipe.AddShader(&vs);
10133 pipe.AddShader(&fs);
10134
10135 VkDescriptorSetObj descriptorSet(m_device);
10136 descriptorSet.AppendDummy();
10137 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10138
10139 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10140
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010141 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130010142}
10143
Karl Schultz6addd812016-02-02 17:17:23 -070010144TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010146 "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010147
Chris Forbesde136e02015-05-25 11:13:28 +120010148 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010149 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120010150
10151 VkVertexInputBindingDescription input_binding;
10152 memset(&input_binding, 0, sizeof(input_binding));
10153
10154 VkVertexInputAttributeDescription input_attrib;
10155 memset(&input_attrib, 0, sizeof(input_attrib));
10156 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10157
10158 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010159 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +120010160 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010161 "out gl_PerVertex {\n"
10162 " vec4 gl_Position;\n"
10163 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +120010164 "void main(){\n"
10165 " gl_Position = vec4(1);\n"
10166 "}\n";
10167 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010168 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +120010169 "\n"
10170 "layout(location=0) out vec4 color;\n"
10171 "void main(){\n"
10172 " color = vec4(1);\n"
10173 "}\n";
10174
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010175 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10176 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120010177
10178 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010179 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120010180 pipe.AddShader(&vs);
10181 pipe.AddShader(&fs);
10182
10183 pipe.AddVertexInputBindings(&input_binding, 1);
10184 pipe.AddVertexInputAttribs(&input_attrib, 1);
10185
Chris Forbesde136e02015-05-25 11:13:28 +120010186 VkDescriptorSetObj descriptorSet(m_device);
10187 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010188 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120010189
Tony Barbour5781e8f2015-08-04 16:23:11 -060010190 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120010191
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010192 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120010193}
10194
Karl Schultz6addd812016-02-02 17:17:23 -070010195TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010197 "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130010198
10199 ASSERT_NO_FATAL_FAILURE(InitState());
10200 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10201
10202 VkVertexInputBindingDescription input_binding;
10203 memset(&input_binding, 0, sizeof(input_binding));
10204
10205 VkVertexInputAttributeDescription input_attrib;
10206 memset(&input_attrib, 0, sizeof(input_attrib));
10207 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10208
10209 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010210 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +130010211 "\n"
10212 "layout(location=1) in float x;\n"
10213 "out gl_PerVertex {\n"
10214 " vec4 gl_Position;\n"
10215 "};\n"
10216 "void main(){\n"
10217 " gl_Position = vec4(x);\n"
10218 "}\n";
10219 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010220 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +130010221 "\n"
10222 "layout(location=0) out vec4 color;\n"
10223 "void main(){\n"
10224 " color = vec4(1);\n"
10225 "}\n";
10226
10227 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10228 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10229
10230 VkPipelineObj pipe(m_device);
10231 pipe.AddColorAttachment();
10232 pipe.AddShader(&vs);
10233 pipe.AddShader(&fs);
10234
10235 pipe.AddVertexInputBindings(&input_binding, 1);
10236 pipe.AddVertexInputAttribs(&input_attrib, 1);
10237
10238 VkDescriptorSetObj descriptorSet(m_device);
10239 descriptorSet.AppendDummy();
10240 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10241
10242 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10243
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010244 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130010245}
10246
Karl Schultz6addd812016-02-02 17:17:23 -070010247TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
10248 m_errorMonitor->SetDesiredFailureMsg(
10249 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010250 "VS consumes input at location 0 but not provided");
10251
Chris Forbes62e8e502015-05-25 11:13:29 +120010252 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010253 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120010254
10255 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010256 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +120010257 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010258 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -070010259 "out gl_PerVertex {\n"
10260 " vec4 gl_Position;\n"
10261 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +120010262 "void main(){\n"
10263 " gl_Position = x;\n"
10264 "}\n";
10265 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010266 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +120010267 "\n"
10268 "layout(location=0) out vec4 color;\n"
10269 "void main(){\n"
10270 " color = vec4(1);\n"
10271 "}\n";
10272
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010273 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10274 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120010275
10276 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010277 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120010278 pipe.AddShader(&vs);
10279 pipe.AddShader(&fs);
10280
Chris Forbes62e8e502015-05-25 11:13:29 +120010281 VkDescriptorSetObj descriptorSet(m_device);
10282 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010283 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120010284
Tony Barbour5781e8f2015-08-04 16:23:11 -060010285 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120010286
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010287 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120010288}
10289
Karl Schultz6addd812016-02-02 17:17:23 -070010290TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
10291 m_errorMonitor->SetDesiredFailureMsg(
10292 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010293 "location 0 does not match VS input type");
10294
Chris Forbesc97d98e2015-05-25 11:13:31 +120010295 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120010297
10298 VkVertexInputBindingDescription input_binding;
10299 memset(&input_binding, 0, sizeof(input_binding));
10300
10301 VkVertexInputAttributeDescription input_attrib;
10302 memset(&input_attrib, 0, sizeof(input_attrib));
10303 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10304
10305 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010306 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010307 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010308 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -070010309 "out gl_PerVertex {\n"
10310 " vec4 gl_Position;\n"
10311 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010312 "void main(){\n"
10313 " gl_Position = vec4(x);\n"
10314 "}\n";
10315 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010316 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010317 "\n"
10318 "layout(location=0) out vec4 color;\n"
10319 "void main(){\n"
10320 " color = vec4(1);\n"
10321 "}\n";
10322
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010323 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10324 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120010325
10326 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010327 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120010328 pipe.AddShader(&vs);
10329 pipe.AddShader(&fs);
10330
10331 pipe.AddVertexInputBindings(&input_binding, 1);
10332 pipe.AddVertexInputAttribs(&input_attrib, 1);
10333
Chris Forbesc97d98e2015-05-25 11:13:31 +120010334 VkDescriptorSetObj descriptorSet(m_device);
10335 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010336 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120010337
Tony Barbour5781e8f2015-08-04 16:23:11 -060010338 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120010339
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010340 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120010341}
10342
Chris Forbesc68b43c2016-04-06 11:18:47 +120010343TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
10344 m_errorMonitor->SetDesiredFailureMsg(
10345 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10346 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
10347
10348 ASSERT_NO_FATAL_FAILURE(InitState());
10349 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10350
10351 char const *vsSource =
10352 "#version 450\n"
10353 "\n"
10354 "out gl_PerVertex {\n"
10355 " vec4 gl_Position;\n"
10356 "};\n"
10357 "void main(){\n"
10358 " gl_Position = vec4(1);\n"
10359 "}\n";
10360 char const *fsSource =
10361 "#version 450\n"
10362 "\n"
10363 "layout(location=0) out vec4 color;\n"
10364 "void main(){\n"
10365 " color = vec4(1);\n"
10366 "}\n";
10367
10368 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10369 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10370
10371 VkPipelineObj pipe(m_device);
10372 pipe.AddColorAttachment();
10373 pipe.AddShader(&vs);
10374 pipe.AddShader(&vs);
10375 pipe.AddShader(&fs);
10376
10377 VkDescriptorSetObj descriptorSet(m_device);
10378 descriptorSet.AppendDummy();
10379 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10380
10381 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10382
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010383 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120010384}
10385
Karl Schultz6addd812016-02-02 17:17:23 -070010386TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010387 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130010388
10389 ASSERT_NO_FATAL_FAILURE(InitState());
10390 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10391
10392 VkVertexInputBindingDescription input_binding;
10393 memset(&input_binding, 0, sizeof(input_binding));
10394
10395 VkVertexInputAttributeDescription input_attribs[2];
10396 memset(input_attribs, 0, sizeof(input_attribs));
10397
10398 for (int i = 0; i < 2; i++) {
10399 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10400 input_attribs[i].location = i;
10401 }
10402
10403 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010404 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010405 "\n"
10406 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -070010407 "out gl_PerVertex {\n"
10408 " vec4 gl_Position;\n"
10409 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010410 "void main(){\n"
10411 " gl_Position = x[0] + x[1];\n"
10412 "}\n";
10413 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010414 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010415 "\n"
10416 "layout(location=0) out vec4 color;\n"
10417 "void main(){\n"
10418 " color = vec4(1);\n"
10419 "}\n";
10420
10421 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10422 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10423
10424 VkPipelineObj pipe(m_device);
10425 pipe.AddColorAttachment();
10426 pipe.AddShader(&vs);
10427 pipe.AddShader(&fs);
10428
10429 pipe.AddVertexInputBindings(&input_binding, 1);
10430 pipe.AddVertexInputAttribs(input_attribs, 2);
10431
10432 VkDescriptorSetObj descriptorSet(m_device);
10433 descriptorSet.AppendDummy();
10434 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10435
10436 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10437
10438 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010439 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010440}
10441
Chris Forbes2682b242015-11-24 11:13:14 +130010442TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
10443{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010444 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130010445
10446 ASSERT_NO_FATAL_FAILURE(InitState());
10447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10448
10449 VkVertexInputBindingDescription input_binding;
10450 memset(&input_binding, 0, sizeof(input_binding));
10451
10452 VkVertexInputAttributeDescription input_attribs[2];
10453 memset(input_attribs, 0, sizeof(input_attribs));
10454
10455 for (int i = 0; i < 2; i++) {
10456 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10457 input_attribs[i].location = i;
10458 }
10459
10460 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010461 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010462 "\n"
10463 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -070010464 "out gl_PerVertex {\n"
10465 " vec4 gl_Position;\n"
10466 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010467 "void main(){\n"
10468 " gl_Position = x[0] + x[1];\n"
10469 "}\n";
10470 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010471 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010472 "\n"
10473 "layout(location=0) out vec4 color;\n"
10474 "void main(){\n"
10475 " color = vec4(1);\n"
10476 "}\n";
10477
10478 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10479 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10480
10481 VkPipelineObj pipe(m_device);
10482 pipe.AddColorAttachment();
10483 pipe.AddShader(&vs);
10484 pipe.AddShader(&fs);
10485
10486 pipe.AddVertexInputBindings(&input_binding, 1);
10487 pipe.AddVertexInputAttribs(input_attribs, 2);
10488
10489 VkDescriptorSetObj descriptorSet(m_device);
10490 descriptorSet.AppendDummy();
10491 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10492
10493 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10494
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010495 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010496}
Chris Forbes2682b242015-11-24 11:13:14 +130010497
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010498TEST_F(VkLayerTest, CreatePipelineSimplePositive)
10499{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010500 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010501
10502 ASSERT_NO_FATAL_FAILURE(InitState());
10503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10504
10505 char const *vsSource =
10506 "#version 450\n"
10507 "out gl_PerVertex {\n"
10508 " vec4 gl_Position;\n"
10509 "};\n"
10510 "void main(){\n"
10511 " gl_Position = vec4(0);\n"
10512 "}\n";
10513 char const *fsSource =
10514 "#version 450\n"
10515 "\n"
10516 "layout(location=0) out vec4 color;\n"
10517 "void main(){\n"
10518 " color = vec4(1);\n"
10519 "}\n";
10520
10521 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10522 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10523
10524 VkPipelineObj pipe(m_device);
10525 pipe.AddColorAttachment();
10526 pipe.AddShader(&vs);
10527 pipe.AddShader(&fs);
10528
10529 VkDescriptorSetObj descriptorSet(m_device);
10530 descriptorSet.AppendDummy();
10531 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10532
10533 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10534
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010535 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010536}
10537
Chris Forbes912c9192016-04-05 17:50:35 +120010538TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch)
10539{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010540 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120010541
10542 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
10543
10544 ASSERT_NO_FATAL_FAILURE(InitState());
10545 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10546
10547 char const *vsSource =
10548 "#version 450\n"
10549 "out gl_PerVertex {\n"
10550 " vec4 gl_Position;\n"
10551 "};\n"
10552 "layout(location=0) out vec3 x;\n"
10553 "layout(location=1) out ivec3 y;\n"
10554 "layout(location=2) out vec3 z;\n"
10555 "void main(){\n"
10556 " gl_Position = vec4(0);\n"
10557 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
10558 "}\n";
10559 char const *fsSource =
10560 "#version 450\n"
10561 "\n"
10562 "layout(location=0) out vec4 color;\n"
10563 "layout(location=0) in float x;\n"
10564 "layout(location=1) flat in int y;\n"
10565 "layout(location=2) in vec2 z;\n"
10566 "void main(){\n"
10567 " color = vec4(1 + x + y + z.x);\n"
10568 "}\n";
10569
10570 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10571 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10572
10573 VkPipelineObj pipe(m_device);
10574 pipe.AddColorAttachment();
10575 pipe.AddShader(&vs);
10576 pipe.AddShader(&fs);
10577
10578 VkDescriptorSetObj descriptorSet(m_device);
10579 descriptorSet.AppendDummy();
10580 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10581
10582 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10583
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010584 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120010585}
10586
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010587TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
10588{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010589 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010590
10591 ASSERT_NO_FATAL_FAILURE(InitState());
10592 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10593
Chris Forbesc1e852d2016-04-04 19:26:42 +120010594 if (!m_device->phy().features().tessellationShader) {
10595 printf("Device does not support tessellation shaders; skipped.\n");
10596 return;
10597 }
10598
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010599 char const *vsSource =
10600 "#version 450\n"
10601 "void main(){}\n";
10602 char const *tcsSource =
10603 "#version 450\n"
10604 "layout(location=0) out int x[];\n"
10605 "layout(vertices=3) out;\n"
10606 "void main(){\n"
10607 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10608 " gl_TessLevelInner[0] = 1;\n"
10609 " x[gl_InvocationID] = gl_InvocationID;\n"
10610 "}\n";
10611 char const *tesSource =
10612 "#version 450\n"
10613 "layout(triangles, equal_spacing, cw) in;\n"
10614 "layout(location=0) in int x[];\n"
10615 "out gl_PerVertex { vec4 gl_Position; };\n"
10616 "void main(){\n"
10617 " gl_Position.xyz = gl_TessCoord;\n"
10618 " gl_Position.w = x[0] + x[1] + x[2];\n"
10619 "}\n";
10620 char const *fsSource =
10621 "#version 450\n"
10622 "layout(location=0) out vec4 color;\n"
10623 "void main(){\n"
10624 " color = vec4(1);\n"
10625 "}\n";
10626
10627 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10628 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10629 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10630 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10631
10632 VkPipelineInputAssemblyStateCreateInfo iasci{
10633 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10634 nullptr,
10635 0,
10636 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10637 VK_FALSE};
10638
Chris Forbesb4cacb62016-04-04 19:15:00 +120010639 VkPipelineTessellationStateCreateInfo tsci{
10640 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10641 nullptr,
10642 0,
10643 3};
10644
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010645 VkPipelineObj pipe(m_device);
10646 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120010647 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010648 pipe.AddColorAttachment();
10649 pipe.AddShader(&vs);
10650 pipe.AddShader(&tcs);
10651 pipe.AddShader(&tes);
10652 pipe.AddShader(&fs);
10653
10654 VkDescriptorSetObj descriptorSet(m_device);
10655 descriptorSet.AppendDummy();
10656 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10657
10658 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10659
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010660 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010661}
10662
Chris Forbesa0ab8152016-04-20 13:34:27 +120010663TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive)
10664{
10665 m_errorMonitor->ExpectSuccess();
10666
10667 ASSERT_NO_FATAL_FAILURE(InitState());
10668 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10669
10670 if (!m_device->phy().features().geometryShader) {
10671 printf("Device does not support geometry shaders; skipped.\n");
10672 return;
10673 }
10674
10675 char const *vsSource =
10676 "#version 450\n"
10677 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
10678 "void main(){\n"
10679 " vs_out.x = vec4(1);\n"
10680 "}\n";
10681 char const *gsSource =
10682 "#version 450\n"
10683 "layout(triangles) in;\n"
10684 "layout(triangle_strip, max_vertices=3) out;\n"
10685 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
10686 "out gl_PerVertex { vec4 gl_Position; };\n"
10687 "void main() {\n"
10688 " gl_Position = gs_in[0].x;\n"
10689 " EmitVertex();\n"
10690 "}\n";
10691 char const *fsSource =
10692 "#version 450\n"
10693 "layout(location=0) out vec4 color;\n"
10694 "void main(){\n"
10695 " color = vec4(1);\n"
10696 "}\n";
10697
10698 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10699 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
10700 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10701
10702 VkPipelineObj pipe(m_device);
10703 pipe.AddColorAttachment();
10704 pipe.AddShader(&vs);
10705 pipe.AddShader(&gs);
10706 pipe.AddShader(&fs);
10707
10708 VkDescriptorSetObj descriptorSet(m_device);
10709 descriptorSet.AppendDummy();
10710 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10711
10712 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10713
10714 m_errorMonitor->VerifyNotFound();
10715}
10716
Chris Forbesa0193bc2016-04-04 19:19:47 +120010717TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
10718{
10719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10720 "is per-vertex in tessellation control shader stage "
10721 "but per-patch in tessellation evaluation shader stage");
10722
10723 ASSERT_NO_FATAL_FAILURE(InitState());
10724 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10725
Chris Forbesc1e852d2016-04-04 19:26:42 +120010726 if (!m_device->phy().features().tessellationShader) {
10727 printf("Device does not support tessellation shaders; skipped.\n");
10728 return;
10729 }
10730
Chris Forbesa0193bc2016-04-04 19:19:47 +120010731 char const *vsSource =
10732 "#version 450\n"
10733 "void main(){}\n";
10734 char const *tcsSource =
10735 "#version 450\n"
10736 "layout(location=0) out int x[];\n"
10737 "layout(vertices=3) out;\n"
10738 "void main(){\n"
10739 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10740 " gl_TessLevelInner[0] = 1;\n"
10741 " x[gl_InvocationID] = gl_InvocationID;\n"
10742 "}\n";
10743 char const *tesSource =
10744 "#version 450\n"
10745 "layout(triangles, equal_spacing, cw) in;\n"
10746 "layout(location=0) patch in int x;\n"
10747 "out gl_PerVertex { vec4 gl_Position; };\n"
10748 "void main(){\n"
10749 " gl_Position.xyz = gl_TessCoord;\n"
10750 " gl_Position.w = x;\n"
10751 "}\n";
10752 char const *fsSource =
10753 "#version 450\n"
10754 "layout(location=0) out vec4 color;\n"
10755 "void main(){\n"
10756 " color = vec4(1);\n"
10757 "}\n";
10758
10759 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10760 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10761 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10762 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10763
10764 VkPipelineInputAssemblyStateCreateInfo iasci{
10765 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10766 nullptr,
10767 0,
10768 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10769 VK_FALSE};
10770
10771 VkPipelineTessellationStateCreateInfo tsci{
10772 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10773 nullptr,
10774 0,
10775 3};
10776
10777 VkPipelineObj pipe(m_device);
10778 pipe.SetInputAssembly(&iasci);
10779 pipe.SetTessellation(&tsci);
10780 pipe.AddColorAttachment();
10781 pipe.AddShader(&vs);
10782 pipe.AddShader(&tcs);
10783 pipe.AddShader(&tes);
10784 pipe.AddShader(&fs);
10785
10786 VkDescriptorSetObj descriptorSet(m_device);
10787 descriptorSet.AppendDummy();
10788 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10789
10790 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10791
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010792 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120010793}
10794
Karl Schultz6addd812016-02-02 17:17:23 -070010795TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
10796 m_errorMonitor->SetDesiredFailureMsg(
10797 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010798 "Duplicate vertex input binding descriptions for binding 0");
10799
Chris Forbes280ba2c2015-06-12 11:16:41 +120010800 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010802
10803 /* Two binding descriptions for binding 0 */
10804 VkVertexInputBindingDescription input_bindings[2];
10805 memset(input_bindings, 0, sizeof(input_bindings));
10806
10807 VkVertexInputAttributeDescription input_attrib;
10808 memset(&input_attrib, 0, sizeof(input_attrib));
10809 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10810
10811 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010812 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010813 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010814 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -070010815 "out gl_PerVertex {\n"
10816 " vec4 gl_Position;\n"
10817 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010818 "void main(){\n"
10819 " gl_Position = vec4(x);\n"
10820 "}\n";
10821 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010822 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010823 "\n"
10824 "layout(location=0) out vec4 color;\n"
10825 "void main(){\n"
10826 " color = vec4(1);\n"
10827 "}\n";
10828
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010829 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10830 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010831
10832 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010833 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010834 pipe.AddShader(&vs);
10835 pipe.AddShader(&fs);
10836
10837 pipe.AddVertexInputBindings(input_bindings, 2);
10838 pipe.AddVertexInputAttribs(&input_attrib, 1);
10839
Chris Forbes280ba2c2015-06-12 11:16:41 +120010840 VkDescriptorSetObj descriptorSet(m_device);
10841 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010842 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010843
Tony Barbour5781e8f2015-08-04 16:23:11 -060010844 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010845
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010846 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010847}
Chris Forbes8f68b562015-05-25 11:13:32 +120010848
Chris Forbes35efec72016-04-21 14:32:08 +120010849TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
10850 m_errorMonitor->ExpectSuccess();
10851
10852 ASSERT_NO_FATAL_FAILURE(InitState());
10853 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10854
10855 if (!m_device->phy().features().tessellationShader) {
10856 printf("Device does not support 64bit vertex attributes; skipped.\n");
10857 return;
10858 }
10859
10860 VkVertexInputBindingDescription input_bindings[1];
10861 memset(input_bindings, 0, sizeof(input_bindings));
10862
10863 VkVertexInputAttributeDescription input_attribs[4];
10864 memset(input_attribs, 0, sizeof(input_attribs));
10865 input_attribs[0].location = 0;
10866 input_attribs[0].offset = 0;
10867 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10868 input_attribs[1].location = 2;
10869 input_attribs[1].offset = 32;
10870 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10871 input_attribs[2].location = 4;
10872 input_attribs[2].offset = 64;
10873 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10874 input_attribs[3].location = 6;
10875 input_attribs[3].offset = 96;
10876 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10877
10878 char const *vsSource =
10879 "#version 450\n"
10880 "\n"
10881 "layout(location=0) in dmat4 x;\n"
10882 "out gl_PerVertex {\n"
10883 " vec4 gl_Position;\n"
10884 "};\n"
10885 "void main(){\n"
10886 " gl_Position = vec4(x[0][0]);\n"
10887 "}\n";
10888 char const *fsSource =
10889 "#version 450\n"
10890 "\n"
10891 "layout(location=0) out vec4 color;\n"
10892 "void main(){\n"
10893 " color = vec4(1);\n"
10894 "}\n";
10895
10896 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10897 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10898
10899 VkPipelineObj pipe(m_device);
10900 pipe.AddColorAttachment();
10901 pipe.AddShader(&vs);
10902 pipe.AddShader(&fs);
10903
10904 pipe.AddVertexInputBindings(input_bindings, 1);
10905 pipe.AddVertexInputAttribs(input_attribs, 4);
10906
10907 VkDescriptorSetObj descriptorSet(m_device);
10908 descriptorSet.AppendDummy();
10909 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10910
10911 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10912
10913 m_errorMonitor->VerifyNotFound();
10914}
10915
Karl Schultz6addd812016-02-02 17:17:23 -070010916TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010918 "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010919
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010920 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010921
10922 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010923 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010924 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010925 "out gl_PerVertex {\n"
10926 " vec4 gl_Position;\n"
10927 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010928 "void main(){\n"
10929 " gl_Position = vec4(1);\n"
10930 "}\n";
10931 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010932 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010933 "\n"
10934 "void main(){\n"
10935 "}\n";
10936
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010937 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10938 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010939
10940 VkPipelineObj pipe(m_device);
10941 pipe.AddShader(&vs);
10942 pipe.AddShader(&fs);
10943
Chia-I Wu08accc62015-07-07 11:50:03 +080010944 /* set up CB 0, not written */
10945 pipe.AddColorAttachment();
10946 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010947
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010948 VkDescriptorSetObj descriptorSet(m_device);
10949 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010950 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010951
Tony Barbour5781e8f2015-08-04 16:23:11 -060010952 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010953
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010954 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010955}
10956
Karl Schultz6addd812016-02-02 17:17:23 -070010957TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Karl Schultz6addd812016-02-02 17:17:23 -070010958 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010959 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010960 "FS writes to output location 1 with no matching attachment");
10961
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010962 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010963
10964 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010965 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010966 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010967 "out gl_PerVertex {\n"
10968 " vec4 gl_Position;\n"
10969 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010970 "void main(){\n"
10971 " gl_Position = vec4(1);\n"
10972 "}\n";
10973 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010974 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010975 "\n"
10976 "layout(location=0) out vec4 x;\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010977 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010978 "void main(){\n"
10979 " x = vec4(1);\n"
10980 " y = vec4(1);\n"
10981 "}\n";
10982
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010983 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10984 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010985
10986 VkPipelineObj pipe(m_device);
10987 pipe.AddShader(&vs);
10988 pipe.AddShader(&fs);
10989
Chia-I Wu08accc62015-07-07 11:50:03 +080010990 /* set up CB 0, not written */
10991 pipe.AddColorAttachment();
10992 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010993 /* FS writes CB 1, but we don't configure it */
10994
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010995 VkDescriptorSetObj descriptorSet(m_device);
10996 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010997 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010998
Tony Barbour5781e8f2015-08-04 16:23:11 -060010999 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120011000
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011001 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120011002}
11003
Karl Schultz6addd812016-02-02 17:17:23 -070011004TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070011006 "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011007
Chris Forbesa36d69e2015-05-25 11:13:44 +120011008 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120011009
11010 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120011011 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120011012 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070011013 "out gl_PerVertex {\n"
11014 " vec4 gl_Position;\n"
11015 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120011016 "void main(){\n"
11017 " gl_Position = vec4(1);\n"
11018 "}\n";
11019 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120011020 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120011021 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070011022 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbesa36d69e2015-05-25 11:13:44 +120011023 "void main(){\n"
11024 " x = ivec4(1);\n"
11025 "}\n";
11026
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011027 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11028 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120011029
11030 VkPipelineObj pipe(m_device);
11031 pipe.AddShader(&vs);
11032 pipe.AddShader(&fs);
11033
Chia-I Wu08accc62015-07-07 11:50:03 +080011034 /* set up CB 0; type is UNORM by default */
11035 pipe.AddColorAttachment();
11036 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120011037
Chris Forbesa36d69e2015-05-25 11:13:44 +120011038 VkDescriptorSetObj descriptorSet(m_device);
11039 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011040 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120011041
Tony Barbour5781e8f2015-08-04 16:23:11 -060011042 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120011043
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011044 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120011045}
Chris Forbes7b1b8932015-06-05 14:43:36 +120011046
Karl Schultz6addd812016-02-02 17:17:23 -070011047TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070011049 "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011050
Chris Forbes556c76c2015-08-14 12:04:59 +120011051 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120011052
11053 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120011054 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120011055 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070011056 "out gl_PerVertex {\n"
11057 " vec4 gl_Position;\n"
11058 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120011059 "void main(){\n"
11060 " gl_Position = vec4(1);\n"
11061 "}\n";
11062 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120011063 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120011064 "\n"
11065 "layout(location=0) out vec4 x;\n"
11066 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
11067 "void main(){\n"
11068 " x = vec4(bar.y);\n"
11069 "}\n";
11070
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011071 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11072 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120011073
Chris Forbes556c76c2015-08-14 12:04:59 +120011074 VkPipelineObj pipe(m_device);
11075 pipe.AddShader(&vs);
11076 pipe.AddShader(&fs);
11077
11078 /* set up CB 0; type is UNORM by default */
11079 pipe.AddColorAttachment();
11080 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11081
11082 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011083 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120011084
11085 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
11086
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011087 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120011088}
11089
Chris Forbes5c59e902016-02-26 16:56:09 +130011090TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
11091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11092 "not declared in layout");
11093
11094 ASSERT_NO_FATAL_FAILURE(InitState());
11095
11096 char const *vsSource =
11097 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130011098 "\n"
11099 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
11100 "out gl_PerVertex {\n"
11101 " vec4 gl_Position;\n"
11102 "};\n"
11103 "void main(){\n"
11104 " gl_Position = vec4(consts.x);\n"
11105 "}\n";
11106 char const *fsSource =
11107 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130011108 "\n"
11109 "layout(location=0) out vec4 x;\n"
11110 "void main(){\n"
11111 " x = vec4(1);\n"
11112 "}\n";
11113
11114 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11115 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11116
11117 VkPipelineObj pipe(m_device);
11118 pipe.AddShader(&vs);
11119 pipe.AddShader(&fs);
11120
11121 /* set up CB 0; type is UNORM by default */
11122 pipe.AddColorAttachment();
11123 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11124
11125 VkDescriptorSetObj descriptorSet(m_device);
11126 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
11127
11128 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
11129
11130 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011131 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130011132}
11133
Chris Forbes10eb9ae2016-05-31 16:09:42 +120011134TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
11135 m_errorMonitor->SetDesiredFailureMsg(
11136 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11137 "Shader uses descriptor slot 0.0");
11138
11139 ASSERT_NO_FATAL_FAILURE(InitState());
11140
11141 char const *csSource =
11142 "#version 450\n"
11143 "\n"
11144 "layout(local_size_x=1) in;\n"
11145 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
11146 "void main(){\n"
11147 " x = vec4(1);\n"
11148 "}\n";
11149
11150 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
11151
11152 VkDescriptorSetObj descriptorSet(m_device);
11153 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
11154
11155 VkComputePipelineCreateInfo cpci = {
11156 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
11157 nullptr, 0, {
11158 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
11159 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
11160 cs.handle(), "main", nullptr
11161 },
11162 descriptorSet.GetPipelineLayout(),
11163 VK_NULL_HANDLE, -1
11164 };
11165
11166 VkPipeline pipe;
11167 VkResult err = vkCreateComputePipelines(
11168 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
11169
11170 m_errorMonitor->VerifyFound();
11171
11172 if (err == VK_SUCCESS) {
11173 vkDestroyPipeline(m_device->device(), pipe, nullptr);
11174 }
11175}
11176
11177TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
11178 m_errorMonitor->ExpectSuccess();
11179
11180 ASSERT_NO_FATAL_FAILURE(InitState());
11181
11182 char const *csSource =
11183 "#version 450\n"
11184 "\n"
11185 "layout(local_size_x=1) in;\n"
11186 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
11187 "void main(){\n"
11188 " // x is not used.\n"
11189 "}\n";
11190
11191 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
11192
11193 VkDescriptorSetObj descriptorSet(m_device);
11194 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
11195
11196 VkComputePipelineCreateInfo cpci = {
11197 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
11198 nullptr, 0, {
11199 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
11200 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
11201 cs.handle(), "main", nullptr
11202 },
11203 descriptorSet.GetPipelineLayout(),
11204 VK_NULL_HANDLE, -1
11205 };
11206
11207 VkPipeline pipe;
11208 VkResult err = vkCreateComputePipelines(
11209 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
11210
11211 m_errorMonitor->VerifyNotFound();
11212
11213 if (err == VK_SUCCESS) {
11214 vkDestroyPipeline(m_device->device(), pipe, nullptr);
11215 }
11216}
11217
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011218#endif // SHADER_CHECKER_TESTS
11219
11220#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060011221TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Karl Schultz6addd812016-02-02 17:17:23 -070011222 m_errorMonitor->SetDesiredFailureMsg(
11223 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011224 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011225
11226 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011227
11228 // Create an image
11229 VkImage image;
11230
Karl Schultz6addd812016-02-02 17:17:23 -070011231 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11232 const int32_t tex_width = 32;
11233 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011234
11235 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011236 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11237 image_create_info.pNext = NULL;
11238 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11239 image_create_info.format = tex_format;
11240 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011241 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070011242 image_create_info.extent.depth = 1;
11243 image_create_info.mipLevels = 1;
11244 image_create_info.arrayLayers = 1;
11245 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11246 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11247 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11248 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011249
11250 // Introduce error by sending down a bogus width extent
11251 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011252 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011253
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011254 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011255}
11256
Mark Youngc48c4c12016-04-11 14:26:49 -060011257TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
11258 m_errorMonitor->SetDesiredFailureMsg(
11259 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11260 "CreateImage extents is 0 for at least one required dimension");
11261
11262 ASSERT_NO_FATAL_FAILURE(InitState());
11263
11264 // Create an image
11265 VkImage image;
11266
11267 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11268 const int32_t tex_width = 32;
11269 const int32_t tex_height = 32;
11270
11271 VkImageCreateInfo image_create_info = {};
11272 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11273 image_create_info.pNext = NULL;
11274 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11275 image_create_info.format = tex_format;
11276 image_create_info.extent.width = tex_width;
11277 image_create_info.extent.height = tex_height;
11278 image_create_info.extent.depth = 1;
11279 image_create_info.mipLevels = 1;
11280 image_create_info.arrayLayers = 1;
11281 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11282 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11283 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11284 image_create_info.flags = 0;
11285
11286 // Introduce error by sending down a bogus width extent
11287 image_create_info.extent.width = 0;
11288 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
11289
11290 m_errorMonitor->VerifyFound();
11291}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011292#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120011293
Tobin Ehliscde08892015-09-22 10:11:37 -060011294#if IMAGE_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011295TEST_F(VkLayerTest, InvalidImageView) {
11296 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060011297
Karl Schultz6addd812016-02-02 17:17:23 -070011298 m_errorMonitor->SetDesiredFailureMsg(
11299 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011300 "vkCreateImageView called with baseMipLevel 10 ");
11301
Tobin Ehliscde08892015-09-22 10:11:37 -060011302 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060011303
Mike Stroyana3082432015-09-25 13:39:21 -060011304 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070011305 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060011306
Karl Schultz6addd812016-02-02 17:17:23 -070011307 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11308 const int32_t tex_width = 32;
11309 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060011310
11311 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011312 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11313 image_create_info.pNext = NULL;
11314 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11315 image_create_info.format = tex_format;
11316 image_create_info.extent.width = tex_width;
11317 image_create_info.extent.height = tex_height;
11318 image_create_info.extent.depth = 1;
11319 image_create_info.mipLevels = 1;
11320 image_create_info.arrayLayers = 1;
11321 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11322 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11323 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11324 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060011325
Chia-I Wuf7458c52015-10-26 21:10:41 +080011326 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060011327 ASSERT_VK_SUCCESS(err);
11328
11329 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011330 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11331 image_view_create_info.image = image;
11332 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11333 image_view_create_info.format = tex_format;
11334 image_view_create_info.subresourceRange.layerCount = 1;
11335 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
11336 image_view_create_info.subresourceRange.levelCount = 1;
11337 image_view_create_info.subresourceRange.aspectMask =
11338 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060011339
11340 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070011341 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
11342 &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060011343
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011344 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060011345 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060011346}
Mike Stroyana3082432015-09-25 13:39:21 -060011347
Karl Schultz6addd812016-02-02 17:17:23 -070011348TEST_F(VkLayerTest, InvalidImageViewAspect) {
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011349 TEST_DESCRIPTION(
11350 "Create an image and try to create a view with an invalid aspectMask");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070011352 "vkCreateImageView: Color image "
11353 "formats must have ONLY the "
11354 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011355
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011356 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011357
Karl Schultz6addd812016-02-02 17:17:23 -070011358 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011359 VkImageObj image(m_device);
11360 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT,
11361 VK_IMAGE_TILING_LINEAR, 0);
11362 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011363
11364 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011365 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011366 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070011367 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11368 image_view_create_info.format = tex_format;
11369 image_view_create_info.subresourceRange.baseMipLevel = 0;
11370 image_view_create_info.subresourceRange.levelCount = 1;
11371 // Cause an error by setting an invalid image aspect
11372 image_view_create_info.subresourceRange.aspectMask =
11373 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011374
11375 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011376 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011377
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011378 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011379}
11380
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011381TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070011382 VkResult err;
11383 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011384
Karl Schultz6addd812016-02-02 17:17:23 -070011385 m_errorMonitor->SetDesiredFailureMsg(
11386 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011387 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011388
Mike Stroyana3082432015-09-25 13:39:21 -060011389 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011390
11391 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011392 VkImage srcImage;
11393 VkImage dstImage;
11394 VkDeviceMemory srcMem;
11395 VkDeviceMemory destMem;
11396 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011397
11398 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011399 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11400 image_create_info.pNext = NULL;
11401 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11402 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11403 image_create_info.extent.width = 32;
11404 image_create_info.extent.height = 32;
11405 image_create_info.extent.depth = 1;
11406 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011407 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070011408 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11409 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11410 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11411 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011412
Karl Schultz6addd812016-02-02 17:17:23 -070011413 err =
11414 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011415 ASSERT_VK_SUCCESS(err);
11416
Karl Schultz6addd812016-02-02 17:17:23 -070011417 err =
11418 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011419 ASSERT_VK_SUCCESS(err);
11420
11421 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011422 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011423 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11424 memAlloc.pNext = NULL;
11425 memAlloc.allocationSize = 0;
11426 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011427
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011428 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011429 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011430 pass =
11431 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011432 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011433 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011434 ASSERT_VK_SUCCESS(err);
11435
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011436 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011437 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011438 pass =
11439 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011440 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011441 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011442 ASSERT_VK_SUCCESS(err);
11443
11444 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11445 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011446 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011447 ASSERT_VK_SUCCESS(err);
11448
11449 BeginCommandBuffer();
11450 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011451 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011452 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011453 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011454 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060011455 copyRegion.srcOffset.x = 0;
11456 copyRegion.srcOffset.y = 0;
11457 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011458 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011459 copyRegion.dstSubresource.mipLevel = 0;
11460 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011461 // Introduce failure by forcing the dst layerCount to differ from src
11462 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011463 copyRegion.dstOffset.x = 0;
11464 copyRegion.dstOffset.y = 0;
11465 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011466 copyRegion.extent.width = 1;
11467 copyRegion.extent.height = 1;
11468 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011469 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11470 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011471 EndCommandBuffer();
11472
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011473 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011474
Chia-I Wuf7458c52015-10-26 21:10:41 +080011475 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011476 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011477 vkFreeMemory(m_device->device(), srcMem, NULL);
11478 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011479}
11480
Tony Barbourd6673642016-05-05 14:46:39 -060011481TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
11482
11483 TEST_DESCRIPTION("Creating images with unsuported formats ");
11484
11485 ASSERT_NO_FATAL_FAILURE(InitState());
11486 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11487 VkImageObj image(m_device);
11488 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11489 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11490 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11491 VK_IMAGE_TILING_OPTIMAL, 0);
11492 ASSERT_TRUE(image.initialized());
11493
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011494 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
11495 VkImageCreateInfo image_create_info;
11496 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11497 image_create_info.pNext = NULL;
11498 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11499 image_create_info.format = VK_FORMAT_UNDEFINED;
11500 image_create_info.extent.width = 32;
11501 image_create_info.extent.height = 32;
11502 image_create_info.extent.depth = 1;
11503 image_create_info.mipLevels = 1;
11504 image_create_info.arrayLayers = 1;
11505 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11506 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11507 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11508 image_create_info.flags = 0;
11509
11510 m_errorMonitor->SetDesiredFailureMsg(
11511 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11512 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
11513
11514 VkImage localImage;
11515 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
11516 m_errorMonitor->VerifyFound();
11517
Tony Barbourd6673642016-05-05 14:46:39 -060011518 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011519 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060011520 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
11521 VkFormat format = static_cast<VkFormat>(f);
11522 VkFormatProperties fProps = m_device->format_properties(format);
11523 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
11524 fProps.optimalTilingFeatures == 0) {
11525 unsupported = format;
11526 break;
11527 }
11528 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011529
Tony Barbourd6673642016-05-05 14:46:39 -060011530 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060011531 image_create_info.format = unsupported;
Tony Barbourd6673642016-05-05 14:46:39 -060011532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011533 "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060011534
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011535 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060011536 m_errorMonitor->VerifyFound();
11537 }
11538}
11539
11540TEST_F(VkLayerTest, ImageLayerViewTests) {
11541 VkResult ret;
11542 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
11543
11544 ASSERT_NO_FATAL_FAILURE(InitState());
11545
11546 VkImageObj image(m_device);
11547 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11548 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11549 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11550 VK_IMAGE_TILING_OPTIMAL, 0);
11551 ASSERT_TRUE(image.initialized());
11552
11553 VkImageView imgView;
11554 VkImageViewCreateInfo imgViewInfo = {};
11555 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11556 imgViewInfo.image = image.handle();
11557 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
11558 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11559 imgViewInfo.subresourceRange.layerCount = 1;
11560 imgViewInfo.subresourceRange.baseMipLevel = 0;
11561 imgViewInfo.subresourceRange.levelCount = 1;
11562 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11563
11564 m_errorMonitor->SetDesiredFailureMsg(
11565 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11566 "vkCreateImageView called with baseMipLevel");
11567 // View can't have baseMipLevel >= image's mipLevels - Expect
11568 // VIEW_CREATE_ERROR
11569 imgViewInfo.subresourceRange.baseMipLevel = 1;
11570 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11571 m_errorMonitor->VerifyFound();
11572 imgViewInfo.subresourceRange.baseMipLevel = 0;
11573
11574 m_errorMonitor->SetDesiredFailureMsg(
11575 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11576 "vkCreateImageView called with baseArrayLayer");
11577 // View can't have baseArrayLayer >= image's arraySize - Expect
11578 // VIEW_CREATE_ERROR
11579 imgViewInfo.subresourceRange.baseArrayLayer = 1;
11580 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11581 m_errorMonitor->VerifyFound();
11582 imgViewInfo.subresourceRange.baseArrayLayer = 0;
11583
11584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11585 "vkCreateImageView called with 0 in "
11586 "pCreateInfo->subresourceRange."
11587 "levelCount");
11588 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
11589 imgViewInfo.subresourceRange.levelCount = 0;
11590 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11591 m_errorMonitor->VerifyFound();
11592 imgViewInfo.subresourceRange.levelCount = 1;
11593
11594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11595 "vkCreateImageView called with 0 in "
11596 "pCreateInfo->subresourceRange."
11597 "layerCount");
11598 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
11599 imgViewInfo.subresourceRange.layerCount = 0;
11600 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11601 m_errorMonitor->VerifyFound();
11602 imgViewInfo.subresourceRange.layerCount = 1;
11603
11604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11605 "but both must be color formats");
11606 // Can't use depth format for view into color image - Expect INVALID_FORMAT
11607 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
11608 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11609 m_errorMonitor->VerifyFound();
11610 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11611
11612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11613 "Formats MUST be IDENTICAL unless "
11614 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
11615 "was set on image creation.");
11616 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
11617 // VIEW_CREATE_ERROR
11618 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
11619 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11620 m_errorMonitor->VerifyFound();
11621 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11622
11623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11624 "can support ImageViews with "
11625 "differing formats but they must be "
11626 "in the same compatibility class.");
11627 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
11628 // VIEW_CREATE_ERROR
11629 VkImageCreateInfo mutImgInfo = image.create_info();
11630 VkImage mutImage;
11631 mutImgInfo.format = VK_FORMAT_R8_UINT;
11632 assert(
11633 m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures &
11634 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
11635 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
11636 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11637 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
11638 ASSERT_VK_SUCCESS(ret);
11639 imgViewInfo.image = mutImage;
11640 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11641 m_errorMonitor->VerifyFound();
11642 imgViewInfo.image = image.handle();
11643 vkDestroyImage(m_device->handle(), mutImage, NULL);
11644}
11645
11646TEST_F(VkLayerTest, MiscImageLayerTests) {
11647
11648 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
11649
11650 ASSERT_NO_FATAL_FAILURE(InitState());
11651
11652 VkImageObj image(m_device);
11653 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11654 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11655 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11656 VK_IMAGE_TILING_OPTIMAL, 0);
11657 ASSERT_TRUE(image.initialized());
11658
11659 m_errorMonitor->SetDesiredFailureMsg(
11660 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11661 "number of layers in image subresource is zero");
11662 vk_testing::Buffer buffer;
11663 VkMemoryPropertyFlags reqs = 0;
11664 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
11665 VkBufferImageCopy region = {};
11666 region.bufferRowLength = 128;
11667 region.bufferImageHeight = 128;
11668 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11669 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
11670 region.imageSubresource.layerCount = 0;
11671 region.imageExtent.height = 4;
11672 region.imageExtent.width = 4;
11673 region.imageExtent.depth = 1;
11674 m_commandBuffer->BeginCommandBuffer();
11675 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11676 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11677 1, &region);
11678 m_errorMonitor->VerifyFound();
11679 region.imageSubresource.layerCount = 1;
11680
11681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11682 "aspectMasks for each region must "
11683 "specify only COLOR or DEPTH or "
11684 "STENCIL");
11685 // Expect MISMATCHED_IMAGE_ASPECT
11686 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
11687 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11688 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11689 1, &region);
11690 m_errorMonitor->VerifyFound();
11691 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11692
11693 m_errorMonitor->SetDesiredFailureMsg(
11694 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11695 "If the format of srcImage is a depth, stencil, depth stencil or "
11696 "integer-based format then filter must be VK_FILTER_NEAREST");
11697 // Expect INVALID_FILTER
11698 VkImageObj intImage1(m_device);
11699 intImage1.init(128, 128, VK_FORMAT_R8_UINT,
11700 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11701 0);
11702 VkImageObj intImage2(m_device);
11703 intImage2.init(128, 128, VK_FORMAT_R8_UINT,
11704 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11705 0);
11706 VkImageBlit blitRegion = {};
11707 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11708 blitRegion.srcSubresource.baseArrayLayer = 0;
11709 blitRegion.srcSubresource.layerCount = 1;
11710 blitRegion.srcSubresource.mipLevel = 0;
11711 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11712 blitRegion.dstSubresource.baseArrayLayer = 0;
11713 blitRegion.dstSubresource.layerCount = 1;
11714 blitRegion.dstSubresource.mipLevel = 0;
11715
11716 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(),
11717 intImage1.layout(), intImage2.handle(), intImage2.layout(),
11718 16, &blitRegion, VK_FILTER_LINEAR);
11719 m_errorMonitor->VerifyFound();
11720
11721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11722 "called with 0 in ppMemoryBarriers");
11723 VkImageMemoryBarrier img_barrier;
11724 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11725 img_barrier.pNext = NULL;
11726 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11727 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11728 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11729 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11730 img_barrier.image = image.handle();
11731 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11732 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11733 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11734 img_barrier.subresourceRange.baseArrayLayer = 0;
11735 img_barrier.subresourceRange.baseMipLevel = 0;
11736 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
11737 img_barrier.subresourceRange.layerCount = 0;
11738 img_barrier.subresourceRange.levelCount = 1;
11739 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
11740 VK_PIPELINE_STAGE_HOST_BIT,
11741 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
11742 nullptr, 1, &img_barrier);
11743 m_errorMonitor->VerifyFound();
11744 img_barrier.subresourceRange.layerCount = 1;
11745}
11746
11747TEST_F(VkLayerTest, ImageFormatLimits) {
11748
11749 TEST_DESCRIPTION("Exceed the limits of image format ");
11750
11751 m_errorMonitor->SetDesiredFailureMsg(
11752 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11753 "CreateImage extents exceed allowable limits for format");
11754 VkImageCreateInfo image_create_info = {};
11755 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11756 image_create_info.pNext = NULL;
11757 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11758 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11759 image_create_info.extent.width = 32;
11760 image_create_info.extent.height = 32;
11761 image_create_info.extent.depth = 1;
11762 image_create_info.mipLevels = 1;
11763 image_create_info.arrayLayers = 1;
11764 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11765 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11766 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11767 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11768 image_create_info.flags = 0;
11769
11770 VkImage nullImg;
11771 VkImageFormatProperties imgFmtProps;
11772 vkGetPhysicalDeviceImageFormatProperties(
11773 gpu(), image_create_info.format, image_create_info.imageType,
11774 image_create_info.tiling, image_create_info.usage,
11775 image_create_info.flags, &imgFmtProps);
11776 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
11777 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11778 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11779 m_errorMonitor->VerifyFound();
11780 image_create_info.extent.depth = 1;
11781
11782 m_errorMonitor->SetDesiredFailureMsg(
11783 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11784 "exceeds allowable maximum supported by format of");
11785 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
11786 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11787 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11788 m_errorMonitor->VerifyFound();
11789 image_create_info.mipLevels = 1;
11790
11791 m_errorMonitor->SetDesiredFailureMsg(
11792 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11793 "exceeds allowable maximum supported by format of");
11794 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
11795 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11796 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11797 m_errorMonitor->VerifyFound();
11798 image_create_info.arrayLayers = 1;
11799
11800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11801 "is not supported by format");
11802 int samples = imgFmtProps.sampleCounts >> 1;
11803 image_create_info.samples = (VkSampleCountFlagBits)samples;
11804 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11805 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11806 m_errorMonitor->VerifyFound();
11807 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11808
11809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11810 "pCreateInfo->initialLayout, must be "
11811 "VK_IMAGE_LAYOUT_UNDEFINED or "
11812 "VK_IMAGE_LAYOUT_PREINITIALIZED");
11813 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11814 // Expect INVALID_LAYOUT
11815 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11816 m_errorMonitor->VerifyFound();
11817 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11818}
11819
Karl Schultz6addd812016-02-02 17:17:23 -070011820TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060011821 VkResult err;
11822 bool pass;
11823
11824 // Create color images with different format sizes and try to copy between them
11825 m_errorMonitor->SetDesiredFailureMsg(
11826 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11827 "vkCmdCopyImage called with unmatched source and dest image format sizes");
11828
11829 ASSERT_NO_FATAL_FAILURE(InitState());
11830
11831 // Create two images of different types and try to copy between them
11832 VkImage srcImage;
11833 VkImage dstImage;
11834 VkDeviceMemory srcMem;
11835 VkDeviceMemory destMem;
11836 VkMemoryRequirements memReqs;
11837
11838 VkImageCreateInfo image_create_info = {};
11839 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11840 image_create_info.pNext = NULL;
11841 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11842 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11843 image_create_info.extent.width = 32;
11844 image_create_info.extent.height = 32;
11845 image_create_info.extent.depth = 1;
11846 image_create_info.mipLevels = 1;
11847 image_create_info.arrayLayers = 1;
11848 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11849 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11850 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11851 image_create_info.flags = 0;
11852
11853 err =
11854 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
11855 ASSERT_VK_SUCCESS(err);
11856
11857 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11858 // Introduce failure by creating second image with a different-sized format.
11859 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
11860
11861 err =
11862 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
11863 ASSERT_VK_SUCCESS(err);
11864
11865 // Allocate memory
11866 VkMemoryAllocateInfo memAlloc = {};
11867 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11868 memAlloc.pNext = NULL;
11869 memAlloc.allocationSize = 0;
11870 memAlloc.memoryTypeIndex = 0;
11871
11872 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
11873 memAlloc.allocationSize = memReqs.size;
11874 pass =
11875 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11876 ASSERT_TRUE(pass);
11877 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
11878 ASSERT_VK_SUCCESS(err);
11879
11880 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
11881 memAlloc.allocationSize = memReqs.size;
11882 pass =
11883 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11884 ASSERT_TRUE(pass);
11885 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
11886 ASSERT_VK_SUCCESS(err);
11887
11888 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11889 ASSERT_VK_SUCCESS(err);
11890 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
11891 ASSERT_VK_SUCCESS(err);
11892
11893 BeginCommandBuffer();
11894 VkImageCopy copyRegion;
11895 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11896 copyRegion.srcSubresource.mipLevel = 0;
11897 copyRegion.srcSubresource.baseArrayLayer = 0;
11898 copyRegion.srcSubresource.layerCount = 0;
11899 copyRegion.srcOffset.x = 0;
11900 copyRegion.srcOffset.y = 0;
11901 copyRegion.srcOffset.z = 0;
11902 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11903 copyRegion.dstSubresource.mipLevel = 0;
11904 copyRegion.dstSubresource.baseArrayLayer = 0;
11905 copyRegion.dstSubresource.layerCount = 0;
11906 copyRegion.dstOffset.x = 0;
11907 copyRegion.dstOffset.y = 0;
11908 copyRegion.dstOffset.z = 0;
11909 copyRegion.extent.width = 1;
11910 copyRegion.extent.height = 1;
11911 copyRegion.extent.depth = 1;
11912 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11913 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
11914 EndCommandBuffer();
11915
11916 m_errorMonitor->VerifyFound();
11917
11918 vkDestroyImage(m_device->device(), srcImage, NULL);
11919 vkDestroyImage(m_device->device(), dstImage, NULL);
11920 vkFreeMemory(m_device->device(), srcMem, NULL);
11921 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011922}
11923
Karl Schultz6addd812016-02-02 17:17:23 -070011924TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
11925 VkResult err;
11926 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011927
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011928 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011929 m_errorMonitor->SetDesiredFailureMsg(
11930 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011931 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011932
Mike Stroyana3082432015-09-25 13:39:21 -060011933 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011934
11935 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011936 VkImage srcImage;
11937 VkImage dstImage;
11938 VkDeviceMemory srcMem;
11939 VkDeviceMemory destMem;
11940 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011941
11942 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011943 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11944 image_create_info.pNext = NULL;
11945 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11946 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11947 image_create_info.extent.width = 32;
11948 image_create_info.extent.height = 32;
11949 image_create_info.extent.depth = 1;
11950 image_create_info.mipLevels = 1;
11951 image_create_info.arrayLayers = 1;
11952 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11953 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11954 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11955 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011956
Karl Schultz6addd812016-02-02 17:17:23 -070011957 err =
11958 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011959 ASSERT_VK_SUCCESS(err);
11960
Karl Schultzbdb75952016-04-19 11:36:49 -060011961 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11962
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011963 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070011964 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011965 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
11966 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011967
Karl Schultz6addd812016-02-02 17:17:23 -070011968 err =
11969 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011970 ASSERT_VK_SUCCESS(err);
11971
11972 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011973 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011974 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11975 memAlloc.pNext = NULL;
11976 memAlloc.allocationSize = 0;
11977 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011978
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011979 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011980 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011981 pass =
11982 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011983 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011984 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011985 ASSERT_VK_SUCCESS(err);
11986
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011987 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011988 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011989 pass =
11990 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011991 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011992 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011993 ASSERT_VK_SUCCESS(err);
11994
11995 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11996 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011997 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011998 ASSERT_VK_SUCCESS(err);
11999
12000 BeginCommandBuffer();
12001 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012002 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012003 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012004 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012005 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012006 copyRegion.srcOffset.x = 0;
12007 copyRegion.srcOffset.y = 0;
12008 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012009 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012010 copyRegion.dstSubresource.mipLevel = 0;
12011 copyRegion.dstSubresource.baseArrayLayer = 0;
12012 copyRegion.dstSubresource.layerCount = 0;
12013 copyRegion.dstOffset.x = 0;
12014 copyRegion.dstOffset.y = 0;
12015 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012016 copyRegion.extent.width = 1;
12017 copyRegion.extent.height = 1;
12018 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012019 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12020 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012021 EndCommandBuffer();
12022
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012023 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012024
Chia-I Wuf7458c52015-10-26 21:10:41 +080012025 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012026 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012027 vkFreeMemory(m_device->device(), srcMem, NULL);
12028 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012029}
12030
Karl Schultz6addd812016-02-02 17:17:23 -070012031TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
12032 VkResult err;
12033 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060012034
Karl Schultz6addd812016-02-02 17:17:23 -070012035 m_errorMonitor->SetDesiredFailureMsg(
12036 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012037 "vkCmdResolveImage called with source sample count less than 2.");
12038
Mike Stroyana3082432015-09-25 13:39:21 -060012039 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060012040
12041 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070012042 VkImage srcImage;
12043 VkImage dstImage;
12044 VkDeviceMemory srcMem;
12045 VkDeviceMemory destMem;
12046 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012047
12048 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012049 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12050 image_create_info.pNext = NULL;
12051 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12052 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12053 image_create_info.extent.width = 32;
12054 image_create_info.extent.height = 1;
12055 image_create_info.extent.depth = 1;
12056 image_create_info.mipLevels = 1;
12057 image_create_info.arrayLayers = 1;
12058 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12059 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12060 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
12061 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012062
Karl Schultz6addd812016-02-02 17:17:23 -070012063 err =
12064 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012065 ASSERT_VK_SUCCESS(err);
12066
Karl Schultz6addd812016-02-02 17:17:23 -070012067 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012068
Karl Schultz6addd812016-02-02 17:17:23 -070012069 err =
12070 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012071 ASSERT_VK_SUCCESS(err);
12072
12073 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012074 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012075 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12076 memAlloc.pNext = NULL;
12077 memAlloc.allocationSize = 0;
12078 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012079
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012080 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012081 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012082 pass =
12083 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012084 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012085 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012086 ASSERT_VK_SUCCESS(err);
12087
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012088 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012089 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012090 pass =
12091 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012092 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012093 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012094 ASSERT_VK_SUCCESS(err);
12095
12096 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12097 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012098 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012099 ASSERT_VK_SUCCESS(err);
12100
12101 BeginCommandBuffer();
12102 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012103 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12104 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012105 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012106 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012107 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012108 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012109 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012110 resolveRegion.srcOffset.x = 0;
12111 resolveRegion.srcOffset.y = 0;
12112 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012113 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012114 resolveRegion.dstSubresource.mipLevel = 0;
12115 resolveRegion.dstSubresource.baseArrayLayer = 0;
12116 resolveRegion.dstSubresource.layerCount = 0;
12117 resolveRegion.dstOffset.x = 0;
12118 resolveRegion.dstOffset.y = 0;
12119 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012120 resolveRegion.extent.width = 1;
12121 resolveRegion.extent.height = 1;
12122 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012123 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12124 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012125 EndCommandBuffer();
12126
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012127 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012128
Chia-I Wuf7458c52015-10-26 21:10:41 +080012129 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012130 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012131 vkFreeMemory(m_device->device(), srcMem, NULL);
12132 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012133}
12134
Karl Schultz6addd812016-02-02 17:17:23 -070012135TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
12136 VkResult err;
12137 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060012138
Karl Schultz6addd812016-02-02 17:17:23 -070012139 m_errorMonitor->SetDesiredFailureMsg(
12140 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012141 "vkCmdResolveImage called with dest sample count greater than 1.");
12142
Mike Stroyana3082432015-09-25 13:39:21 -060012143 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060012144
Chris Forbesa7530692016-05-08 12:35:39 +120012145 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070012146 VkImage srcImage;
12147 VkImage dstImage;
12148 VkDeviceMemory srcMem;
12149 VkDeviceMemory destMem;
12150 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012151
12152 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012153 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12154 image_create_info.pNext = NULL;
12155 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12156 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12157 image_create_info.extent.width = 32;
12158 image_create_info.extent.height = 1;
12159 image_create_info.extent.depth = 1;
12160 image_create_info.mipLevels = 1;
12161 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120012162 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070012163 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12164 // Note: Some implementations expect color attachment usage for any
12165 // multisample surface
12166 image_create_info.usage =
12167 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12168 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012169
Karl Schultz6addd812016-02-02 17:17:23 -070012170 err =
12171 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012172 ASSERT_VK_SUCCESS(err);
12173
Karl Schultz6addd812016-02-02 17:17:23 -070012174 // Note: Some implementations expect color attachment usage for any
12175 // multisample surface
12176 image_create_info.usage =
12177 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012178
Karl Schultz6addd812016-02-02 17:17:23 -070012179 err =
12180 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012181 ASSERT_VK_SUCCESS(err);
12182
12183 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012184 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012185 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12186 memAlloc.pNext = NULL;
12187 memAlloc.allocationSize = 0;
12188 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012189
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012190 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012191 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012192 pass =
12193 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012194 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012195 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012196 ASSERT_VK_SUCCESS(err);
12197
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012198 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012199 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012200 pass =
12201 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012202 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012203 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012204 ASSERT_VK_SUCCESS(err);
12205
12206 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12207 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012208 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012209 ASSERT_VK_SUCCESS(err);
12210
12211 BeginCommandBuffer();
12212 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012213 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12214 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012215 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012216 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012217 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012218 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012219 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012220 resolveRegion.srcOffset.x = 0;
12221 resolveRegion.srcOffset.y = 0;
12222 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012223 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012224 resolveRegion.dstSubresource.mipLevel = 0;
12225 resolveRegion.dstSubresource.baseArrayLayer = 0;
12226 resolveRegion.dstSubresource.layerCount = 0;
12227 resolveRegion.dstOffset.x = 0;
12228 resolveRegion.dstOffset.y = 0;
12229 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012230 resolveRegion.extent.width = 1;
12231 resolveRegion.extent.height = 1;
12232 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012233 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12234 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012235 EndCommandBuffer();
12236
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012237 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012238
Chia-I Wuf7458c52015-10-26 21:10:41 +080012239 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012240 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012241 vkFreeMemory(m_device->device(), srcMem, NULL);
12242 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012243}
12244
Karl Schultz6addd812016-02-02 17:17:23 -070012245TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
12246 VkResult err;
12247 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060012248
Karl Schultz6addd812016-02-02 17:17:23 -070012249 m_errorMonitor->SetDesiredFailureMsg(
12250 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012251 "vkCmdResolveImage called with unmatched source and dest formats.");
12252
Mike Stroyana3082432015-09-25 13:39:21 -060012253 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060012254
12255 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070012256 VkImage srcImage;
12257 VkImage dstImage;
12258 VkDeviceMemory srcMem;
12259 VkDeviceMemory destMem;
12260 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012261
12262 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012263 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12264 image_create_info.pNext = NULL;
12265 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12266 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12267 image_create_info.extent.width = 32;
12268 image_create_info.extent.height = 1;
12269 image_create_info.extent.depth = 1;
12270 image_create_info.mipLevels = 1;
12271 image_create_info.arrayLayers = 1;
12272 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
12273 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12274 // Note: Some implementations expect color attachment usage for any
12275 // multisample surface
12276 image_create_info.usage =
12277 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12278 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012279
Karl Schultz6addd812016-02-02 17:17:23 -070012280 err =
12281 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012282 ASSERT_VK_SUCCESS(err);
12283
Karl Schultz6addd812016-02-02 17:17:23 -070012284 // Set format to something other than source image
12285 image_create_info.format = VK_FORMAT_R32_SFLOAT;
12286 // Note: Some implementations expect color attachment usage for any
12287 // multisample surface
12288 image_create_info.usage =
12289 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12290 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012291
Karl Schultz6addd812016-02-02 17:17:23 -070012292 err =
12293 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012294 ASSERT_VK_SUCCESS(err);
12295
12296 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012297 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012298 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12299 memAlloc.pNext = NULL;
12300 memAlloc.allocationSize = 0;
12301 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012302
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012303 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012304 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012305 pass =
12306 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012307 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012308 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012309 ASSERT_VK_SUCCESS(err);
12310
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012311 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012312 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012313 pass =
12314 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012315 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012316 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012317 ASSERT_VK_SUCCESS(err);
12318
12319 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12320 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012321 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012322 ASSERT_VK_SUCCESS(err);
12323
12324 BeginCommandBuffer();
12325 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012326 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12327 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012328 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012329 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012330 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012331 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012332 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012333 resolveRegion.srcOffset.x = 0;
12334 resolveRegion.srcOffset.y = 0;
12335 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012336 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012337 resolveRegion.dstSubresource.mipLevel = 0;
12338 resolveRegion.dstSubresource.baseArrayLayer = 0;
12339 resolveRegion.dstSubresource.layerCount = 0;
12340 resolveRegion.dstOffset.x = 0;
12341 resolveRegion.dstOffset.y = 0;
12342 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012343 resolveRegion.extent.width = 1;
12344 resolveRegion.extent.height = 1;
12345 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012346 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12347 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012348 EndCommandBuffer();
12349
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012350 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012351
Chia-I Wuf7458c52015-10-26 21:10:41 +080012352 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012353 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012354 vkFreeMemory(m_device->device(), srcMem, NULL);
12355 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012356}
12357
Karl Schultz6addd812016-02-02 17:17:23 -070012358TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
12359 VkResult err;
12360 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060012361
Karl Schultz6addd812016-02-02 17:17:23 -070012362 m_errorMonitor->SetDesiredFailureMsg(
12363 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012364 "vkCmdResolveImage called with unmatched source and dest image types.");
12365
Mike Stroyana3082432015-09-25 13:39:21 -060012366 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060012367
12368 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070012369 VkImage srcImage;
12370 VkImage dstImage;
12371 VkDeviceMemory srcMem;
12372 VkDeviceMemory destMem;
12373 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012374
12375 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012376 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12377 image_create_info.pNext = NULL;
12378 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12379 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12380 image_create_info.extent.width = 32;
12381 image_create_info.extent.height = 1;
12382 image_create_info.extent.depth = 1;
12383 image_create_info.mipLevels = 1;
12384 image_create_info.arrayLayers = 1;
12385 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
12386 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12387 // Note: Some implementations expect color attachment usage for any
12388 // multisample surface
12389 image_create_info.usage =
12390 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12391 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012392
Karl Schultz6addd812016-02-02 17:17:23 -070012393 err =
12394 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012395 ASSERT_VK_SUCCESS(err);
12396
Karl Schultz6addd812016-02-02 17:17:23 -070012397 image_create_info.imageType = VK_IMAGE_TYPE_1D;
12398 // Note: Some implementations expect color attachment usage for any
12399 // multisample surface
12400 image_create_info.usage =
12401 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12402 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012403
Karl Schultz6addd812016-02-02 17:17:23 -070012404 err =
12405 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012406 ASSERT_VK_SUCCESS(err);
12407
12408 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012409 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012410 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12411 memAlloc.pNext = NULL;
12412 memAlloc.allocationSize = 0;
12413 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012414
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012415 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012416 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012417 pass =
12418 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012419 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012420 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012421 ASSERT_VK_SUCCESS(err);
12422
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012423 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012424 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012425 pass =
12426 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012427 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012428 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012429 ASSERT_VK_SUCCESS(err);
12430
12431 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12432 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012433 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012434 ASSERT_VK_SUCCESS(err);
12435
12436 BeginCommandBuffer();
12437 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012438 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12439 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012440 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012441 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012442 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012443 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012444 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012445 resolveRegion.srcOffset.x = 0;
12446 resolveRegion.srcOffset.y = 0;
12447 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012448 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012449 resolveRegion.dstSubresource.mipLevel = 0;
12450 resolveRegion.dstSubresource.baseArrayLayer = 0;
12451 resolveRegion.dstSubresource.layerCount = 0;
12452 resolveRegion.dstOffset.x = 0;
12453 resolveRegion.dstOffset.y = 0;
12454 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012455 resolveRegion.extent.width = 1;
12456 resolveRegion.extent.height = 1;
12457 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012458 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12459 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012460 EndCommandBuffer();
12461
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012462 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012463
Chia-I Wuf7458c52015-10-26 21:10:41 +080012464 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012465 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012466 vkFreeMemory(m_device->device(), srcMem, NULL);
12467 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012468}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012469
Karl Schultz6addd812016-02-02 17:17:23 -070012470TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012471 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070012472 // to using a DS format, then cause it to hit error due to COLOR_BIT not
12473 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012474 // The image format check comes 2nd in validation so we trigger it first,
12475 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070012476 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012477
Karl Schultz6addd812016-02-02 17:17:23 -070012478 m_errorMonitor->SetDesiredFailureMsg(
12479 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012480 "Combination depth/stencil image formats can have only the ");
12481
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012482 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012483
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012484 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012485 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12486 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012487
12488 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012489 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12490 ds_pool_ci.pNext = NULL;
12491 ds_pool_ci.maxSets = 1;
12492 ds_pool_ci.poolSizeCount = 1;
12493 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012494
12495 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -070012496 err =
12497 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012498 ASSERT_VK_SUCCESS(err);
12499
12500 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012501 dsl_binding.binding = 0;
12502 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12503 dsl_binding.descriptorCount = 1;
12504 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12505 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012506
12507 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012508 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12509 ds_layout_ci.pNext = NULL;
12510 ds_layout_ci.bindingCount = 1;
12511 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012512 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012513 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
12514 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012515 ASSERT_VK_SUCCESS(err);
12516
12517 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012518 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012519 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012520 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012521 alloc_info.descriptorPool = ds_pool;
12522 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012523 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
12524 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012525 ASSERT_VK_SUCCESS(err);
12526
Karl Schultz6addd812016-02-02 17:17:23 -070012527 VkImage image_bad;
12528 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012529 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060012530 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012531 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070012532 const int32_t tex_width = 32;
12533 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012534
12535 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012536 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12537 image_create_info.pNext = NULL;
12538 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12539 image_create_info.format = tex_format_bad;
12540 image_create_info.extent.width = tex_width;
12541 image_create_info.extent.height = tex_height;
12542 image_create_info.extent.depth = 1;
12543 image_create_info.mipLevels = 1;
12544 image_create_info.arrayLayers = 1;
12545 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12546 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12547 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
12548 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12549 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012550
Karl Schultz6addd812016-02-02 17:17:23 -070012551 err =
12552 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012553 ASSERT_VK_SUCCESS(err);
12554 image_create_info.format = tex_format_good;
Karl Schultz6addd812016-02-02 17:17:23 -070012555 image_create_info.usage =
12556 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12557 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
12558 &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012559 ASSERT_VK_SUCCESS(err);
12560
12561 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012562 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12563 image_view_create_info.image = image_bad;
12564 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
12565 image_view_create_info.format = tex_format_bad;
12566 image_view_create_info.subresourceRange.baseArrayLayer = 0;
12567 image_view_create_info.subresourceRange.baseMipLevel = 0;
12568 image_view_create_info.subresourceRange.layerCount = 1;
12569 image_view_create_info.subresourceRange.levelCount = 1;
12570 image_view_create_info.subresourceRange.aspectMask =
12571 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012572
12573 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070012574 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
12575 &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012576
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012577 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012578
Chia-I Wuf7458c52015-10-26 21:10:41 +080012579 vkDestroyImage(m_device->device(), image_bad, NULL);
12580 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012581 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12582 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012583}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012584
12585TEST_F(VkLayerTest, ClearImageErrors) {
12586 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
12587 "ClearDepthStencilImage with a color image.");
12588
12589 ASSERT_NO_FATAL_FAILURE(InitState());
12590 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12591
12592 // Renderpass is started here so end it as Clear cmds can't be in renderpass
12593 BeginCommandBuffer();
12594 m_commandBuffer->EndRenderPass();
12595
12596 // Color image
12597 VkClearColorValue clear_color;
12598 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
12599 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
12600 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
12601 const int32_t img_width = 32;
12602 const int32_t img_height = 32;
12603 VkImageCreateInfo image_create_info = {};
12604 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12605 image_create_info.pNext = NULL;
12606 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12607 image_create_info.format = color_format;
12608 image_create_info.extent.width = img_width;
12609 image_create_info.extent.height = img_height;
12610 image_create_info.extent.depth = 1;
12611 image_create_info.mipLevels = 1;
12612 image_create_info.arrayLayers = 1;
12613 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12614 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
12615 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
12616
12617 vk_testing::Image color_image;
12618 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info,
12619 reqs);
12620
12621 const VkImageSubresourceRange color_range =
12622 vk_testing::Image::subresource_range(image_create_info,
12623 VK_IMAGE_ASPECT_COLOR_BIT);
12624
12625 // Depth/Stencil image
12626 VkClearDepthStencilValue clear_value = {0};
12627 reqs = 0; // don't need HOST_VISIBLE DS image
12628 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
12629 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
12630 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
12631 ds_image_create_info.extent.width = 64;
12632 ds_image_create_info.extent.height = 64;
12633 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12634 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12635
12636 vk_testing::Image ds_image;
12637 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info,
12638 reqs);
12639
12640 const VkImageSubresourceRange ds_range =
12641 vk_testing::Image::subresource_range(ds_image_create_info,
12642 VK_IMAGE_ASPECT_DEPTH_BIT);
12643
12644 m_errorMonitor->SetDesiredFailureMsg(
12645 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12646 "vkCmdClearColorImage called with depth/stencil image.");
12647
12648 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12649 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12650 &color_range);
12651
12652 m_errorMonitor->VerifyFound();
12653
Tony Barbour26434b92016-06-02 09:43:50 -060012654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12655 "vkCmdClearColorImage called with "
12656 "image created without "
12657 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
12658
12659 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12660 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12661 &color_range);
12662
12663 m_errorMonitor->VerifyFound();
12664
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012665 // Call CmdClearDepthStencilImage with color image
12666 m_errorMonitor->SetDesiredFailureMsg(
12667 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12668 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
12669
12670 vkCmdClearDepthStencilImage(
12671 m_commandBuffer->GetBufferHandle(), color_image.handle(),
12672 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
12673 &ds_range);
12674
12675 m_errorMonitor->VerifyFound();
12676}
Tobin Ehliscde08892015-09-22 10:11:37 -060012677#endif // IMAGE_TESTS
12678
Tony Barbour300a6082015-04-07 13:44:53 -060012679int main(int argc, char **argv) {
12680 int result;
12681
Cody Northrop8e54a402016-03-08 22:25:52 -070012682#ifdef ANDROID
12683 int vulkanSupport = InitVulkan();
12684 if (vulkanSupport == 0)
12685 return 1;
12686#endif
12687
Tony Barbour300a6082015-04-07 13:44:53 -060012688 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060012689 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060012690
12691 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
12692
12693 result = RUN_ALL_TESTS();
12694
Tony Barbour6918cd52015-04-09 12:58:51 -060012695 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060012696 return result;
12697}