blob: ade634f6ffe0ea2a3a9dc0171b60883b058f923b [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 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800255 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
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
Tony Barboureb254902015-07-15 12:50:33 -06007311 VkRenderPassBeginInfo rp_begin = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007312 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7313 rp_begin.pNext = NULL;
7314 rp_begin.renderPass = renderPass();
7315 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007316
Karl Schultz6addd812016-02-02 17:17:23 -07007317 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
7318 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007319
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007320 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007321}
7322
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007323TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7324 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7325 "the number of renderPass attachments that use loadOp"
7326 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7327
7328 ASSERT_NO_FATAL_FAILURE(InitState());
7329 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7330
7331 // Create a renderPass with a single attachment that uses loadOp CLEAR
7332 VkAttachmentReference attach = {};
7333 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7334 VkSubpassDescription subpass = {};
7335 subpass.inputAttachmentCount = 1;
7336 subpass.pInputAttachments = &attach;
7337 VkRenderPassCreateInfo rpci = {};
7338 rpci.subpassCount = 1;
7339 rpci.pSubpasses = &subpass;
7340 rpci.attachmentCount = 1;
7341 VkAttachmentDescription attach_desc = {};
7342 attach_desc.format = VK_FORMAT_UNDEFINED;
7343 // Set loadOp to CLEAR
7344 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7345 rpci.pAttachments = &attach_desc;
7346 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7347 VkRenderPass rp;
7348 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7349
7350 VkCommandBufferInheritanceInfo hinfo = {};
7351 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7352 hinfo.renderPass = VK_NULL_HANDLE;
7353 hinfo.subpass = 0;
7354 hinfo.framebuffer = VK_NULL_HANDLE;
7355 hinfo.occlusionQueryEnable = VK_FALSE;
7356 hinfo.queryFlags = 0;
7357 hinfo.pipelineStatistics = 0;
7358 VkCommandBufferBeginInfo info = {};
7359 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7360 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7361 info.pInheritanceInfo = &hinfo;
7362
7363 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7364 VkRenderPassBeginInfo rp_begin = {};
7365 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7366 rp_begin.pNext = NULL;
7367 rp_begin.renderPass = renderPass();
7368 rp_begin.framebuffer = framebuffer();
7369 rp_begin.clearValueCount = 0; // Should be 1
7370
7371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7372 " has a clearValueCount of 0 but the "
7373 "actual number of attachments in "
7374 "renderPass ");
7375
7376 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
7377 VK_SUBPASS_CONTENTS_INLINE);
7378
7379 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007380
7381 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007382}
7383
Cody Northrop3bb4d962016-05-09 16:15:57 -06007384TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7385
7386 TEST_DESCRIPTION("End a command buffer with an active render pass");
7387
7388 m_errorMonitor->SetDesiredFailureMsg(
7389 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7390 "It is invalid to issue this call inside an active render pass");
7391
7392 ASSERT_NO_FATAL_FAILURE(InitState());
7393 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7394
7395 // The framework's BeginCommandBuffer calls CreateRenderPass
7396 BeginCommandBuffer();
7397
7398 // Call directly into vkEndCommandBuffer instead of the
7399 // the framework's EndCommandBuffer, which inserts a
7400 // vkEndRenderPass
7401 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7402
7403 m_errorMonitor->VerifyFound();
7404
7405 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7406 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
7407}
7408
Karl Schultz6addd812016-02-02 17:17:23 -07007409TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007410 // Call CmdFillBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07007411 m_errorMonitor->SetDesiredFailureMsg(
7412 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007413 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007414
7415 ASSERT_NO_FATAL_FAILURE(InitState());
7416 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007417
7418 // Renderpass is started here
7419 BeginCommandBuffer();
7420
7421 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007422 vk_testing::Buffer dstBuffer;
7423 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007424
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007425 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007426
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007427 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007428}
7429
Karl Schultz6addd812016-02-02 17:17:23 -07007430TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007431 // Call CmdUpdateBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07007432 m_errorMonitor->SetDesiredFailureMsg(
7433 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007434 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007435
7436 ASSERT_NO_FATAL_FAILURE(InitState());
7437 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007438
7439 // Renderpass is started here
7440 BeginCommandBuffer();
7441
7442 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007443 vk_testing::Buffer dstBuffer;
7444 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007445
Karl Schultz6addd812016-02-02 17:17:23 -07007446 VkDeviceSize dstOffset = 0;
7447 VkDeviceSize dataSize = 1024;
7448 const uint32_t *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007449
Karl Schultz6addd812016-02-02 17:17:23 -07007450 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
7451 dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007452
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007453 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007454}
7455
Karl Schultz6addd812016-02-02 17:17:23 -07007456TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007457 // Call CmdClearColorImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007458 m_errorMonitor->SetDesiredFailureMsg(
7459 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007460 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007461
7462 ASSERT_NO_FATAL_FAILURE(InitState());
7463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007464
7465 // Renderpass is started here
7466 BeginCommandBuffer();
7467
Michael Lentine0a369f62016-02-03 16:51:46 -06007468 VkClearColorValue clear_color;
7469 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007470 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7471 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7472 const int32_t tex_width = 32;
7473 const int32_t tex_height = 32;
7474 VkImageCreateInfo image_create_info = {};
7475 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7476 image_create_info.pNext = NULL;
7477 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7478 image_create_info.format = tex_format;
7479 image_create_info.extent.width = tex_width;
7480 image_create_info.extent.height = tex_height;
7481 image_create_info.extent.depth = 1;
7482 image_create_info.mipLevels = 1;
7483 image_create_info.arrayLayers = 1;
7484 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7485 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7486 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007487
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007488 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07007489 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
7490 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007491
Karl Schultz6addd812016-02-02 17:17:23 -07007492 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
7493 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007494
Karl Schultz6addd812016-02-02 17:17:23 -07007495 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7496 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007497
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007498 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007499}
7500
Karl Schultz6addd812016-02-02 17:17:23 -07007501TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007502 // Call CmdClearDepthStencilImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007503 m_errorMonitor->SetDesiredFailureMsg(
7504 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007505 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007506
7507 ASSERT_NO_FATAL_FAILURE(InitState());
7508 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007509
7510 // Renderpass is started here
7511 BeginCommandBuffer();
7512
7513 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007514 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007515 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7516 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7517 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7518 image_create_info.extent.width = 64;
7519 image_create_info.extent.height = 64;
7520 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7521 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007522
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007523 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07007524 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
7525 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007526
Karl Schultz6addd812016-02-02 17:17:23 -07007527 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
7528 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007529
Karl Schultz6addd812016-02-02 17:17:23 -07007530 vkCmdClearDepthStencilImage(
7531 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7532 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
7533 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007534
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007535 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007536}
7537
Karl Schultz6addd812016-02-02 17:17:23 -07007538TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007539 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007540 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007541
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007543 "vkCmdClearAttachments: This call "
7544 "must be issued inside an active "
7545 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007546
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007547 ASSERT_NO_FATAL_FAILURE(InitState());
7548 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007549
7550 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007551 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007552 ASSERT_VK_SUCCESS(err);
7553
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007554 VkClearAttachment color_attachment;
7555 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7556 color_attachment.clearValue.color.float32[0] = 0;
7557 color_attachment.clearValue.color.float32[1] = 0;
7558 color_attachment.clearValue.color.float32[2] = 0;
7559 color_attachment.clearValue.color.float32[3] = 0;
7560 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007561 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
7562 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
7563 &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007564
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007565 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007566}
7567
Karl Schultz9e66a292016-04-21 15:57:51 -06007568TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
7569 // Try to add a buffer memory barrier with no buffer.
7570 m_errorMonitor->SetDesiredFailureMsg(
7571 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7572 "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE");
7573
7574 ASSERT_NO_FATAL_FAILURE(InitState());
7575 BeginCommandBuffer();
7576
7577 VkBufferMemoryBarrier buf_barrier = {};
7578 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7579 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7580 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7581 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7582 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7583 buf_barrier.buffer = VK_NULL_HANDLE;
7584 buf_barrier.offset = 0;
7585 buf_barrier.size = VK_WHOLE_SIZE;
7586 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7587 VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
7588 0, 0, nullptr, 1, &buf_barrier, 0, nullptr);
7589
7590 m_errorMonitor->VerifyFound();
7591}
7592
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007593TEST_F(VkLayerTest, InvalidBarriers) {
7594 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
7595
7596 m_errorMonitor->SetDesiredFailureMsg(
7597 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
7598
7599 ASSERT_NO_FATAL_FAILURE(InitState());
7600 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7601
7602 VkMemoryBarrier mem_barrier = {};
7603 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
7604 mem_barrier.pNext = NULL;
7605 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7606 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7607 BeginCommandBuffer();
7608 // BeginCommandBuffer() starts a render pass
7609 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7610 VK_PIPELINE_STAGE_HOST_BIT,
7611 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
7612 &mem_barrier, 0, nullptr, 0, nullptr);
7613 m_errorMonitor->VerifyFound();
7614
7615 m_errorMonitor->SetDesiredFailureMsg(
7616 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7617 "Image Layout cannot be transitioned to UNDEFINED");
7618 VkImageObj image(m_device);
7619 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
7620 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
7621 ASSERT_TRUE(image.initialized());
7622 VkImageMemoryBarrier img_barrier = {};
7623 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
7624 img_barrier.pNext = NULL;
7625 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7626 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7627 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7628 // New layout can't be UNDEFINED
7629 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
7630 img_barrier.image = image.handle();
7631 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7632 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7633 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7634 img_barrier.subresourceRange.baseArrayLayer = 0;
7635 img_barrier.subresourceRange.baseMipLevel = 0;
7636 img_barrier.subresourceRange.layerCount = 1;
7637 img_barrier.subresourceRange.levelCount = 1;
7638 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7639 VK_PIPELINE_STAGE_HOST_BIT,
7640 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7641 nullptr, 1, &img_barrier);
7642 m_errorMonitor->VerifyFound();
7643 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7644
7645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7646 "Subresource must have the sum of the "
7647 "baseArrayLayer");
7648 // baseArrayLayer + layerCount must be <= image's arrayLayers
7649 img_barrier.subresourceRange.baseArrayLayer = 1;
7650 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7651 VK_PIPELINE_STAGE_HOST_BIT,
7652 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7653 nullptr, 1, &img_barrier);
7654 m_errorMonitor->VerifyFound();
7655 img_barrier.subresourceRange.baseArrayLayer = 0;
7656
7657 m_errorMonitor->SetDesiredFailureMsg(
7658 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7659 "Subresource must have the sum of the baseMipLevel");
7660 // baseMipLevel + levelCount must be <= image's mipLevels
7661 img_barrier.subresourceRange.baseMipLevel = 1;
7662 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7663 VK_PIPELINE_STAGE_HOST_BIT,
7664 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7665 nullptr, 1, &img_barrier);
7666 m_errorMonitor->VerifyFound();
7667 img_barrier.subresourceRange.baseMipLevel = 0;
7668
7669 m_errorMonitor->SetDesiredFailureMsg(
7670 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7671 "Buffer Barriers cannot be used during a render pass");
7672 vk_testing::Buffer buffer;
7673 buffer.init(*m_device, 256);
7674 VkBufferMemoryBarrier buf_barrier = {};
7675 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7676 buf_barrier.pNext = NULL;
7677 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7678 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7679 buf_barrier.buffer = buffer.handle();
7680 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7681 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7682 buf_barrier.offset = 0;
7683 buf_barrier.size = VK_WHOLE_SIZE;
7684 // Can't send buffer barrier during a render pass
7685 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7686 VK_PIPELINE_STAGE_HOST_BIT,
7687 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7688 &buf_barrier, 0, nullptr);
7689 m_errorMonitor->VerifyFound();
7690 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7691
7692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7693 "which is not less than total size");
7694 buf_barrier.offset = 257;
7695 // Offset greater than total size
7696 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7697 VK_PIPELINE_STAGE_HOST_BIT,
7698 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7699 &buf_barrier, 0, nullptr);
7700 m_errorMonitor->VerifyFound();
7701 buf_barrier.offset = 0;
7702
7703 m_errorMonitor->SetDesiredFailureMsg(
7704 VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
7705 buf_barrier.size = 257;
7706 // Size greater than total size
7707 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7708 VK_PIPELINE_STAGE_HOST_BIT,
7709 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7710 &buf_barrier, 0, nullptr);
7711 m_errorMonitor->VerifyFound();
7712 buf_barrier.size = VK_WHOLE_SIZE;
7713
7714 m_errorMonitor->SetDesiredFailureMsg(
7715 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7716 "Image is a depth and stencil format and thus must "
7717 "have both VK_IMAGE_ASPECT_DEPTH_BIT and "
7718 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
7719 VkDepthStencilObj ds_image(m_device);
7720 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
7721 ASSERT_TRUE(ds_image.initialized());
7722 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7723 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
7724 img_barrier.image = ds_image.handle();
7725 // Leave aspectMask at COLOR on purpose
7726 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7727 VK_PIPELINE_STAGE_HOST_BIT,
7728 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7729 nullptr, 1, &img_barrier);
7730 m_errorMonitor->VerifyFound();
7731}
7732
Karl Schultz6addd812016-02-02 17:17:23 -07007733TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007734 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007735 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007736
Karl Schultz6addd812016-02-02 17:17:23 -07007737 m_errorMonitor->SetDesiredFailureMsg(
7738 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007739 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
7740
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007741 ASSERT_NO_FATAL_FAILURE(InitState());
7742 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007743 uint32_t qfi = 0;
7744 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007745 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7746 buffCI.size = 1024;
7747 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7748 buffCI.queueFamilyIndexCount = 1;
7749 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007750
7751 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007752 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007753 ASSERT_VK_SUCCESS(err);
7754
7755 BeginCommandBuffer();
7756 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007757 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7758 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007759 // Should error before calling to driver so don't care about actual data
Karl Schultz6addd812016-02-02 17:17:23 -07007760 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
7761 VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007762
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007763 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007764
Chia-I Wuf7458c52015-10-26 21:10:41 +08007765 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007766}
7767
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007768TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
7769 // Create an out-of-range queueFamilyIndex
7770 m_errorMonitor->SetDesiredFailureMsg(
7771 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesde628532016-04-21 16:30:17 -06007772 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
7773 "of the indices specified when the device was created, via the "
7774 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007775
7776 ASSERT_NO_FATAL_FAILURE(InitState());
7777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7778 VkBufferCreateInfo buffCI = {};
7779 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7780 buffCI.size = 1024;
7781 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7782 buffCI.queueFamilyIndexCount = 1;
7783 // Introduce failure by specifying invalid queue_family_index
7784 uint32_t qfi = 777;
7785 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06007786 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007787
7788 VkBuffer ib;
7789 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
7790
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007791 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007792 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007793}
7794
Karl Schultz6addd812016-02-02 17:17:23 -07007795TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
7796 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
7797 // secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007798
Karl Schultz6addd812016-02-02 17:17:23 -07007799 m_errorMonitor->SetDesiredFailureMsg(
7800 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007801 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007802
7803 ASSERT_NO_FATAL_FAILURE(InitState());
7804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007805
7806 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007807 // ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007808 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
7809 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007810
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007811 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007812}
7813
Tobin Ehlis17826bd2016-05-25 11:12:50 -06007814TEST_F(VkLayerTest, DSUsageBitsErrors) {
7815 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
7816 "that do not have correct usage bits sets.");
7817 VkResult err;
7818
7819 ASSERT_NO_FATAL_FAILURE(InitState());
7820 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
7821 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7822 ds_type_count[i].type = VkDescriptorType(i);
7823 ds_type_count[i].descriptorCount = 1;
7824 }
7825 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7826 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7827 ds_pool_ci.pNext = NULL;
7828 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7829 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7830 ds_pool_ci.pPoolSizes = ds_type_count;
7831
7832 VkDescriptorPool ds_pool;
7833 err =
7834 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7835 ASSERT_VK_SUCCESS(err);
7836
7837 // Create 10 layouts where each has a single descriptor of different type
7838 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] =
7839 {};
7840 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7841 dsl_binding[i].binding = 0;
7842 dsl_binding[i].descriptorType = VkDescriptorType(i);
7843 dsl_binding[i].descriptorCount = 1;
7844 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
7845 dsl_binding[i].pImmutableSamplers = NULL;
7846 }
7847
7848 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7849 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7850 ds_layout_ci.pNext = NULL;
7851 ds_layout_ci.bindingCount = 1;
7852 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
7853 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7854 ds_layout_ci.pBindings = dsl_binding + i;
7855 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci,
7856 NULL, ds_layouts + i);
7857 ASSERT_VK_SUCCESS(err);
7858 }
7859 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
7860 VkDescriptorSetAllocateInfo alloc_info = {};
7861 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7862 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7863 alloc_info.descriptorPool = ds_pool;
7864 alloc_info.pSetLayouts = ds_layouts;
7865 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7866 descriptor_sets);
7867 ASSERT_VK_SUCCESS(err);
7868
7869 // Create a buffer & bufferView to be used for invalid updates
7870 VkBufferCreateInfo buff_ci = {};
7871 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7872 // This usage is not valid for any descriptor type
7873 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
7874 buff_ci.size = 256;
7875 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7876 VkBuffer buffer;
7877 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7878 ASSERT_VK_SUCCESS(err);
7879
7880 VkBufferViewCreateInfo buff_view_ci = {};
7881 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7882 buff_view_ci.buffer = buffer;
7883 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7884 buff_view_ci.range = VK_WHOLE_SIZE;
7885 VkBufferView buff_view;
7886 err =
7887 vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
7888 ASSERT_VK_SUCCESS(err);
7889
7890 // Create an image to be used for invalid updates
7891 VkImageCreateInfo image_ci = {};
7892 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7893 image_ci.imageType = VK_IMAGE_TYPE_2D;
7894 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
7895 image_ci.extent.width = 64;
7896 image_ci.extent.height = 64;
7897 image_ci.extent.depth = 1;
7898 image_ci.mipLevels = 1;
7899 image_ci.arrayLayers = 1;
7900 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
7901 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
7902 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
7903 // This usage is not valid for any descriptor type
7904 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
7905 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7906 VkImage image;
7907 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
7908 ASSERT_VK_SUCCESS(err);
7909 // Bind memory to image
7910 VkMemoryRequirements mem_reqs;
7911 VkDeviceMemory image_mem;
7912 bool pass;
7913 VkMemoryAllocateInfo mem_alloc = {};
7914 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7915 mem_alloc.pNext = NULL;
7916 mem_alloc.allocationSize = 0;
7917 mem_alloc.memoryTypeIndex = 0;
7918 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
7919 mem_alloc.allocationSize = mem_reqs.size;
7920 pass =
7921 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
7922 ASSERT_TRUE(pass);
7923 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
7924 ASSERT_VK_SUCCESS(err);
7925 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
7926 ASSERT_VK_SUCCESS(err);
7927 // Now create view for image
7928 VkImageViewCreateInfo image_view_ci = {};
7929 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7930 image_view_ci.image = image;
7931 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
7932 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
7933 image_view_ci.subresourceRange.layerCount = 1;
7934 image_view_ci.subresourceRange.baseArrayLayer = 0;
7935 image_view_ci.subresourceRange.levelCount = 1;
7936 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7937 VkImageView image_view;
7938 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL,
7939 &image_view);
7940 ASSERT_VK_SUCCESS(err);
7941
7942 VkDescriptorBufferInfo buff_info = {};
7943 buff_info.buffer = buffer;
7944 VkDescriptorImageInfo img_info = {};
7945 img_info.imageView = image_view;
7946 VkWriteDescriptorSet descriptor_write = {};
7947 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7948 descriptor_write.dstBinding = 0;
7949 descriptor_write.descriptorCount = 1;
7950 descriptor_write.pTexelBufferView = &buff_view;
7951 descriptor_write.pBufferInfo = &buff_info;
7952 descriptor_write.pImageInfo = &img_info;
7953
7954 // These error messages align with VkDescriptorType struct
7955 const char *error_msgs[] = {
7956 "", // placeholder, no error for SAMPLER descriptor
7957 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
7958 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
7959 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
7960 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
7961 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
7962 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
7963 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
7964 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
7965 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
7966 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
7967 // Start loop at 1 as SAMPLER desc type has no usage bit error
7968 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7969 descriptor_write.descriptorType = VkDescriptorType(i);
7970 descriptor_write.dstSet = descriptor_sets[i];
7971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7972 error_msgs[i]);
7973
7974 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0,
7975 NULL);
7976
7977 m_errorMonitor->VerifyFound();
7978 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
7979 }
7980 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
7981 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007982 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06007983 vkDestroyImageView(m_device->device(), image_view, NULL);
7984 vkDestroyBuffer(m_device->device(), buffer, NULL);
7985 vkDestroyBufferView(m_device->device(), buff_view, NULL);
7986 vkFreeDescriptorSets(m_device->device(), ds_pool,
7987 VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
7988 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7989}
7990
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06007991TEST_F(VkLayerTest, DSAspectBitsErrors) {
7992 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
7993 // are set, but could expand this test to hit more cases.
7994 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
7995 "that do not have correct aspect bits sets.");
7996 VkResult err;
7997
7998 ASSERT_NO_FATAL_FAILURE(InitState());
7999 VkDescriptorPoolSize ds_type_count = {};
8000 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8001 ds_type_count.descriptorCount = 1;
8002
8003 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8004 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8005 ds_pool_ci.pNext = NULL;
8006 ds_pool_ci.maxSets = 5;
8007 ds_pool_ci.poolSizeCount = 1;
8008 ds_pool_ci.pPoolSizes = &ds_type_count;
8009
8010 VkDescriptorPool ds_pool;
8011 err =
8012 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
8013 ASSERT_VK_SUCCESS(err);
8014
8015 VkDescriptorSetLayoutBinding dsl_binding = {};
8016 dsl_binding.binding = 0;
8017 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8018 dsl_binding.descriptorCount = 1;
8019 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8020 dsl_binding.pImmutableSamplers = NULL;
8021
8022 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8023 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8024 ds_layout_ci.pNext = NULL;
8025 ds_layout_ci.bindingCount = 1;
8026 ds_layout_ci.pBindings = &dsl_binding;
8027 VkDescriptorSetLayout ds_layout;
8028 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8029 &ds_layout);
8030 ASSERT_VK_SUCCESS(err);
8031
8032 VkDescriptorSet descriptor_set = {};
8033 VkDescriptorSetAllocateInfo alloc_info = {};
8034 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8035 alloc_info.descriptorSetCount = 1;
8036 alloc_info.descriptorPool = ds_pool;
8037 alloc_info.pSetLayouts = &ds_layout;
8038 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8039 &descriptor_set);
8040 ASSERT_VK_SUCCESS(err);
8041
8042 // Create an image to be used for invalid updates
8043 VkImageCreateInfo image_ci = {};
8044 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8045 image_ci.imageType = VK_IMAGE_TYPE_2D;
8046 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8047 image_ci.extent.width = 64;
8048 image_ci.extent.height = 64;
8049 image_ci.extent.depth = 1;
8050 image_ci.mipLevels = 1;
8051 image_ci.arrayLayers = 1;
8052 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8053 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8054 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8055 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8056 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8057 VkImage image;
8058 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8059 ASSERT_VK_SUCCESS(err);
8060 // Bind memory to image
8061 VkMemoryRequirements mem_reqs;
8062 VkDeviceMemory image_mem;
8063 bool pass;
8064 VkMemoryAllocateInfo mem_alloc = {};
8065 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8066 mem_alloc.pNext = NULL;
8067 mem_alloc.allocationSize = 0;
8068 mem_alloc.memoryTypeIndex = 0;
8069 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8070 mem_alloc.allocationSize = mem_reqs.size;
8071 pass =
8072 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
8073 ASSERT_TRUE(pass);
8074 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8075 ASSERT_VK_SUCCESS(err);
8076 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8077 ASSERT_VK_SUCCESS(err);
8078 // Now create view for image
8079 VkImageViewCreateInfo image_view_ci = {};
8080 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8081 image_view_ci.image = image;
8082 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8083 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8084 image_view_ci.subresourceRange.layerCount = 1;
8085 image_view_ci.subresourceRange.baseArrayLayer = 0;
8086 image_view_ci.subresourceRange.levelCount = 1;
8087 // Setting both depth & stencil aspect bits is illegal for descriptor
8088 image_view_ci.subresourceRange.aspectMask =
8089 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
8090
8091 VkImageView image_view;
8092 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL,
8093 &image_view);
8094 ASSERT_VK_SUCCESS(err);
8095
8096 VkDescriptorImageInfo img_info = {};
8097 img_info.imageView = image_view;
8098 VkWriteDescriptorSet descriptor_write = {};
8099 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8100 descriptor_write.dstBinding = 0;
8101 descriptor_write.descriptorCount = 1;
8102 descriptor_write.pTexelBufferView = NULL;
8103 descriptor_write.pBufferInfo = NULL;
8104 descriptor_write.pImageInfo = &img_info;
8105 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8106 descriptor_write.dstSet = descriptor_set;
8107 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8108 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
8109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8110 error_msg);
8111
8112 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8113
8114 m_errorMonitor->VerifyFound();
8115 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8116 vkDestroyImage(m_device->device(), image, NULL);
8117 vkFreeMemory(m_device->device(), image_mem, NULL);
8118 vkDestroyImageView(m_device->device(), image_view, NULL);
8119 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8120 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8121}
8122
Karl Schultz6addd812016-02-02 17:17:23 -07008123TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008124 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008125 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008126
Karl Schultz6addd812016-02-02 17:17:23 -07008127 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008128 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8129 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8130 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008131
Tobin Ehlis3b780662015-05-28 12:11:26 -06008132 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008133 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008134 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008135 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8136 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008137
8138 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008139 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8140 ds_pool_ci.pNext = NULL;
8141 ds_pool_ci.maxSets = 1;
8142 ds_pool_ci.poolSizeCount = 1;
8143 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008144
Tobin Ehlis3b780662015-05-28 12:11:26 -06008145 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008146 err =
8147 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008148 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008149 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008150 dsl_binding.binding = 0;
8151 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8152 dsl_binding.descriptorCount = 1;
8153 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8154 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008155
Tony Barboureb254902015-07-15 12:50:33 -06008156 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008157 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8158 ds_layout_ci.pNext = NULL;
8159 ds_layout_ci.bindingCount = 1;
8160 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008161
Tobin Ehlis3b780662015-05-28 12:11:26 -06008162 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008163 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8164 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008165 ASSERT_VK_SUCCESS(err);
8166
8167 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008168 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008169 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008170 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008171 alloc_info.descriptorPool = ds_pool;
8172 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008173 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8174 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008175 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008176
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008177 VkSamplerCreateInfo sampler_ci = {};
8178 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8179 sampler_ci.pNext = NULL;
8180 sampler_ci.magFilter = VK_FILTER_NEAREST;
8181 sampler_ci.minFilter = VK_FILTER_NEAREST;
8182 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8183 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8184 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8185 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8186 sampler_ci.mipLodBias = 1.0;
8187 sampler_ci.anisotropyEnable = VK_FALSE;
8188 sampler_ci.maxAnisotropy = 1;
8189 sampler_ci.compareEnable = VK_FALSE;
8190 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8191 sampler_ci.minLod = 1.0;
8192 sampler_ci.maxLod = 1.0;
8193 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8194 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8195 VkSampler sampler;
8196 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8197 ASSERT_VK_SUCCESS(err);
8198
8199 VkDescriptorImageInfo info = {};
8200 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008201
8202 VkWriteDescriptorSet descriptor_write;
8203 memset(&descriptor_write, 0, sizeof(descriptor_write));
8204 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008205 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008206 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008207 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008208 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008209 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008210
8211 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8212
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008213 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008214
Chia-I Wuf7458c52015-10-26 21:10:41 +08008215 vkDestroySampler(m_device->device(), sampler, NULL);
8216 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8217 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008218}
8219
Karl Schultz6addd812016-02-02 17:17:23 -07008220TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008221 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008222 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008223
Karl Schultz6addd812016-02-02 17:17:23 -07008224 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008225 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8226 " binding #0 with 1 total descriptors but update of 1 descriptors "
8227 "starting at binding offset of 0 combined with update array element "
8228 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008229
Tobin Ehlis3b780662015-05-28 12:11:26 -06008230 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008231 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008232 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008233 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8234 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008235
8236 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008237 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8238 ds_pool_ci.pNext = NULL;
8239 ds_pool_ci.maxSets = 1;
8240 ds_pool_ci.poolSizeCount = 1;
8241 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008242
Tobin Ehlis3b780662015-05-28 12:11:26 -06008243 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008244 err =
8245 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008246 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008247
Tony Barboureb254902015-07-15 12:50:33 -06008248 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008249 dsl_binding.binding = 0;
8250 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8251 dsl_binding.descriptorCount = 1;
8252 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8253 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008254
8255 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008256 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8257 ds_layout_ci.pNext = NULL;
8258 ds_layout_ci.bindingCount = 1;
8259 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008260
Tobin Ehlis3b780662015-05-28 12:11:26 -06008261 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008262 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8263 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008264 ASSERT_VK_SUCCESS(err);
8265
8266 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008267 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008268 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008269 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008270 alloc_info.descriptorPool = ds_pool;
8271 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008272 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8273 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008274 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008275
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008276 // Correctly update descriptor to avoid "NOT_UPDATED" error
8277 VkDescriptorBufferInfo buff_info = {};
8278 buff_info.buffer =
8279 VkBuffer(0); // Don't care about buffer handle for this test
8280 buff_info.offset = 0;
8281 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008282
8283 VkWriteDescriptorSet descriptor_write;
8284 memset(&descriptor_write, 0, sizeof(descriptor_write));
8285 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008286 descriptor_write.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008287 descriptor_write.dstArrayElement =
8288 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008289 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008290 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8291 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008292
8293 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8294
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008295 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008296
Chia-I Wuf7458c52015-10-26 21:10:41 +08008297 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8298 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008299}
8300
Karl Schultz6addd812016-02-02 17:17:23 -07008301TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8302 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8303 // index 2
8304 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008305
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8307 " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008308
Tobin Ehlis3b780662015-05-28 12:11:26 -06008309 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008310 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008311 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008312 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8313 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008314
8315 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008316 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8317 ds_pool_ci.pNext = NULL;
8318 ds_pool_ci.maxSets = 1;
8319 ds_pool_ci.poolSizeCount = 1;
8320 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008321
Tobin Ehlis3b780662015-05-28 12:11:26 -06008322 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008323 err =
8324 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008325 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008326
Tony Barboureb254902015-07-15 12:50:33 -06008327 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008328 dsl_binding.binding = 0;
8329 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8330 dsl_binding.descriptorCount = 1;
8331 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8332 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008333
8334 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008335 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8336 ds_layout_ci.pNext = NULL;
8337 ds_layout_ci.bindingCount = 1;
8338 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008339 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008340 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8341 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008342 ASSERT_VK_SUCCESS(err);
8343
8344 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008345 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008346 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008347 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008348 alloc_info.descriptorPool = ds_pool;
8349 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008350 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8351 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008352 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008353
Tony Barboureb254902015-07-15 12:50:33 -06008354 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008355 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8356 sampler_ci.pNext = NULL;
8357 sampler_ci.magFilter = VK_FILTER_NEAREST;
8358 sampler_ci.minFilter = VK_FILTER_NEAREST;
8359 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8360 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8361 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8362 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8363 sampler_ci.mipLodBias = 1.0;
8364 sampler_ci.anisotropyEnable = VK_FALSE;
8365 sampler_ci.maxAnisotropy = 1;
8366 sampler_ci.compareEnable = VK_FALSE;
8367 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8368 sampler_ci.minLod = 1.0;
8369 sampler_ci.maxLod = 1.0;
8370 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8371 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06008372
Tobin Ehlis3b780662015-05-28 12:11:26 -06008373 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008374 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008375 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008376
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008377 VkDescriptorImageInfo info = {};
8378 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008379
8380 VkWriteDescriptorSet descriptor_write;
8381 memset(&descriptor_write, 0, sizeof(descriptor_write));
8382 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008383 descriptor_write.dstSet = descriptorSet;
8384 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008385 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008386 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008387 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008388 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008389
8390 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8391
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008392 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008393
Chia-I Wuf7458c52015-10-26 21:10:41 +08008394 vkDestroySampler(m_device->device(), sampler, NULL);
8395 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8396 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008397}
8398
Karl Schultz6addd812016-02-02 17:17:23 -07008399TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
8400 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
8401 // types
8402 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008403
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis660bcdc2016-05-17 10:39:46 -06008405 ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008406
Tobin Ehlis3b780662015-05-28 12:11:26 -06008407 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008408
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008409 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008410 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8411 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008412
8413 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008414 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8415 ds_pool_ci.pNext = NULL;
8416 ds_pool_ci.maxSets = 1;
8417 ds_pool_ci.poolSizeCount = 1;
8418 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008419
Tobin Ehlis3b780662015-05-28 12:11:26 -06008420 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008421 err =
8422 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008423 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008424 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008425 dsl_binding.binding = 0;
8426 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8427 dsl_binding.descriptorCount = 1;
8428 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8429 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008430
Tony Barboureb254902015-07-15 12:50:33 -06008431 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008432 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8433 ds_layout_ci.pNext = NULL;
8434 ds_layout_ci.bindingCount = 1;
8435 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008436
Tobin Ehlis3b780662015-05-28 12:11:26 -06008437 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008438 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8439 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008440 ASSERT_VK_SUCCESS(err);
8441
8442 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008443 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008444 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008445 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008446 alloc_info.descriptorPool = ds_pool;
8447 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008448 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8449 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008450 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008451
Tony Barboureb254902015-07-15 12:50:33 -06008452 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008453 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8454 sampler_ci.pNext = NULL;
8455 sampler_ci.magFilter = VK_FILTER_NEAREST;
8456 sampler_ci.minFilter = VK_FILTER_NEAREST;
8457 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8458 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8459 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8460 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8461 sampler_ci.mipLodBias = 1.0;
8462 sampler_ci.anisotropyEnable = VK_FALSE;
8463 sampler_ci.maxAnisotropy = 1;
8464 sampler_ci.compareEnable = VK_FALSE;
8465 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8466 sampler_ci.minLod = 1.0;
8467 sampler_ci.maxLod = 1.0;
8468 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8469 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008470 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008471 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008472 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008473
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008474 VkDescriptorImageInfo info = {};
8475 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008476
8477 VkWriteDescriptorSet descriptor_write;
8478 memset(&descriptor_write, 0, sizeof(descriptor_write));
Karl Schultz6addd812016-02-02 17:17:23 -07008479 descriptor_write.sType =
8480 (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008481 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008482 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008483 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008484 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008485 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008486
8487 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8488
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008489 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008490
Chia-I Wuf7458c52015-10-26 21:10:41 +08008491 vkDestroySampler(m_device->device(), sampler, NULL);
8492 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8493 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008494}
8495
Karl Schultz6addd812016-02-02 17:17:23 -07008496TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008497 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07008498 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008499
Karl Schultz6addd812016-02-02 17:17:23 -07008500 m_errorMonitor->SetDesiredFailureMsg(
8501 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008502 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008503
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008504 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008505 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
8506 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008507 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008508 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
8509 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008510
8511 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008512 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8513 ds_pool_ci.pNext = NULL;
8514 ds_pool_ci.maxSets = 1;
8515 ds_pool_ci.poolSizeCount = 1;
8516 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008517
8518 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008519 err =
8520 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008521 ASSERT_VK_SUCCESS(err);
8522
8523 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008524 dsl_binding.binding = 0;
8525 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8526 dsl_binding.descriptorCount = 1;
8527 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8528 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008529
8530 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008531 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8532 ds_layout_ci.pNext = NULL;
8533 ds_layout_ci.bindingCount = 1;
8534 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008535 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008536 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8537 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008538 ASSERT_VK_SUCCESS(err);
8539
8540 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008541 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008542 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008543 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008544 alloc_info.descriptorPool = ds_pool;
8545 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008546 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8547 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008548 ASSERT_VK_SUCCESS(err);
8549
Karl Schultz6addd812016-02-02 17:17:23 -07008550 VkSampler sampler =
8551 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008552
8553 VkDescriptorImageInfo descriptor_info;
8554 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8555 descriptor_info.sampler = sampler;
8556
8557 VkWriteDescriptorSet descriptor_write;
8558 memset(&descriptor_write, 0, sizeof(descriptor_write));
8559 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008560 descriptor_write.dstSet = descriptorSet;
8561 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008562 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008563 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8564 descriptor_write.pImageInfo = &descriptor_info;
8565
8566 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8567
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008568 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008569
Chia-I Wuf7458c52015-10-26 21:10:41 +08008570 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8571 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008572}
8573
Karl Schultz6addd812016-02-02 17:17:23 -07008574TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
8575 // Create a single combined Image/Sampler descriptor and send it an invalid
8576 // imageView
8577 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008578
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8580 "Attempted write update to combined "
8581 "image sampler descriptor failed due "
Tobin Ehlis63c4b8a2016-05-09 10:29:34 -06008582 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008583
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008584 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008585 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008586 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8587 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008588
8589 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008590 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8591 ds_pool_ci.pNext = NULL;
8592 ds_pool_ci.maxSets = 1;
8593 ds_pool_ci.poolSizeCount = 1;
8594 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008595
8596 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008597 err =
8598 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008599 ASSERT_VK_SUCCESS(err);
8600
8601 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008602 dsl_binding.binding = 0;
8603 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8604 dsl_binding.descriptorCount = 1;
8605 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8606 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008607
8608 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008609 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8610 ds_layout_ci.pNext = NULL;
8611 ds_layout_ci.bindingCount = 1;
8612 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008613 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008614 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8615 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008616 ASSERT_VK_SUCCESS(err);
8617
8618 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008619 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008620 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008621 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008622 alloc_info.descriptorPool = ds_pool;
8623 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008624 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8625 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008626 ASSERT_VK_SUCCESS(err);
8627
8628 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008629 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8630 sampler_ci.pNext = NULL;
8631 sampler_ci.magFilter = VK_FILTER_NEAREST;
8632 sampler_ci.minFilter = VK_FILTER_NEAREST;
8633 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8634 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8635 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8636 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8637 sampler_ci.mipLodBias = 1.0;
8638 sampler_ci.anisotropyEnable = VK_FALSE;
8639 sampler_ci.maxAnisotropy = 1;
8640 sampler_ci.compareEnable = VK_FALSE;
8641 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8642 sampler_ci.minLod = 1.0;
8643 sampler_ci.maxLod = 1.0;
8644 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8645 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008646
8647 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008648 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008649 ASSERT_VK_SUCCESS(err);
8650
Karl Schultz6addd812016-02-02 17:17:23 -07008651 VkImageView view =
8652 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008653
8654 VkDescriptorImageInfo descriptor_info;
8655 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8656 descriptor_info.sampler = sampler;
8657 descriptor_info.imageView = view;
8658
8659 VkWriteDescriptorSet descriptor_write;
8660 memset(&descriptor_write, 0, sizeof(descriptor_write));
8661 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008662 descriptor_write.dstSet = descriptorSet;
8663 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008664 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008665 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8666 descriptor_write.pImageInfo = &descriptor_info;
8667
8668 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8669
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008670 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008671
Chia-I Wuf7458c52015-10-26 21:10:41 +08008672 vkDestroySampler(m_device->device(), sampler, NULL);
8673 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8674 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008675}
8676
Karl Schultz6addd812016-02-02 17:17:23 -07008677TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
8678 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
8679 // into the other
8680 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008681
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8683 " binding #1 with type "
8684 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
8685 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008686
Tobin Ehlis04356f92015-10-27 16:35:27 -06008687 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008688 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008689 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008690 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8691 ds_type_count[0].descriptorCount = 1;
8692 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8693 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008694
8695 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008696 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8697 ds_pool_ci.pNext = NULL;
8698 ds_pool_ci.maxSets = 1;
8699 ds_pool_ci.poolSizeCount = 2;
8700 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008701
8702 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008703 err =
8704 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008705 ASSERT_VK_SUCCESS(err);
8706 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008707 dsl_binding[0].binding = 0;
8708 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8709 dsl_binding[0].descriptorCount = 1;
8710 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8711 dsl_binding[0].pImmutableSamplers = NULL;
8712 dsl_binding[1].binding = 1;
8713 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8714 dsl_binding[1].descriptorCount = 1;
8715 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8716 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008717
8718 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008719 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8720 ds_layout_ci.pNext = NULL;
8721 ds_layout_ci.bindingCount = 2;
8722 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008723
8724 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008725 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8726 &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008727 ASSERT_VK_SUCCESS(err);
8728
8729 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008730 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008731 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008732 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008733 alloc_info.descriptorPool = ds_pool;
8734 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008735 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8736 &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008737 ASSERT_VK_SUCCESS(err);
8738
8739 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008740 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8741 sampler_ci.pNext = NULL;
8742 sampler_ci.magFilter = VK_FILTER_NEAREST;
8743 sampler_ci.minFilter = VK_FILTER_NEAREST;
8744 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8745 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8746 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8747 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8748 sampler_ci.mipLodBias = 1.0;
8749 sampler_ci.anisotropyEnable = VK_FALSE;
8750 sampler_ci.maxAnisotropy = 1;
8751 sampler_ci.compareEnable = VK_FALSE;
8752 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8753 sampler_ci.minLod = 1.0;
8754 sampler_ci.maxLod = 1.0;
8755 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8756 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008757
8758 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008759 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008760 ASSERT_VK_SUCCESS(err);
8761
8762 VkDescriptorImageInfo info = {};
8763 info.sampler = sampler;
8764
8765 VkWriteDescriptorSet descriptor_write;
8766 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
8767 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008768 descriptor_write.dstSet = descriptorSet;
8769 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08008770 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008771 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8772 descriptor_write.pImageInfo = &info;
8773 // This write update should succeed
8774 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8775 // Now perform a copy update that fails due to type mismatch
8776 VkCopyDescriptorSet copy_ds_update;
8777 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8778 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8779 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06008780 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008781 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008782 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08008783 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06008784 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8785
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008786 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06008787 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07008788 m_errorMonitor->SetDesiredFailureMsg(
8789 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008790 " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -06008791 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8792 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8793 copy_ds_update.srcSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008794 copy_ds_update.srcBinding =
8795 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008796 copy_ds_update.dstSet = descriptorSet;
8797 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06008798 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06008799 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8800
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008801 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008802
Tobin Ehlis04356f92015-10-27 16:35:27 -06008803 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07008804 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008805 VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
8806 "update array offset of 0 and update of "
8807 "5 descriptors oversteps total number "
8808 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008809
Tobin Ehlis04356f92015-10-27 16:35:27 -06008810 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8811 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8812 copy_ds_update.srcSet = descriptorSet;
8813 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008814 copy_ds_update.dstSet = descriptorSet;
8815 copy_ds_update.dstBinding = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008816 copy_ds_update.descriptorCount =
8817 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06008818 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8819
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008820 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06008821
Chia-I Wuf7458c52015-10-26 21:10:41 +08008822 vkDestroySampler(m_device->device(), sampler, NULL);
8823 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8824 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008825}
8826
Karl Schultz6addd812016-02-02 17:17:23 -07008827TEST_F(VkLayerTest, NumSamplesMismatch) {
8828 // Create CommandBuffer where MSAA samples doesn't match RenderPass
8829 // sampleCount
8830 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008831
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008833 "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008834
Tobin Ehlis3b780662015-05-28 12:11:26 -06008835 ASSERT_NO_FATAL_FAILURE(InitState());
8836 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008837 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06008838 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008839 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008840
8841 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008842 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8843 ds_pool_ci.pNext = NULL;
8844 ds_pool_ci.maxSets = 1;
8845 ds_pool_ci.poolSizeCount = 1;
8846 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008847
Tobin Ehlis3b780662015-05-28 12:11:26 -06008848 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008849 err =
8850 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008851 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008852
Tony Barboureb254902015-07-15 12:50:33 -06008853 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08008854 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06008855 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08008856 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008857 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8858 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008859
Tony Barboureb254902015-07-15 12:50:33 -06008860 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8861 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8862 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008863 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008864 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008865
Tobin Ehlis3b780662015-05-28 12:11:26 -06008866 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008867 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8868 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008869 ASSERT_VK_SUCCESS(err);
8870
8871 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008872 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008873 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008874 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008875 alloc_info.descriptorPool = ds_pool;
8876 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008877 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8878 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008879 ASSERT_VK_SUCCESS(err);
8880
Tony Barboureb254902015-07-15 12:50:33 -06008881 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008882 pipe_ms_state_ci.sType =
8883 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8884 pipe_ms_state_ci.pNext = NULL;
8885 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8886 pipe_ms_state_ci.sampleShadingEnable = 0;
8887 pipe_ms_state_ci.minSampleShading = 1.0;
8888 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008889
Tony Barboureb254902015-07-15 12:50:33 -06008890 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008891 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8892 pipeline_layout_ci.pNext = NULL;
8893 pipeline_layout_ci.setLayoutCount = 1;
8894 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008895
8896 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008897 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8898 &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008899 ASSERT_VK_SUCCESS(err);
8900
Karl Schultz6addd812016-02-02 17:17:23 -07008901 VkShaderObj vs(m_device, bindStateVertShaderText,
8902 VK_SHADER_STAGE_VERTEX_BIT, this);
8903 VkShaderObj fs(m_device, bindStateFragShaderText,
8904 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06008905 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07008906 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008907 VkPipelineObj pipe(m_device);
8908 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008909 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06008910 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008911 pipe.SetMSAA(&pipe_ms_state_ci);
8912 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06008913
Tony Barbourfe3351b2015-07-28 10:17:20 -06008914 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008915 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8916 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06008917
Mark Young29927482016-05-04 14:38:51 -06008918 // Render triangle (the error should trigger on the attempt to draw).
8919 Draw(3, 1, 0, 0);
8920
8921 // Finalize recording of the command buffer
8922 EndCommandBuffer();
8923
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008924 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008925
Chia-I Wuf7458c52015-10-26 21:10:41 +08008926 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8927 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8928 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008929}
Mark Young29927482016-05-04 14:38:51 -06008930
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06008931TEST_F(VkLayerTest, RenderPassIncompatible) {
8932 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
8933 "Initial case is drawing with an active renderpass that's "
8934 "not compatible with the bound PSO's creation renderpass");
8935 VkResult err;
8936
8937 ASSERT_NO_FATAL_FAILURE(InitState());
8938 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8939
8940 VkDescriptorSetLayoutBinding dsl_binding = {};
8941 dsl_binding.binding = 0;
8942 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8943 dsl_binding.descriptorCount = 1;
8944 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8945 dsl_binding.pImmutableSamplers = NULL;
8946
8947 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8948 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8949 ds_layout_ci.pNext = NULL;
8950 ds_layout_ci.bindingCount = 1;
8951 ds_layout_ci.pBindings = &dsl_binding;
8952
8953 VkDescriptorSetLayout ds_layout;
8954 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8955 &ds_layout);
8956 ASSERT_VK_SUCCESS(err);
8957
8958 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8959 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8960 pipeline_layout_ci.pNext = NULL;
8961 pipeline_layout_ci.setLayoutCount = 1;
8962 pipeline_layout_ci.pSetLayouts = &ds_layout;
8963
8964 VkPipelineLayout pipeline_layout;
8965 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8966 &pipeline_layout);
8967 ASSERT_VK_SUCCESS(err);
8968
8969 VkShaderObj vs(m_device, bindStateVertShaderText,
8970 VK_SHADER_STAGE_VERTEX_BIT, this);
8971 VkShaderObj fs(m_device, bindStateFragShaderText,
8972 VK_SHADER_STAGE_FRAGMENT_BIT,
8973 this); // We shouldn't need a fragment shader
8974 // but add it to be able to run on more devices
8975 // Create a renderpass that will be incompatible with default renderpass
8976 VkAttachmentReference attach = {};
8977 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8978 VkAttachmentReference color_att = {};
8979 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8980 VkSubpassDescription subpass = {};
8981 subpass.inputAttachmentCount = 1;
8982 subpass.pInputAttachments = &attach;
8983 subpass.colorAttachmentCount = 1;
8984 subpass.pColorAttachments = &color_att;
8985 VkRenderPassCreateInfo rpci = {};
8986 rpci.subpassCount = 1;
8987 rpci.pSubpasses = &subpass;
8988 rpci.attachmentCount = 1;
8989 VkAttachmentDescription attach_desc = {};
8990 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06008991 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
8992 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06008993 rpci.pAttachments = &attach_desc;
8994 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8995 VkRenderPass rp;
8996 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8997 VkPipelineObj pipe(m_device);
8998 pipe.AddShader(&vs);
8999 pipe.AddShader(&fs);
9000 pipe.AddColorAttachment();
9001 VkViewport view_port = {};
9002 m_viewports.push_back(view_port);
9003 pipe.SetViewport(m_viewports);
9004 VkRect2D rect = {};
9005 m_scissors.push_back(rect);
9006 pipe.SetScissor(m_scissors);
9007 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9008
9009 VkCommandBufferInheritanceInfo cbii = {};
9010 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9011 cbii.renderPass = rp;
9012 cbii.subpass = 0;
9013 VkCommandBufferBeginInfo cbbi = {};
9014 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9015 cbbi.pInheritanceInfo = &cbii;
9016 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9017 VkRenderPassBeginInfo rpbi = {};
9018 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9019 rpbi.framebuffer = m_framebuffer;
9020 rpbi.renderPass = rp;
9021 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi,
9022 VK_SUBPASS_CONTENTS_INLINE);
9023 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9024 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
9025
9026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9027 " is incompatible w/ gfx pipeline ");
9028 // Render triangle (the error should trigger on the attempt to draw).
9029 Draw(3, 1, 0, 0);
9030
9031 // Finalize recording of the command buffer
9032 EndCommandBuffer();
9033
9034 m_errorMonitor->VerifyFound();
9035
9036 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9037 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9038 vkDestroyRenderPass(m_device->device(), rp, NULL);
9039}
9040
Mark Youngc89c6312016-03-31 16:03:20 -06009041TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9042 // Create Pipeline where the number of blend attachments doesn't match the
9043 // number of color attachments. In this case, we don't add any color
9044 // blend attachments even though we have a color attachment.
9045 VkResult err;
9046
9047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young29927482016-05-04 14:38:51 -06009048 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009049
9050 ASSERT_NO_FATAL_FAILURE(InitState());
9051 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9052 VkDescriptorPoolSize ds_type_count = {};
9053 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9054 ds_type_count.descriptorCount = 1;
9055
9056 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9057 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9058 ds_pool_ci.pNext = NULL;
9059 ds_pool_ci.maxSets = 1;
9060 ds_pool_ci.poolSizeCount = 1;
9061 ds_pool_ci.pPoolSizes = &ds_type_count;
9062
9063 VkDescriptorPool ds_pool;
9064 err =
9065 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9066 ASSERT_VK_SUCCESS(err);
9067
9068 VkDescriptorSetLayoutBinding dsl_binding = {};
9069 dsl_binding.binding = 0;
9070 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9071 dsl_binding.descriptorCount = 1;
9072 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9073 dsl_binding.pImmutableSamplers = NULL;
9074
9075 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9076 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9077 ds_layout_ci.pNext = NULL;
9078 ds_layout_ci.bindingCount = 1;
9079 ds_layout_ci.pBindings = &dsl_binding;
9080
9081 VkDescriptorSetLayout ds_layout;
9082 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9083 &ds_layout);
9084 ASSERT_VK_SUCCESS(err);
9085
9086 VkDescriptorSet descriptorSet;
9087 VkDescriptorSetAllocateInfo alloc_info = {};
9088 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9089 alloc_info.descriptorSetCount = 1;
9090 alloc_info.descriptorPool = ds_pool;
9091 alloc_info.pSetLayouts = &ds_layout;
9092 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9093 &descriptorSet);
9094 ASSERT_VK_SUCCESS(err);
9095
9096 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
9097 pipe_ms_state_ci.sType =
9098 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9099 pipe_ms_state_ci.pNext = NULL;
9100 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9101 pipe_ms_state_ci.sampleShadingEnable = 0;
9102 pipe_ms_state_ci.minSampleShading = 1.0;
9103 pipe_ms_state_ci.pSampleMask = NULL;
9104
9105 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9106 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9107 pipeline_layout_ci.pNext = NULL;
9108 pipeline_layout_ci.setLayoutCount = 1;
9109 pipeline_layout_ci.pSetLayouts = &ds_layout;
9110
9111 VkPipelineLayout pipeline_layout;
9112 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9113 &pipeline_layout);
9114 ASSERT_VK_SUCCESS(err);
9115
9116 VkShaderObj vs(m_device, bindStateVertShaderText,
9117 VK_SHADER_STAGE_VERTEX_BIT, this);
9118 VkShaderObj fs(m_device, bindStateFragShaderText,
9119 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06009120 this); // We shouldn't need a fragment shader
Mark Youngc89c6312016-03-31 16:03:20 -06009121 // but add it to be able to run on more devices
9122 VkPipelineObj pipe(m_device);
9123 pipe.AddShader(&vs);
9124 pipe.AddShader(&fs);
9125 pipe.SetMSAA(&pipe_ms_state_ci);
9126 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9127
9128 BeginCommandBuffer();
9129 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9130 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
9131
Mark Young29927482016-05-04 14:38:51 -06009132 // Render triangle (the error should trigger on the attempt to draw).
9133 Draw(3, 1, 0, 0);
9134
9135 // Finalize recording of the command buffer
9136 EndCommandBuffer();
9137
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009138 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009139
9140 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9141 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9142 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9143}
Mark Young29927482016-05-04 14:38:51 -06009144
Mark Muellerd4914412016-06-13 17:52:06 -06009145TEST_F(VkLayerTest, MissingClearAttachment) {
9146 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9147 "structure passed to vkCmdClearAttachments");
9148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9149 "vkCmdClearAttachments() attachment index 1 not found in attachment "
9150 "reference array of active subpass 0");
9151
9152 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9153 m_errorMonitor->VerifyFound();
9154}
9155
Karl Schultz6addd812016-02-02 17:17:23 -07009156TEST_F(VkLayerTest, ClearCmdNoDraw) {
9157 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9158 // to issuing a Draw
9159 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009160
Karl Schultz6addd812016-02-02 17:17:23 -07009161 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbour7e56d302016-03-02 15:12:01 -07009162 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009163 "vkCmdClearAttachments() issued on CB object ");
9164
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009165 ASSERT_NO_FATAL_FAILURE(InitState());
9166 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009167
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009168 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009169 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9170 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009171
9172 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009173 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9174 ds_pool_ci.pNext = NULL;
9175 ds_pool_ci.maxSets = 1;
9176 ds_pool_ci.poolSizeCount = 1;
9177 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009178
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009179 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009180 err =
9181 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009182 ASSERT_VK_SUCCESS(err);
9183
Tony Barboureb254902015-07-15 12:50:33 -06009184 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009185 dsl_binding.binding = 0;
9186 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9187 dsl_binding.descriptorCount = 1;
9188 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9189 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009190
Tony Barboureb254902015-07-15 12:50:33 -06009191 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009192 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9193 ds_layout_ci.pNext = NULL;
9194 ds_layout_ci.bindingCount = 1;
9195 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009196
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009197 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009198 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9199 &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009200 ASSERT_VK_SUCCESS(err);
9201
9202 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009203 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009204 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009205 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009206 alloc_info.descriptorPool = ds_pool;
9207 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009208 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9209 &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009210 ASSERT_VK_SUCCESS(err);
9211
Tony Barboureb254902015-07-15 12:50:33 -06009212 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009213 pipe_ms_state_ci.sType =
9214 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9215 pipe_ms_state_ci.pNext = NULL;
9216 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9217 pipe_ms_state_ci.sampleShadingEnable = 0;
9218 pipe_ms_state_ci.minSampleShading = 1.0;
9219 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009220
Tony Barboureb254902015-07-15 12:50:33 -06009221 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009222 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9223 pipeline_layout_ci.pNext = NULL;
9224 pipeline_layout_ci.setLayoutCount = 1;
9225 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009226
9227 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009228 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9229 &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009230 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009231
Karl Schultz6addd812016-02-02 17:17:23 -07009232 VkShaderObj vs(m_device, bindStateVertShaderText,
9233 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009234 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009235 // on more devices
9236 VkShaderObj fs(m_device, bindStateFragShaderText,
9237 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009238
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009239 VkPipelineObj pipe(m_device);
9240 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009241 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009242 pipe.SetMSAA(&pipe_ms_state_ci);
9243 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009244
9245 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009246
Karl Schultz6addd812016-02-02 17:17:23 -07009247 // Main thing we care about for this test is that the VkImage obj we're
9248 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009249 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009250 VkClearAttachment color_attachment;
9251 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9252 color_attachment.clearValue.color.float32[0] = 1.0;
9253 color_attachment.clearValue.color.float32[1] = 1.0;
9254 color_attachment.clearValue.color.float32[2] = 1.0;
9255 color_attachment.clearValue.color.float32[3] = 1.0;
9256 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009257 VkClearRect clear_rect = {
9258 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009259
Karl Schultz6addd812016-02-02 17:17:23 -07009260 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
9261 &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009262
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009263 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009264
Chia-I Wuf7458c52015-10-26 21:10:41 +08009265 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9266 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9267 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009268}
9269
Karl Schultz6addd812016-02-02 17:17:23 -07009270TEST_F(VkLayerTest, VtxBufferBadIndex) {
9271 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009272
Karl Schultz6addd812016-02-02 17:17:23 -07009273 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009274 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07009275 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009276
Tobin Ehlis502480b2015-06-24 15:53:07 -06009277 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009278 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009279 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009280
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009281 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009282 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9283 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009284
9285 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009286 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9287 ds_pool_ci.pNext = NULL;
9288 ds_pool_ci.maxSets = 1;
9289 ds_pool_ci.poolSizeCount = 1;
9290 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009291
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009292 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009293 err =
9294 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009295 ASSERT_VK_SUCCESS(err);
9296
Tony Barboureb254902015-07-15 12:50:33 -06009297 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009298 dsl_binding.binding = 0;
9299 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9300 dsl_binding.descriptorCount = 1;
9301 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9302 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009303
Tony Barboureb254902015-07-15 12:50:33 -06009304 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009305 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9306 ds_layout_ci.pNext = NULL;
9307 ds_layout_ci.bindingCount = 1;
9308 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009309
Tobin Ehlis502480b2015-06-24 15:53:07 -06009310 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009311 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9312 &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009313 ASSERT_VK_SUCCESS(err);
9314
9315 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009316 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009317 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009318 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009319 alloc_info.descriptorPool = ds_pool;
9320 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009321 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9322 &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009323 ASSERT_VK_SUCCESS(err);
9324
Tony Barboureb254902015-07-15 12:50:33 -06009325 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009326 pipe_ms_state_ci.sType =
9327 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9328 pipe_ms_state_ci.pNext = NULL;
9329 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9330 pipe_ms_state_ci.sampleShadingEnable = 0;
9331 pipe_ms_state_ci.minSampleShading = 1.0;
9332 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009333
Tony Barboureb254902015-07-15 12:50:33 -06009334 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009335 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9336 pipeline_layout_ci.pNext = NULL;
9337 pipeline_layout_ci.setLayoutCount = 1;
9338 pipeline_layout_ci.pSetLayouts = &ds_layout;
9339 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009340
Karl Schultz6addd812016-02-02 17:17:23 -07009341 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9342 &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009343 ASSERT_VK_SUCCESS(err);
9344
Karl Schultz6addd812016-02-02 17:17:23 -07009345 VkShaderObj vs(m_device, bindStateVertShaderText,
9346 VK_SHADER_STAGE_VERTEX_BIT, this);
9347 VkShaderObj fs(m_device, bindStateFragShaderText,
9348 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06009349 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07009350 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009351 VkPipelineObj pipe(m_device);
9352 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009353 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009354 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009355 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009356 pipe.SetViewport(m_viewports);
9357 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009358 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009359
9360 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009361 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9362 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009363 // Don't care about actual data, just need to get to draw to flag error
9364 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz6addd812016-02-02 17:17:23 -07009365 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
9366 (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009367 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009368 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009369
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009370 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009371
Chia-I Wuf7458c52015-10-26 21:10:41 +08009372 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9373 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9374 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009375}
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009376// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
9377TEST_F(VkLayerTest, InvalidImageLayout) {
9378 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
9379 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
9380 "images in the wrong layout when they're copied or transitioned.");
9381 // 3 in ValidateCmdBufImageLayouts
9382 // * -1 Attempt to submit cmd buf w/ deleted image
9383 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
9384 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
9385 m_errorMonitor->SetDesiredFailureMsg(
9386 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9387 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
9388
9389 ASSERT_NO_FATAL_FAILURE(InitState());
9390 // Create src & dst images to use for copy operations
9391 VkImage src_image;
9392 VkImage dst_image;
9393
9394 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9395 const int32_t tex_width = 32;
9396 const int32_t tex_height = 32;
9397
9398 VkImageCreateInfo image_create_info = {};
9399 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9400 image_create_info.pNext = NULL;
9401 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9402 image_create_info.format = tex_format;
9403 image_create_info.extent.width = tex_width;
9404 image_create_info.extent.height = tex_height;
9405 image_create_info.extent.depth = 1;
9406 image_create_info.mipLevels = 1;
9407 image_create_info.arrayLayers = 4;
9408 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9409 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9410 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
9411 image_create_info.flags = 0;
9412
9413 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
9414 ASSERT_VK_SUCCESS(err);
9415 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
9416 ASSERT_VK_SUCCESS(err);
9417
9418 BeginCommandBuffer();
9419 VkImageCopy copyRegion;
9420 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9421 copyRegion.srcSubresource.mipLevel = 0;
9422 copyRegion.srcSubresource.baseArrayLayer = 0;
9423 copyRegion.srcSubresource.layerCount = 1;
9424 copyRegion.srcOffset.x = 0;
9425 copyRegion.srcOffset.y = 0;
9426 copyRegion.srcOffset.z = 0;
9427 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9428 copyRegion.dstSubresource.mipLevel = 0;
9429 copyRegion.dstSubresource.baseArrayLayer = 0;
9430 copyRegion.dstSubresource.layerCount = 1;
9431 copyRegion.dstOffset.x = 0;
9432 copyRegion.dstOffset.y = 0;
9433 copyRegion.dstOffset.z = 0;
9434 copyRegion.extent.width = 1;
9435 copyRegion.extent.height = 1;
9436 copyRegion.extent.depth = 1;
9437 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9438 m_errorMonitor->VerifyFound();
9439 // Now cause error due to src image layout changing
9440 m_errorMonitor->SetDesiredFailureMsg(
9441 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9442 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9443 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9444 m_errorMonitor->VerifyFound();
9445 // Final src error is due to bad layout type
9446 m_errorMonitor->SetDesiredFailureMsg(
9447 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9448 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
9449 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9450 m_errorMonitor->VerifyFound();
9451 // Now verify same checks for dst
9452 m_errorMonitor->SetDesiredFailureMsg(
9453 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9454 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
9455 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9456 m_errorMonitor->VerifyFound();
9457 // Now cause error due to src image layout changing
9458 m_errorMonitor->SetDesiredFailureMsg(
9459 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9460 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9461 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9462 m_errorMonitor->VerifyFound();
9463 m_errorMonitor->SetDesiredFailureMsg(
9464 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9465 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
9466 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9467 m_errorMonitor->VerifyFound();
9468 // Now cause error due to bad image layout transition in PipelineBarrier
9469 VkImageMemoryBarrier image_barrier[1] = {};
9470 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9471 image_barrier[0].image = src_image;
9472 image_barrier[0].subresourceRange.layerCount = 2;
9473 image_barrier[0].subresourceRange.levelCount = 2;
9474 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9475 m_errorMonitor->SetDesiredFailureMsg(
9476 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9477 "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL.");
9478 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier);
9479 m_errorMonitor->VerifyFound();
9480
9481 // Finally some layout errors at RenderPass create time
9482 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
9483 VkAttachmentReference attach = {};
9484 // perf warning for GENERAL layout w/ non-DS input attachment
9485 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9486 VkSubpassDescription subpass = {};
9487 subpass.inputAttachmentCount = 1;
9488 subpass.pInputAttachments = &attach;
9489 VkRenderPassCreateInfo rpci = {};
9490 rpci.subpassCount = 1;
9491 rpci.pSubpasses = &subpass;
9492 rpci.attachmentCount = 1;
9493 VkAttachmentDescription attach_desc = {};
9494 attach_desc.format = VK_FORMAT_UNDEFINED;
9495 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -06009496 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009497 VkRenderPass rp;
9498 m_errorMonitor->SetDesiredFailureMsg(
9499 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9500 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
9501 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9502 m_errorMonitor->VerifyFound();
9503 // error w/ non-general layout
9504 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9505
9506 m_errorMonitor->SetDesiredFailureMsg(
9507 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9508 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
9509 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9510 m_errorMonitor->VerifyFound();
9511 subpass.inputAttachmentCount = 0;
9512 subpass.colorAttachmentCount = 1;
9513 subpass.pColorAttachments = &attach;
9514 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9515 // perf warning for GENERAL layout on color attachment
9516 m_errorMonitor->SetDesiredFailureMsg(
9517 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9518 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
9519 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9520 m_errorMonitor->VerifyFound();
9521 // error w/ non-color opt or GENERAL layout for color attachment
9522 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9523 m_errorMonitor->SetDesiredFailureMsg(
9524 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9525 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
9526 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9527 m_errorMonitor->VerifyFound();
9528 subpass.colorAttachmentCount = 0;
9529 subpass.pDepthStencilAttachment = &attach;
9530 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9531 // perf warning for GENERAL layout on DS attachment
9532 m_errorMonitor->SetDesiredFailureMsg(
9533 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9534 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
9535 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9536 m_errorMonitor->VerifyFound();
9537 // error w/ non-ds opt or GENERAL layout for color attachment
9538 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9539 m_errorMonitor->SetDesiredFailureMsg(
9540 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9541 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.");
9542 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9543 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -06009544 // For this error we need a valid renderpass so create default one
9545 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9546 attach.attachment = 0;
9547 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
9548 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
9549 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
9550 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
9551 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
9552 // Can't do a CLEAR load on READ_ONLY initialLayout
9553 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9554 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9555 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9557 " with invalid first layout "
9558 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
9559 "ONLY_OPTIMAL");
9560 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9561 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009562
9563 vkDestroyImage(m_device->device(), src_image, NULL);
9564 vkDestroyImage(m_device->device(), dst_image, NULL);
9565}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009566#endif // DRAW_STATE_TESTS
9567
Tobin Ehlis0788f522015-05-26 16:11:58 -06009568#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06009569#if GTEST_IS_THREADSAFE
9570struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009571 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009572 VkEvent event;
9573 bool bailout;
9574};
9575
Karl Schultz6addd812016-02-02 17:17:23 -07009576extern "C" void *AddToCommandBuffer(void *arg) {
9577 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009578
Karl Schultz6addd812016-02-02 17:17:23 -07009579 for (int i = 0; i < 10000; i++) {
9580 vkCmdSetEvent(data->commandBuffer, data->event,
9581 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009582 if (data->bailout) {
9583 break;
9584 }
9585 }
9586 return NULL;
9587}
9588
Karl Schultz6addd812016-02-02 17:17:23 -07009589TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009590 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009591
Karl Schultz6addd812016-02-02 17:17:23 -07009592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9593 "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009594
Mike Stroyanaccf7692015-05-12 16:00:45 -06009595 ASSERT_NO_FATAL_FAILURE(InitState());
9596 ASSERT_NO_FATAL_FAILURE(InitViewport());
9597 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9598
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009599 // Calls AllocateCommandBuffers
9600 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009601
9602 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009603 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009604
9605 VkEventCreateInfo event_info;
9606 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009607 VkResult err;
9608
9609 memset(&event_info, 0, sizeof(event_info));
9610 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9611
Chia-I Wuf7458c52015-10-26 21:10:41 +08009612 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009613 ASSERT_VK_SUCCESS(err);
9614
Mike Stroyanaccf7692015-05-12 16:00:45 -06009615 err = vkResetEvent(device(), event);
9616 ASSERT_VK_SUCCESS(err);
9617
9618 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009619 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009620 data.event = event;
9621 data.bailout = false;
9622 m_errorMonitor->SetBailout(&data.bailout);
9623 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009624 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009625 // Add many entries to command buffer from this thread at the same time.
9626 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009627
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009628 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009629 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009630
Mike Stroyan10b8cb72016-01-22 15:22:03 -07009631 m_errorMonitor->SetBailout(NULL);
9632
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009633 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009634
Chia-I Wuf7458c52015-10-26 21:10:41 +08009635 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009636}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009637#endif // GTEST_IS_THREADSAFE
9638#endif // THREADING_TESTS
9639
Chris Forbes9f7ff632015-05-25 11:13:08 +12009640#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07009641TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009643 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009644
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009645 ASSERT_NO_FATAL_FAILURE(InitState());
9646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9647
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009648 VkShaderModule module;
9649 VkShaderModuleCreateInfo moduleCreateInfo;
9650 struct icd_spv_header spv;
9651
9652 spv.magic = ICD_SPV_MAGIC;
9653 spv.version = ICD_SPV_VERSION;
9654 spv.gen_magic = 0;
9655
9656 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9657 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009658 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009659 moduleCreateInfo.codeSize = 4;
9660 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009661 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009662
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009663 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009664}
9665
Karl Schultz6addd812016-02-02 17:17:23 -07009666TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009668 "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009669
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009670 ASSERT_NO_FATAL_FAILURE(InitState());
9671 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9672
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009673 VkShaderModule module;
9674 VkShaderModuleCreateInfo moduleCreateInfo;
9675 struct icd_spv_header spv;
9676
9677 spv.magic = ~ICD_SPV_MAGIC;
9678 spv.version = ICD_SPV_VERSION;
9679 spv.gen_magic = 0;
9680
9681 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9682 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009683 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009684 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9685 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009686 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009687
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009688 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009689}
9690
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009691#if 0
9692// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -07009693TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009695 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009696
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009697 ASSERT_NO_FATAL_FAILURE(InitState());
9698 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9699
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009700 VkShaderModule module;
9701 VkShaderModuleCreateInfo moduleCreateInfo;
9702 struct icd_spv_header spv;
9703
9704 spv.magic = ICD_SPV_MAGIC;
9705 spv.version = ~ICD_SPV_VERSION;
9706 spv.gen_magic = 0;
9707
9708 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9709 moduleCreateInfo.pNext = NULL;
9710
Karl Schultz6addd812016-02-02 17:17:23 -07009711 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009712 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9713 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009714 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009715
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009716 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009717}
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009718#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009719
Karl Schultz6addd812016-02-02 17:17:23 -07009720TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009722 "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009723
Chris Forbes9f7ff632015-05-25 11:13:08 +12009724 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009725 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009726
9727 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009728 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009729 "\n"
9730 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009731 "out gl_PerVertex {\n"
9732 " vec4 gl_Position;\n"
9733 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009734 "void main(){\n"
9735 " gl_Position = vec4(1);\n"
9736 " x = 0;\n"
9737 "}\n";
9738 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009739 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009740 "\n"
9741 "layout(location=0) out vec4 color;\n"
9742 "void main(){\n"
9743 " color = vec4(1);\n"
9744 "}\n";
9745
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009746 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9747 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009748
9749 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009750 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009751 pipe.AddShader(&vs);
9752 pipe.AddShader(&fs);
9753
Chris Forbes9f7ff632015-05-25 11:13:08 +12009754 VkDescriptorSetObj descriptorSet(m_device);
9755 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009756 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009757
Tony Barbour5781e8f2015-08-04 16:23:11 -06009758 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009759
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009760 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009761}
Chris Forbes9f7ff632015-05-25 11:13:08 +12009762
Karl Schultz6addd812016-02-02 17:17:23 -07009763TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009765 "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009766
Chris Forbes59cb88d2015-05-25 11:13:13 +12009767 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009769
9770 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009771 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009772 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009773 "out gl_PerVertex {\n"
9774 " vec4 gl_Position;\n"
9775 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009776 "void main(){\n"
9777 " gl_Position = vec4(1);\n"
9778 "}\n";
9779 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009780 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009781 "\n"
9782 "layout(location=0) in float x;\n"
9783 "layout(location=0) out vec4 color;\n"
9784 "void main(){\n"
9785 " color = vec4(x);\n"
9786 "}\n";
9787
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009788 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9789 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009790
9791 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009792 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009793 pipe.AddShader(&vs);
9794 pipe.AddShader(&fs);
9795
Chris Forbes59cb88d2015-05-25 11:13:13 +12009796 VkDescriptorSetObj descriptorSet(m_device);
9797 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009798 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009799
Tony Barbour5781e8f2015-08-04 16:23:11 -06009800 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009801
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009802 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009803}
9804
Karl Schultz6addd812016-02-02 17:17:23 -07009805TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009807 "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009808
9809 ASSERT_NO_FATAL_FAILURE(InitState());
9810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9811
9812 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009813 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009814 "\n"
9815 "out gl_PerVertex {\n"
9816 " vec4 gl_Position;\n"
9817 "};\n"
9818 "void main(){\n"
9819 " gl_Position = vec4(1);\n"
9820 "}\n";
9821 char const *fsSource =
9822 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009823 "\n"
9824 "in block { layout(location=0) float x; } ins;\n"
9825 "layout(location=0) out vec4 color;\n"
9826 "void main(){\n"
9827 " color = vec4(ins.x);\n"
9828 "}\n";
9829
9830 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9831 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9832
9833 VkPipelineObj pipe(m_device);
9834 pipe.AddColorAttachment();
9835 pipe.AddShader(&vs);
9836 pipe.AddShader(&fs);
9837
9838 VkDescriptorSetObj descriptorSet(m_device);
9839 descriptorSet.AppendDummy();
9840 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9841
9842 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9843
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009844 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13009845}
9846
Karl Schultz6addd812016-02-02 17:17:23 -07009847TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes0036fd12016-01-26 14:19:49 +13009848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbese9928822016-02-17 14:44:52 +13009849 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz6addd812016-02-02 17:17:23 -07009850 "output arr[2] of float32' vs 'ptr to "
9851 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +13009852
9853 ASSERT_NO_FATAL_FAILURE(InitState());
9854 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9855
9856 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009857 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009858 "\n"
9859 "layout(location=0) out float x[2];\n"
9860 "out gl_PerVertex {\n"
9861 " vec4 gl_Position;\n"
9862 "};\n"
9863 "void main(){\n"
9864 " x[0] = 0; x[1] = 0;\n"
9865 " gl_Position = vec4(1);\n"
9866 "}\n";
9867 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009868 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009869 "\n"
9870 "layout(location=0) in float x[3];\n"
9871 "layout(location=0) out vec4 color;\n"
9872 "void main(){\n"
9873 " color = vec4(x[0] + x[1] + x[2]);\n"
9874 "}\n";
9875
9876 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9877 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9878
9879 VkPipelineObj pipe(m_device);
9880 pipe.AddColorAttachment();
9881 pipe.AddShader(&vs);
9882 pipe.AddShader(&fs);
9883
9884 VkDescriptorSetObj descriptorSet(m_device);
9885 descriptorSet.AppendDummy();
9886 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9887
9888 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9889
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009890 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +13009891}
9892
Karl Schultz6addd812016-02-02 17:17:23 -07009893TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009895 "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009896
Chris Forbesb56af562015-05-25 11:13:17 +12009897 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009898 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12009899
9900 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009901 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009902 "\n"
9903 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009904 "out gl_PerVertex {\n"
9905 " vec4 gl_Position;\n"
9906 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009907 "void main(){\n"
9908 " x = 0;\n"
9909 " gl_Position = vec4(1);\n"
9910 "}\n";
9911 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009912 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009913 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009914 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbesb56af562015-05-25 11:13:17 +12009915 "layout(location=0) out vec4 color;\n"
9916 "void main(){\n"
9917 " color = vec4(x);\n"
9918 "}\n";
9919
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009920 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9921 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12009922
9923 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009924 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12009925 pipe.AddShader(&vs);
9926 pipe.AddShader(&fs);
9927
Chris Forbesb56af562015-05-25 11:13:17 +12009928 VkDescriptorSetObj descriptorSet(m_device);
9929 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009930 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12009931
Tony Barbour5781e8f2015-08-04 16:23:11 -06009932 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12009933
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009934 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +12009935}
9936
Karl Schultz6addd812016-02-02 17:17:23 -07009937TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009939 "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009940
9941 ASSERT_NO_FATAL_FAILURE(InitState());
9942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9943
9944 char const *vsSource =
9945 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009946 "\n"
9947 "out block { layout(location=0) int x; } outs;\n"
9948 "out gl_PerVertex {\n"
9949 " vec4 gl_Position;\n"
9950 "};\n"
9951 "void main(){\n"
9952 " outs.x = 0;\n"
9953 " gl_Position = vec4(1);\n"
9954 "}\n";
9955 char const *fsSource =
9956 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009957 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009958 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbesa3e85f62016-01-15 14:53:11 +13009959 "layout(location=0) out vec4 color;\n"
9960 "void main(){\n"
9961 " color = vec4(ins.x);\n"
9962 "}\n";
9963
9964 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9965 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9966
9967 VkPipelineObj pipe(m_device);
9968 pipe.AddColorAttachment();
9969 pipe.AddShader(&vs);
9970 pipe.AddShader(&fs);
9971
9972 VkDescriptorSetObj descriptorSet(m_device);
9973 descriptorSet.AppendDummy();
9974 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9975
9976 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9977
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009978 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13009979}
9980
9981TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
9982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9983 "location 0.0 which is not written by vertex shader");
9984
9985 ASSERT_NO_FATAL_FAILURE(InitState());
9986 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9987
9988 char const *vsSource =
9989 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009990 "\n"
9991 "out block { layout(location=1) float x; } outs;\n"
9992 "out gl_PerVertex {\n"
9993 " vec4 gl_Position;\n"
9994 "};\n"
9995 "void main(){\n"
9996 " outs.x = 0;\n"
9997 " gl_Position = vec4(1);\n"
9998 "}\n";
9999 char const *fsSource =
10000 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +130010001 "\n"
10002 "in block { layout(location=0) float x; } ins;\n"
10003 "layout(location=0) out vec4 color;\n"
10004 "void main(){\n"
10005 " color = vec4(ins.x);\n"
10006 "}\n";
10007
10008 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10009 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10010
10011 VkPipelineObj pipe(m_device);
10012 pipe.AddColorAttachment();
10013 pipe.AddShader(&vs);
10014 pipe.AddShader(&fs);
10015
10016 VkDescriptorSetObj descriptorSet(m_device);
10017 descriptorSet.AppendDummy();
10018 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10019
10020 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10021
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010022 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130010023}
10024
10025TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
10026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10027 "location 0.1 which is not written by vertex shader");
10028
10029 ASSERT_NO_FATAL_FAILURE(InitState());
10030 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10031
10032 char const *vsSource =
10033 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +130010034 "\n"
10035 "out block { layout(location=0, component=0) float x; } outs;\n"
10036 "out gl_PerVertex {\n"
10037 " vec4 gl_Position;\n"
10038 "};\n"
10039 "void main(){\n"
10040 " outs.x = 0;\n"
10041 " gl_Position = vec4(1);\n"
10042 "}\n";
10043 char const *fsSource =
10044 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +130010045 "\n"
10046 "in block { layout(location=0, component=1) float x; } ins;\n"
10047 "layout(location=0) out vec4 color;\n"
10048 "void main(){\n"
10049 " color = vec4(ins.x);\n"
10050 "}\n";
10051
10052 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10053 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10054
10055 VkPipelineObj pipe(m_device);
10056 pipe.AddColorAttachment();
10057 pipe.AddShader(&vs);
10058 pipe.AddShader(&fs);
10059
10060 VkDescriptorSetObj descriptorSet(m_device);
10061 descriptorSet.AppendDummy();
10062 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10063
10064 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10065
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010066 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130010067}
10068
Karl Schultz6addd812016-02-02 17:17:23 -070010069TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010070 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010071 "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010072
Chris Forbesde136e02015-05-25 11:13:28 +120010073 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010074 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120010075
10076 VkVertexInputBindingDescription input_binding;
10077 memset(&input_binding, 0, sizeof(input_binding));
10078
10079 VkVertexInputAttributeDescription input_attrib;
10080 memset(&input_attrib, 0, sizeof(input_attrib));
10081 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10082
10083 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010084 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +120010085 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010086 "out gl_PerVertex {\n"
10087 " vec4 gl_Position;\n"
10088 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +120010089 "void main(){\n"
10090 " gl_Position = vec4(1);\n"
10091 "}\n";
10092 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010093 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +120010094 "\n"
10095 "layout(location=0) out vec4 color;\n"
10096 "void main(){\n"
10097 " color = vec4(1);\n"
10098 "}\n";
10099
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010100 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10101 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120010102
10103 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010104 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120010105 pipe.AddShader(&vs);
10106 pipe.AddShader(&fs);
10107
10108 pipe.AddVertexInputBindings(&input_binding, 1);
10109 pipe.AddVertexInputAttribs(&input_attrib, 1);
10110
Chris Forbesde136e02015-05-25 11:13:28 +120010111 VkDescriptorSetObj descriptorSet(m_device);
10112 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010113 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120010114
Tony Barbour5781e8f2015-08-04 16:23:11 -060010115 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120010116
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010117 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120010118}
10119
Karl Schultz6addd812016-02-02 17:17:23 -070010120TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010122 "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130010123
10124 ASSERT_NO_FATAL_FAILURE(InitState());
10125 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10126
10127 VkVertexInputBindingDescription input_binding;
10128 memset(&input_binding, 0, sizeof(input_binding));
10129
10130 VkVertexInputAttributeDescription input_attrib;
10131 memset(&input_attrib, 0, sizeof(input_attrib));
10132 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10133
10134 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010135 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +130010136 "\n"
10137 "layout(location=1) in float x;\n"
10138 "out gl_PerVertex {\n"
10139 " vec4 gl_Position;\n"
10140 "};\n"
10141 "void main(){\n"
10142 " gl_Position = vec4(x);\n"
10143 "}\n";
10144 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010145 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +130010146 "\n"
10147 "layout(location=0) out vec4 color;\n"
10148 "void main(){\n"
10149 " color = vec4(1);\n"
10150 "}\n";
10151
10152 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10153 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10154
10155 VkPipelineObj pipe(m_device);
10156 pipe.AddColorAttachment();
10157 pipe.AddShader(&vs);
10158 pipe.AddShader(&fs);
10159
10160 pipe.AddVertexInputBindings(&input_binding, 1);
10161 pipe.AddVertexInputAttribs(&input_attrib, 1);
10162
10163 VkDescriptorSetObj descriptorSet(m_device);
10164 descriptorSet.AppendDummy();
10165 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10166
10167 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10168
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010169 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130010170}
10171
Karl Schultz6addd812016-02-02 17:17:23 -070010172TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
10173 m_errorMonitor->SetDesiredFailureMsg(
10174 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010175 "VS consumes input at location 0 but not provided");
10176
Chris Forbes62e8e502015-05-25 11:13:29 +120010177 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120010179
10180 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010181 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +120010182 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010183 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -070010184 "out gl_PerVertex {\n"
10185 " vec4 gl_Position;\n"
10186 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +120010187 "void main(){\n"
10188 " gl_Position = x;\n"
10189 "}\n";
10190 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010191 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +120010192 "\n"
10193 "layout(location=0) out vec4 color;\n"
10194 "void main(){\n"
10195 " color = vec4(1);\n"
10196 "}\n";
10197
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010198 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10199 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120010200
10201 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010202 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120010203 pipe.AddShader(&vs);
10204 pipe.AddShader(&fs);
10205
Chris Forbes62e8e502015-05-25 11:13:29 +120010206 VkDescriptorSetObj descriptorSet(m_device);
10207 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010208 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120010209
Tony Barbour5781e8f2015-08-04 16:23:11 -060010210 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120010211
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010212 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120010213}
10214
Karl Schultz6addd812016-02-02 17:17:23 -070010215TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
10216 m_errorMonitor->SetDesiredFailureMsg(
10217 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010218 "location 0 does not match VS input type");
10219
Chris Forbesc97d98e2015-05-25 11:13:31 +120010220 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010221 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120010222
10223 VkVertexInputBindingDescription input_binding;
10224 memset(&input_binding, 0, sizeof(input_binding));
10225
10226 VkVertexInputAttributeDescription input_attrib;
10227 memset(&input_attrib, 0, sizeof(input_attrib));
10228 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10229
10230 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010231 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010232 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010233 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -070010234 "out gl_PerVertex {\n"
10235 " vec4 gl_Position;\n"
10236 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010237 "void main(){\n"
10238 " gl_Position = vec4(x);\n"
10239 "}\n";
10240 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010241 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010242 "\n"
10243 "layout(location=0) out vec4 color;\n"
10244 "void main(){\n"
10245 " color = vec4(1);\n"
10246 "}\n";
10247
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010248 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10249 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120010250
10251 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010252 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120010253 pipe.AddShader(&vs);
10254 pipe.AddShader(&fs);
10255
10256 pipe.AddVertexInputBindings(&input_binding, 1);
10257 pipe.AddVertexInputAttribs(&input_attrib, 1);
10258
Chris Forbesc97d98e2015-05-25 11:13:31 +120010259 VkDescriptorSetObj descriptorSet(m_device);
10260 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010261 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120010262
Tony Barbour5781e8f2015-08-04 16:23:11 -060010263 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120010264
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010265 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120010266}
10267
Chris Forbesc68b43c2016-04-06 11:18:47 +120010268TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
10269 m_errorMonitor->SetDesiredFailureMsg(
10270 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10271 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
10272
10273 ASSERT_NO_FATAL_FAILURE(InitState());
10274 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10275
10276 char const *vsSource =
10277 "#version 450\n"
10278 "\n"
10279 "out gl_PerVertex {\n"
10280 " vec4 gl_Position;\n"
10281 "};\n"
10282 "void main(){\n"
10283 " gl_Position = vec4(1);\n"
10284 "}\n";
10285 char const *fsSource =
10286 "#version 450\n"
10287 "\n"
10288 "layout(location=0) out vec4 color;\n"
10289 "void main(){\n"
10290 " color = vec4(1);\n"
10291 "}\n";
10292
10293 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10294 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10295
10296 VkPipelineObj pipe(m_device);
10297 pipe.AddColorAttachment();
10298 pipe.AddShader(&vs);
10299 pipe.AddShader(&vs);
10300 pipe.AddShader(&fs);
10301
10302 VkDescriptorSetObj descriptorSet(m_device);
10303 descriptorSet.AppendDummy();
10304 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10305
10306 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10307
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010308 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120010309}
10310
Karl Schultz6addd812016-02-02 17:17:23 -070010311TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010312 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130010313
10314 ASSERT_NO_FATAL_FAILURE(InitState());
10315 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10316
10317 VkVertexInputBindingDescription input_binding;
10318 memset(&input_binding, 0, sizeof(input_binding));
10319
10320 VkVertexInputAttributeDescription input_attribs[2];
10321 memset(input_attribs, 0, sizeof(input_attribs));
10322
10323 for (int i = 0; i < 2; i++) {
10324 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10325 input_attribs[i].location = i;
10326 }
10327
10328 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010329 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010330 "\n"
10331 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -070010332 "out gl_PerVertex {\n"
10333 " vec4 gl_Position;\n"
10334 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010335 "void main(){\n"
10336 " gl_Position = x[0] + x[1];\n"
10337 "}\n";
10338 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010339 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010340 "\n"
10341 "layout(location=0) out vec4 color;\n"
10342 "void main(){\n"
10343 " color = vec4(1);\n"
10344 "}\n";
10345
10346 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10347 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10348
10349 VkPipelineObj pipe(m_device);
10350 pipe.AddColorAttachment();
10351 pipe.AddShader(&vs);
10352 pipe.AddShader(&fs);
10353
10354 pipe.AddVertexInputBindings(&input_binding, 1);
10355 pipe.AddVertexInputAttribs(input_attribs, 2);
10356
10357 VkDescriptorSetObj descriptorSet(m_device);
10358 descriptorSet.AppendDummy();
10359 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10360
10361 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10362
10363 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010364 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010365}
10366
Chris Forbes2682b242015-11-24 11:13:14 +130010367TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
10368{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010369 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130010370
10371 ASSERT_NO_FATAL_FAILURE(InitState());
10372 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10373
10374 VkVertexInputBindingDescription input_binding;
10375 memset(&input_binding, 0, sizeof(input_binding));
10376
10377 VkVertexInputAttributeDescription input_attribs[2];
10378 memset(input_attribs, 0, sizeof(input_attribs));
10379
10380 for (int i = 0; i < 2; i++) {
10381 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10382 input_attribs[i].location = i;
10383 }
10384
10385 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010386 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010387 "\n"
10388 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -070010389 "out gl_PerVertex {\n"
10390 " vec4 gl_Position;\n"
10391 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010392 "void main(){\n"
10393 " gl_Position = x[0] + x[1];\n"
10394 "}\n";
10395 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010396 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010397 "\n"
10398 "layout(location=0) out vec4 color;\n"
10399 "void main(){\n"
10400 " color = vec4(1);\n"
10401 "}\n";
10402
10403 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10404 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10405
10406 VkPipelineObj pipe(m_device);
10407 pipe.AddColorAttachment();
10408 pipe.AddShader(&vs);
10409 pipe.AddShader(&fs);
10410
10411 pipe.AddVertexInputBindings(&input_binding, 1);
10412 pipe.AddVertexInputAttribs(input_attribs, 2);
10413
10414 VkDescriptorSetObj descriptorSet(m_device);
10415 descriptorSet.AppendDummy();
10416 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10417
10418 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10419
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010420 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010421}
Chris Forbes2682b242015-11-24 11:13:14 +130010422
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010423TEST_F(VkLayerTest, CreatePipelineSimplePositive)
10424{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010425 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010426
10427 ASSERT_NO_FATAL_FAILURE(InitState());
10428 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10429
10430 char const *vsSource =
10431 "#version 450\n"
10432 "out gl_PerVertex {\n"
10433 " vec4 gl_Position;\n"
10434 "};\n"
10435 "void main(){\n"
10436 " gl_Position = vec4(0);\n"
10437 "}\n";
10438 char const *fsSource =
10439 "#version 450\n"
10440 "\n"
10441 "layout(location=0) out vec4 color;\n"
10442 "void main(){\n"
10443 " color = vec4(1);\n"
10444 "}\n";
10445
10446 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10447 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10448
10449 VkPipelineObj pipe(m_device);
10450 pipe.AddColorAttachment();
10451 pipe.AddShader(&vs);
10452 pipe.AddShader(&fs);
10453
10454 VkDescriptorSetObj descriptorSet(m_device);
10455 descriptorSet.AppendDummy();
10456 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10457
10458 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10459
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010460 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010461}
10462
Chris Forbes912c9192016-04-05 17:50:35 +120010463TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch)
10464{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010465 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120010466
10467 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
10468
10469 ASSERT_NO_FATAL_FAILURE(InitState());
10470 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10471
10472 char const *vsSource =
10473 "#version 450\n"
10474 "out gl_PerVertex {\n"
10475 " vec4 gl_Position;\n"
10476 "};\n"
10477 "layout(location=0) out vec3 x;\n"
10478 "layout(location=1) out ivec3 y;\n"
10479 "layout(location=2) out vec3 z;\n"
10480 "void main(){\n"
10481 " gl_Position = vec4(0);\n"
10482 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
10483 "}\n";
10484 char const *fsSource =
10485 "#version 450\n"
10486 "\n"
10487 "layout(location=0) out vec4 color;\n"
10488 "layout(location=0) in float x;\n"
10489 "layout(location=1) flat in int y;\n"
10490 "layout(location=2) in vec2 z;\n"
10491 "void main(){\n"
10492 " color = vec4(1 + x + y + z.x);\n"
10493 "}\n";
10494
10495 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10496 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10497
10498 VkPipelineObj pipe(m_device);
10499 pipe.AddColorAttachment();
10500 pipe.AddShader(&vs);
10501 pipe.AddShader(&fs);
10502
10503 VkDescriptorSetObj descriptorSet(m_device);
10504 descriptorSet.AppendDummy();
10505 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10506
10507 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10508
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010509 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120010510}
10511
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010512TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
10513{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010514 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010515
10516 ASSERT_NO_FATAL_FAILURE(InitState());
10517 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10518
Chris Forbesc1e852d2016-04-04 19:26:42 +120010519 if (!m_device->phy().features().tessellationShader) {
10520 printf("Device does not support tessellation shaders; skipped.\n");
10521 return;
10522 }
10523
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010524 char const *vsSource =
10525 "#version 450\n"
10526 "void main(){}\n";
10527 char const *tcsSource =
10528 "#version 450\n"
10529 "layout(location=0) out int x[];\n"
10530 "layout(vertices=3) out;\n"
10531 "void main(){\n"
10532 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10533 " gl_TessLevelInner[0] = 1;\n"
10534 " x[gl_InvocationID] = gl_InvocationID;\n"
10535 "}\n";
10536 char const *tesSource =
10537 "#version 450\n"
10538 "layout(triangles, equal_spacing, cw) in;\n"
10539 "layout(location=0) in int x[];\n"
10540 "out gl_PerVertex { vec4 gl_Position; };\n"
10541 "void main(){\n"
10542 " gl_Position.xyz = gl_TessCoord;\n"
10543 " gl_Position.w = x[0] + x[1] + x[2];\n"
10544 "}\n";
10545 char const *fsSource =
10546 "#version 450\n"
10547 "layout(location=0) out vec4 color;\n"
10548 "void main(){\n"
10549 " color = vec4(1);\n"
10550 "}\n";
10551
10552 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10553 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10554 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10555 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10556
10557 VkPipelineInputAssemblyStateCreateInfo iasci{
10558 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10559 nullptr,
10560 0,
10561 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10562 VK_FALSE};
10563
Chris Forbesb4cacb62016-04-04 19:15:00 +120010564 VkPipelineTessellationStateCreateInfo tsci{
10565 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10566 nullptr,
10567 0,
10568 3};
10569
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010570 VkPipelineObj pipe(m_device);
10571 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120010572 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010573 pipe.AddColorAttachment();
10574 pipe.AddShader(&vs);
10575 pipe.AddShader(&tcs);
10576 pipe.AddShader(&tes);
10577 pipe.AddShader(&fs);
10578
10579 VkDescriptorSetObj descriptorSet(m_device);
10580 descriptorSet.AppendDummy();
10581 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10582
10583 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10584
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010585 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010586}
10587
Chris Forbesa0ab8152016-04-20 13:34:27 +120010588TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive)
10589{
10590 m_errorMonitor->ExpectSuccess();
10591
10592 ASSERT_NO_FATAL_FAILURE(InitState());
10593 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10594
10595 if (!m_device->phy().features().geometryShader) {
10596 printf("Device does not support geometry shaders; skipped.\n");
10597 return;
10598 }
10599
10600 char const *vsSource =
10601 "#version 450\n"
10602 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
10603 "void main(){\n"
10604 " vs_out.x = vec4(1);\n"
10605 "}\n";
10606 char const *gsSource =
10607 "#version 450\n"
10608 "layout(triangles) in;\n"
10609 "layout(triangle_strip, max_vertices=3) out;\n"
10610 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
10611 "out gl_PerVertex { vec4 gl_Position; };\n"
10612 "void main() {\n"
10613 " gl_Position = gs_in[0].x;\n"
10614 " EmitVertex();\n"
10615 "}\n";
10616 char const *fsSource =
10617 "#version 450\n"
10618 "layout(location=0) out vec4 color;\n"
10619 "void main(){\n"
10620 " color = vec4(1);\n"
10621 "}\n";
10622
10623 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10624 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
10625 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10626
10627 VkPipelineObj pipe(m_device);
10628 pipe.AddColorAttachment();
10629 pipe.AddShader(&vs);
10630 pipe.AddShader(&gs);
10631 pipe.AddShader(&fs);
10632
10633 VkDescriptorSetObj descriptorSet(m_device);
10634 descriptorSet.AppendDummy();
10635 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10636
10637 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10638
10639 m_errorMonitor->VerifyNotFound();
10640}
10641
Chris Forbesa0193bc2016-04-04 19:19:47 +120010642TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
10643{
10644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10645 "is per-vertex in tessellation control shader stage "
10646 "but per-patch in tessellation evaluation shader stage");
10647
10648 ASSERT_NO_FATAL_FAILURE(InitState());
10649 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10650
Chris Forbesc1e852d2016-04-04 19:26:42 +120010651 if (!m_device->phy().features().tessellationShader) {
10652 printf("Device does not support tessellation shaders; skipped.\n");
10653 return;
10654 }
10655
Chris Forbesa0193bc2016-04-04 19:19:47 +120010656 char const *vsSource =
10657 "#version 450\n"
10658 "void main(){}\n";
10659 char const *tcsSource =
10660 "#version 450\n"
10661 "layout(location=0) out int x[];\n"
10662 "layout(vertices=3) out;\n"
10663 "void main(){\n"
10664 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10665 " gl_TessLevelInner[0] = 1;\n"
10666 " x[gl_InvocationID] = gl_InvocationID;\n"
10667 "}\n";
10668 char const *tesSource =
10669 "#version 450\n"
10670 "layout(triangles, equal_spacing, cw) in;\n"
10671 "layout(location=0) patch in int x;\n"
10672 "out gl_PerVertex { vec4 gl_Position; };\n"
10673 "void main(){\n"
10674 " gl_Position.xyz = gl_TessCoord;\n"
10675 " gl_Position.w = x;\n"
10676 "}\n";
10677 char const *fsSource =
10678 "#version 450\n"
10679 "layout(location=0) out vec4 color;\n"
10680 "void main(){\n"
10681 " color = vec4(1);\n"
10682 "}\n";
10683
10684 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10685 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10686 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10687 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10688
10689 VkPipelineInputAssemblyStateCreateInfo iasci{
10690 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10691 nullptr,
10692 0,
10693 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10694 VK_FALSE};
10695
10696 VkPipelineTessellationStateCreateInfo tsci{
10697 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10698 nullptr,
10699 0,
10700 3};
10701
10702 VkPipelineObj pipe(m_device);
10703 pipe.SetInputAssembly(&iasci);
10704 pipe.SetTessellation(&tsci);
10705 pipe.AddColorAttachment();
10706 pipe.AddShader(&vs);
10707 pipe.AddShader(&tcs);
10708 pipe.AddShader(&tes);
10709 pipe.AddShader(&fs);
10710
10711 VkDescriptorSetObj descriptorSet(m_device);
10712 descriptorSet.AppendDummy();
10713 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10714
10715 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10716
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010717 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120010718}
10719
Karl Schultz6addd812016-02-02 17:17:23 -070010720TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
10721 m_errorMonitor->SetDesiredFailureMsg(
10722 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010723 "Duplicate vertex input binding descriptions for binding 0");
10724
Chris Forbes280ba2c2015-06-12 11:16:41 +120010725 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010726 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010727
10728 /* Two binding descriptions for binding 0 */
10729 VkVertexInputBindingDescription input_bindings[2];
10730 memset(input_bindings, 0, sizeof(input_bindings));
10731
10732 VkVertexInputAttributeDescription input_attrib;
10733 memset(&input_attrib, 0, sizeof(input_attrib));
10734 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10735
10736 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010737 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010738 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010739 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -070010740 "out gl_PerVertex {\n"
10741 " vec4 gl_Position;\n"
10742 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010743 "void main(){\n"
10744 " gl_Position = vec4(x);\n"
10745 "}\n";
10746 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010747 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010748 "\n"
10749 "layout(location=0) out vec4 color;\n"
10750 "void main(){\n"
10751 " color = vec4(1);\n"
10752 "}\n";
10753
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010754 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10755 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010756
10757 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010758 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010759 pipe.AddShader(&vs);
10760 pipe.AddShader(&fs);
10761
10762 pipe.AddVertexInputBindings(input_bindings, 2);
10763 pipe.AddVertexInputAttribs(&input_attrib, 1);
10764
Chris Forbes280ba2c2015-06-12 11:16:41 +120010765 VkDescriptorSetObj descriptorSet(m_device);
10766 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010767 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010768
Tony Barbour5781e8f2015-08-04 16:23:11 -060010769 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010770
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010771 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010772}
Chris Forbes8f68b562015-05-25 11:13:32 +120010773
Chris Forbes35efec72016-04-21 14:32:08 +120010774TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
10775 m_errorMonitor->ExpectSuccess();
10776
10777 ASSERT_NO_FATAL_FAILURE(InitState());
10778 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10779
10780 if (!m_device->phy().features().tessellationShader) {
10781 printf("Device does not support 64bit vertex attributes; skipped.\n");
10782 return;
10783 }
10784
10785 VkVertexInputBindingDescription input_bindings[1];
10786 memset(input_bindings, 0, sizeof(input_bindings));
10787
10788 VkVertexInputAttributeDescription input_attribs[4];
10789 memset(input_attribs, 0, sizeof(input_attribs));
10790 input_attribs[0].location = 0;
10791 input_attribs[0].offset = 0;
10792 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10793 input_attribs[1].location = 2;
10794 input_attribs[1].offset = 32;
10795 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10796 input_attribs[2].location = 4;
10797 input_attribs[2].offset = 64;
10798 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10799 input_attribs[3].location = 6;
10800 input_attribs[3].offset = 96;
10801 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10802
10803 char const *vsSource =
10804 "#version 450\n"
10805 "\n"
10806 "layout(location=0) in dmat4 x;\n"
10807 "out gl_PerVertex {\n"
10808 " vec4 gl_Position;\n"
10809 "};\n"
10810 "void main(){\n"
10811 " gl_Position = vec4(x[0][0]);\n"
10812 "}\n";
10813 char const *fsSource =
10814 "#version 450\n"
10815 "\n"
10816 "layout(location=0) out vec4 color;\n"
10817 "void main(){\n"
10818 " color = vec4(1);\n"
10819 "}\n";
10820
10821 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10822 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10823
10824 VkPipelineObj pipe(m_device);
10825 pipe.AddColorAttachment();
10826 pipe.AddShader(&vs);
10827 pipe.AddShader(&fs);
10828
10829 pipe.AddVertexInputBindings(input_bindings, 1);
10830 pipe.AddVertexInputAttribs(input_attribs, 4);
10831
10832 VkDescriptorSetObj descriptorSet(m_device);
10833 descriptorSet.AppendDummy();
10834 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10835
10836 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10837
10838 m_errorMonitor->VerifyNotFound();
10839}
10840
Karl Schultz6addd812016-02-02 17:17:23 -070010841TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010843 "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010844
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010845 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010846
10847 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010848 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010849 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010850 "out gl_PerVertex {\n"
10851 " vec4 gl_Position;\n"
10852 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010853 "void main(){\n"
10854 " gl_Position = vec4(1);\n"
10855 "}\n";
10856 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010857 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010858 "\n"
10859 "void main(){\n"
10860 "}\n";
10861
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010862 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10863 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010864
10865 VkPipelineObj pipe(m_device);
10866 pipe.AddShader(&vs);
10867 pipe.AddShader(&fs);
10868
Chia-I Wu08accc62015-07-07 11:50:03 +080010869 /* set up CB 0, not written */
10870 pipe.AddColorAttachment();
10871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010872
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010873 VkDescriptorSetObj descriptorSet(m_device);
10874 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010875 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010876
Tony Barbour5781e8f2015-08-04 16:23:11 -060010877 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010878
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010879 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010880}
10881
Karl Schultz6addd812016-02-02 17:17:23 -070010882TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Karl Schultz6addd812016-02-02 17:17:23 -070010883 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010884 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010885 "FS writes to output location 1 with no matching attachment");
10886
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010887 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010888
10889 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010890 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010891 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010892 "out gl_PerVertex {\n"
10893 " vec4 gl_Position;\n"
10894 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010895 "void main(){\n"
10896 " gl_Position = vec4(1);\n"
10897 "}\n";
10898 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010899 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010900 "\n"
10901 "layout(location=0) out vec4 x;\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010902 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010903 "void main(){\n"
10904 " x = vec4(1);\n"
10905 " y = vec4(1);\n"
10906 "}\n";
10907
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010908 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10909 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010910
10911 VkPipelineObj pipe(m_device);
10912 pipe.AddShader(&vs);
10913 pipe.AddShader(&fs);
10914
Chia-I Wu08accc62015-07-07 11:50:03 +080010915 /* set up CB 0, not written */
10916 pipe.AddColorAttachment();
10917 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010918 /* FS writes CB 1, but we don't configure it */
10919
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010920 VkDescriptorSetObj descriptorSet(m_device);
10921 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010922 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010923
Tony Barbour5781e8f2015-08-04 16:23:11 -060010924 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010925
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010926 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010927}
10928
Karl Schultz6addd812016-02-02 17:17:23 -070010929TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010931 "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010932
Chris Forbesa36d69e2015-05-25 11:13:44 +120010933 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010934
10935 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010936 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010937 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010938 "out gl_PerVertex {\n"
10939 " vec4 gl_Position;\n"
10940 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010941 "void main(){\n"
10942 " gl_Position = vec4(1);\n"
10943 "}\n";
10944 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010945 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010946 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010947 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbesa36d69e2015-05-25 11:13:44 +120010948 "void main(){\n"
10949 " x = ivec4(1);\n"
10950 "}\n";
10951
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010952 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10953 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120010954
10955 VkPipelineObj pipe(m_device);
10956 pipe.AddShader(&vs);
10957 pipe.AddShader(&fs);
10958
Chia-I Wu08accc62015-07-07 11:50:03 +080010959 /* set up CB 0; type is UNORM by default */
10960 pipe.AddColorAttachment();
10961 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010962
Chris Forbesa36d69e2015-05-25 11:13:44 +120010963 VkDescriptorSetObj descriptorSet(m_device);
10964 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010965 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120010966
Tony Barbour5781e8f2015-08-04 16:23:11 -060010967 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010968
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010969 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120010970}
Chris Forbes7b1b8932015-06-05 14:43:36 +120010971
Karl Schultz6addd812016-02-02 17:17:23 -070010972TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010973 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010974 "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010975
Chris Forbes556c76c2015-08-14 12:04:59 +120010976 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120010977
10978 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010979 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010980 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010981 "out gl_PerVertex {\n"
10982 " vec4 gl_Position;\n"
10983 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010984 "void main(){\n"
10985 " gl_Position = vec4(1);\n"
10986 "}\n";
10987 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010988 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010989 "\n"
10990 "layout(location=0) out vec4 x;\n"
10991 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
10992 "void main(){\n"
10993 " x = vec4(bar.y);\n"
10994 "}\n";
10995
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010996 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10997 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120010998
Chris Forbes556c76c2015-08-14 12:04:59 +120010999 VkPipelineObj pipe(m_device);
11000 pipe.AddShader(&vs);
11001 pipe.AddShader(&fs);
11002
11003 /* set up CB 0; type is UNORM by default */
11004 pipe.AddColorAttachment();
11005 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11006
11007 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011008 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120011009
11010 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
11011
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011012 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120011013}
11014
Chris Forbes5c59e902016-02-26 16:56:09 +130011015TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
11016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11017 "not declared in layout");
11018
11019 ASSERT_NO_FATAL_FAILURE(InitState());
11020
11021 char const *vsSource =
11022 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130011023 "\n"
11024 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
11025 "out gl_PerVertex {\n"
11026 " vec4 gl_Position;\n"
11027 "};\n"
11028 "void main(){\n"
11029 " gl_Position = vec4(consts.x);\n"
11030 "}\n";
11031 char const *fsSource =
11032 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130011033 "\n"
11034 "layout(location=0) out vec4 x;\n"
11035 "void main(){\n"
11036 " x = vec4(1);\n"
11037 "}\n";
11038
11039 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11040 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11041
11042 VkPipelineObj pipe(m_device);
11043 pipe.AddShader(&vs);
11044 pipe.AddShader(&fs);
11045
11046 /* set up CB 0; type is UNORM by default */
11047 pipe.AddColorAttachment();
11048 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11049
11050 VkDescriptorSetObj descriptorSet(m_device);
11051 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
11052
11053 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
11054
11055 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011056 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130011057}
11058
Chris Forbes10eb9ae2016-05-31 16:09:42 +120011059TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
11060 m_errorMonitor->SetDesiredFailureMsg(
11061 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11062 "Shader uses descriptor slot 0.0");
11063
11064 ASSERT_NO_FATAL_FAILURE(InitState());
11065
11066 char const *csSource =
11067 "#version 450\n"
11068 "\n"
11069 "layout(local_size_x=1) in;\n"
11070 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
11071 "void main(){\n"
11072 " x = vec4(1);\n"
11073 "}\n";
11074
11075 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
11076
11077 VkDescriptorSetObj descriptorSet(m_device);
11078 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
11079
11080 VkComputePipelineCreateInfo cpci = {
11081 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
11082 nullptr, 0, {
11083 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
11084 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
11085 cs.handle(), "main", nullptr
11086 },
11087 descriptorSet.GetPipelineLayout(),
11088 VK_NULL_HANDLE, -1
11089 };
11090
11091 VkPipeline pipe;
11092 VkResult err = vkCreateComputePipelines(
11093 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
11094
11095 m_errorMonitor->VerifyFound();
11096
11097 if (err == VK_SUCCESS) {
11098 vkDestroyPipeline(m_device->device(), pipe, nullptr);
11099 }
11100}
11101
11102TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
11103 m_errorMonitor->ExpectSuccess();
11104
11105 ASSERT_NO_FATAL_FAILURE(InitState());
11106
11107 char const *csSource =
11108 "#version 450\n"
11109 "\n"
11110 "layout(local_size_x=1) in;\n"
11111 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
11112 "void main(){\n"
11113 " // x is not used.\n"
11114 "}\n";
11115
11116 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
11117
11118 VkDescriptorSetObj descriptorSet(m_device);
11119 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
11120
11121 VkComputePipelineCreateInfo cpci = {
11122 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
11123 nullptr, 0, {
11124 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
11125 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
11126 cs.handle(), "main", nullptr
11127 },
11128 descriptorSet.GetPipelineLayout(),
11129 VK_NULL_HANDLE, -1
11130 };
11131
11132 VkPipeline pipe;
11133 VkResult err = vkCreateComputePipelines(
11134 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
11135
11136 m_errorMonitor->VerifyNotFound();
11137
11138 if (err == VK_SUCCESS) {
11139 vkDestroyPipeline(m_device->device(), pipe, nullptr);
11140 }
11141}
11142
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011143#endif // SHADER_CHECKER_TESTS
11144
11145#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060011146TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Karl Schultz6addd812016-02-02 17:17:23 -070011147 m_errorMonitor->SetDesiredFailureMsg(
11148 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011149 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011150
11151 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011152
11153 // Create an image
11154 VkImage image;
11155
Karl Schultz6addd812016-02-02 17:17:23 -070011156 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11157 const int32_t tex_width = 32;
11158 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011159
11160 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011161 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11162 image_create_info.pNext = NULL;
11163 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11164 image_create_info.format = tex_format;
11165 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011166 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070011167 image_create_info.extent.depth = 1;
11168 image_create_info.mipLevels = 1;
11169 image_create_info.arrayLayers = 1;
11170 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11171 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11172 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11173 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011174
11175 // Introduce error by sending down a bogus width extent
11176 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011177 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011178
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011179 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011180}
11181
Mark Youngc48c4c12016-04-11 14:26:49 -060011182TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
11183 m_errorMonitor->SetDesiredFailureMsg(
11184 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11185 "CreateImage extents is 0 for at least one required dimension");
11186
11187 ASSERT_NO_FATAL_FAILURE(InitState());
11188
11189 // Create an image
11190 VkImage image;
11191
11192 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11193 const int32_t tex_width = 32;
11194 const int32_t tex_height = 32;
11195
11196 VkImageCreateInfo image_create_info = {};
11197 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11198 image_create_info.pNext = NULL;
11199 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11200 image_create_info.format = tex_format;
11201 image_create_info.extent.width = tex_width;
11202 image_create_info.extent.height = tex_height;
11203 image_create_info.extent.depth = 1;
11204 image_create_info.mipLevels = 1;
11205 image_create_info.arrayLayers = 1;
11206 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11207 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11208 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11209 image_create_info.flags = 0;
11210
11211 // Introduce error by sending down a bogus width extent
11212 image_create_info.extent.width = 0;
11213 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
11214
11215 m_errorMonitor->VerifyFound();
11216}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011217#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120011218
Tobin Ehliscde08892015-09-22 10:11:37 -060011219#if IMAGE_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011220TEST_F(VkLayerTest, InvalidImageView) {
11221 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060011222
Karl Schultz6addd812016-02-02 17:17:23 -070011223 m_errorMonitor->SetDesiredFailureMsg(
11224 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011225 "vkCreateImageView called with baseMipLevel 10 ");
11226
Tobin Ehliscde08892015-09-22 10:11:37 -060011227 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060011228
Mike Stroyana3082432015-09-25 13:39:21 -060011229 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070011230 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060011231
Karl Schultz6addd812016-02-02 17:17:23 -070011232 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11233 const int32_t tex_width = 32;
11234 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060011235
11236 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011237 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11238 image_create_info.pNext = NULL;
11239 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11240 image_create_info.format = tex_format;
11241 image_create_info.extent.width = tex_width;
11242 image_create_info.extent.height = tex_height;
11243 image_create_info.extent.depth = 1;
11244 image_create_info.mipLevels = 1;
11245 image_create_info.arrayLayers = 1;
11246 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11247 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11248 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11249 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060011250
Chia-I Wuf7458c52015-10-26 21:10:41 +080011251 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060011252 ASSERT_VK_SUCCESS(err);
11253
11254 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011255 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11256 image_view_create_info.image = image;
11257 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11258 image_view_create_info.format = tex_format;
11259 image_view_create_info.subresourceRange.layerCount = 1;
11260 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
11261 image_view_create_info.subresourceRange.levelCount = 1;
11262 image_view_create_info.subresourceRange.aspectMask =
11263 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060011264
11265 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070011266 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
11267 &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060011268
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011269 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060011270 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060011271}
Mike Stroyana3082432015-09-25 13:39:21 -060011272
Karl Schultz6addd812016-02-02 17:17:23 -070011273TEST_F(VkLayerTest, InvalidImageViewAspect) {
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011274 TEST_DESCRIPTION(
11275 "Create an image and try to create a view with an invalid aspectMask");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070011277 "vkCreateImageView: Color image "
11278 "formats must have ONLY the "
11279 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011280
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011281 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011282
Karl Schultz6addd812016-02-02 17:17:23 -070011283 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011284 VkImageObj image(m_device);
11285 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT,
11286 VK_IMAGE_TILING_LINEAR, 0);
11287 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011288
11289 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011290 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011291 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070011292 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11293 image_view_create_info.format = tex_format;
11294 image_view_create_info.subresourceRange.baseMipLevel = 0;
11295 image_view_create_info.subresourceRange.levelCount = 1;
11296 // Cause an error by setting an invalid image aspect
11297 image_view_create_info.subresourceRange.aspectMask =
11298 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011299
11300 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011301 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011302
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011303 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011304}
11305
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011306TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070011307 VkResult err;
11308 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011309
Karl Schultz6addd812016-02-02 17:17:23 -070011310 m_errorMonitor->SetDesiredFailureMsg(
11311 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011312 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011313
Mike Stroyana3082432015-09-25 13:39:21 -060011314 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011315
11316 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011317 VkImage srcImage;
11318 VkImage dstImage;
11319 VkDeviceMemory srcMem;
11320 VkDeviceMemory destMem;
11321 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011322
11323 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011324 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11325 image_create_info.pNext = NULL;
11326 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11327 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11328 image_create_info.extent.width = 32;
11329 image_create_info.extent.height = 32;
11330 image_create_info.extent.depth = 1;
11331 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011332 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070011333 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11334 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11335 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11336 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011337
Karl Schultz6addd812016-02-02 17:17:23 -070011338 err =
11339 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011340 ASSERT_VK_SUCCESS(err);
11341
Karl Schultz6addd812016-02-02 17:17:23 -070011342 err =
11343 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011344 ASSERT_VK_SUCCESS(err);
11345
11346 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011347 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011348 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11349 memAlloc.pNext = NULL;
11350 memAlloc.allocationSize = 0;
11351 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011352
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011353 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011354 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011355 pass =
11356 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011357 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011358 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011359 ASSERT_VK_SUCCESS(err);
11360
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011361 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011362 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011363 pass =
11364 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011365 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011366 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011367 ASSERT_VK_SUCCESS(err);
11368
11369 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11370 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011371 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011372 ASSERT_VK_SUCCESS(err);
11373
11374 BeginCommandBuffer();
11375 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011376 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011377 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011378 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011379 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060011380 copyRegion.srcOffset.x = 0;
11381 copyRegion.srcOffset.y = 0;
11382 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011383 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011384 copyRegion.dstSubresource.mipLevel = 0;
11385 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011386 // Introduce failure by forcing the dst layerCount to differ from src
11387 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011388 copyRegion.dstOffset.x = 0;
11389 copyRegion.dstOffset.y = 0;
11390 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011391 copyRegion.extent.width = 1;
11392 copyRegion.extent.height = 1;
11393 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011394 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11395 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011396 EndCommandBuffer();
11397
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011398 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011399
Chia-I Wuf7458c52015-10-26 21:10:41 +080011400 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011401 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011402 vkFreeMemory(m_device->device(), srcMem, NULL);
11403 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011404}
11405
Tony Barbourd6673642016-05-05 14:46:39 -060011406TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
11407
11408 TEST_DESCRIPTION("Creating images with unsuported formats ");
11409
11410 ASSERT_NO_FATAL_FAILURE(InitState());
11411 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11412 VkImageObj image(m_device);
11413 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11414 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11415 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11416 VK_IMAGE_TILING_OPTIMAL, 0);
11417 ASSERT_TRUE(image.initialized());
11418
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011419 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
11420 VkImageCreateInfo image_create_info;
11421 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11422 image_create_info.pNext = NULL;
11423 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11424 image_create_info.format = VK_FORMAT_UNDEFINED;
11425 image_create_info.extent.width = 32;
11426 image_create_info.extent.height = 32;
11427 image_create_info.extent.depth = 1;
11428 image_create_info.mipLevels = 1;
11429 image_create_info.arrayLayers = 1;
11430 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11431 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11432 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11433 image_create_info.flags = 0;
11434
11435 m_errorMonitor->SetDesiredFailureMsg(
11436 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11437 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
11438
11439 VkImage localImage;
11440 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
11441 m_errorMonitor->VerifyFound();
11442
Tony Barbourd6673642016-05-05 14:46:39 -060011443 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011444 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060011445 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
11446 VkFormat format = static_cast<VkFormat>(f);
11447 VkFormatProperties fProps = m_device->format_properties(format);
11448 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
11449 fProps.optimalTilingFeatures == 0) {
11450 unsupported = format;
11451 break;
11452 }
11453 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011454
Tony Barbourd6673642016-05-05 14:46:39 -060011455 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060011456 image_create_info.format = unsupported;
Tony Barbourd6673642016-05-05 14:46:39 -060011457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011458 "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060011459
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011460 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060011461 m_errorMonitor->VerifyFound();
11462 }
11463}
11464
11465TEST_F(VkLayerTest, ImageLayerViewTests) {
11466 VkResult ret;
11467 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
11468
11469 ASSERT_NO_FATAL_FAILURE(InitState());
11470
11471 VkImageObj image(m_device);
11472 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11473 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11474 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11475 VK_IMAGE_TILING_OPTIMAL, 0);
11476 ASSERT_TRUE(image.initialized());
11477
11478 VkImageView imgView;
11479 VkImageViewCreateInfo imgViewInfo = {};
11480 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11481 imgViewInfo.image = image.handle();
11482 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
11483 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11484 imgViewInfo.subresourceRange.layerCount = 1;
11485 imgViewInfo.subresourceRange.baseMipLevel = 0;
11486 imgViewInfo.subresourceRange.levelCount = 1;
11487 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11488
11489 m_errorMonitor->SetDesiredFailureMsg(
11490 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11491 "vkCreateImageView called with baseMipLevel");
11492 // View can't have baseMipLevel >= image's mipLevels - Expect
11493 // VIEW_CREATE_ERROR
11494 imgViewInfo.subresourceRange.baseMipLevel = 1;
11495 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11496 m_errorMonitor->VerifyFound();
11497 imgViewInfo.subresourceRange.baseMipLevel = 0;
11498
11499 m_errorMonitor->SetDesiredFailureMsg(
11500 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11501 "vkCreateImageView called with baseArrayLayer");
11502 // View can't have baseArrayLayer >= image's arraySize - Expect
11503 // VIEW_CREATE_ERROR
11504 imgViewInfo.subresourceRange.baseArrayLayer = 1;
11505 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11506 m_errorMonitor->VerifyFound();
11507 imgViewInfo.subresourceRange.baseArrayLayer = 0;
11508
11509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11510 "vkCreateImageView called with 0 in "
11511 "pCreateInfo->subresourceRange."
11512 "levelCount");
11513 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
11514 imgViewInfo.subresourceRange.levelCount = 0;
11515 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11516 m_errorMonitor->VerifyFound();
11517 imgViewInfo.subresourceRange.levelCount = 1;
11518
11519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11520 "vkCreateImageView called with 0 in "
11521 "pCreateInfo->subresourceRange."
11522 "layerCount");
11523 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
11524 imgViewInfo.subresourceRange.layerCount = 0;
11525 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11526 m_errorMonitor->VerifyFound();
11527 imgViewInfo.subresourceRange.layerCount = 1;
11528
11529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11530 "but both must be color formats");
11531 // Can't use depth format for view into color image - Expect INVALID_FORMAT
11532 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
11533 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11534 m_errorMonitor->VerifyFound();
11535 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11536
11537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11538 "Formats MUST be IDENTICAL unless "
11539 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
11540 "was set on image creation.");
11541 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
11542 // VIEW_CREATE_ERROR
11543 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
11544 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11545 m_errorMonitor->VerifyFound();
11546 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11547
11548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11549 "can support ImageViews with "
11550 "differing formats but they must be "
11551 "in the same compatibility class.");
11552 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
11553 // VIEW_CREATE_ERROR
11554 VkImageCreateInfo mutImgInfo = image.create_info();
11555 VkImage mutImage;
11556 mutImgInfo.format = VK_FORMAT_R8_UINT;
11557 assert(
11558 m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures &
11559 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
11560 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
11561 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11562 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
11563 ASSERT_VK_SUCCESS(ret);
11564 imgViewInfo.image = mutImage;
11565 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11566 m_errorMonitor->VerifyFound();
11567 imgViewInfo.image = image.handle();
11568 vkDestroyImage(m_device->handle(), mutImage, NULL);
11569}
11570
11571TEST_F(VkLayerTest, MiscImageLayerTests) {
11572
11573 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
11574
11575 ASSERT_NO_FATAL_FAILURE(InitState());
11576
11577 VkImageObj image(m_device);
11578 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11579 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11580 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11581 VK_IMAGE_TILING_OPTIMAL, 0);
11582 ASSERT_TRUE(image.initialized());
11583
11584 m_errorMonitor->SetDesiredFailureMsg(
11585 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11586 "number of layers in image subresource is zero");
11587 vk_testing::Buffer buffer;
11588 VkMemoryPropertyFlags reqs = 0;
11589 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
11590 VkBufferImageCopy region = {};
11591 region.bufferRowLength = 128;
11592 region.bufferImageHeight = 128;
11593 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11594 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
11595 region.imageSubresource.layerCount = 0;
11596 region.imageExtent.height = 4;
11597 region.imageExtent.width = 4;
11598 region.imageExtent.depth = 1;
11599 m_commandBuffer->BeginCommandBuffer();
11600 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11601 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11602 1, &region);
11603 m_errorMonitor->VerifyFound();
11604 region.imageSubresource.layerCount = 1;
11605
11606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11607 "aspectMasks for each region must "
11608 "specify only COLOR or DEPTH or "
11609 "STENCIL");
11610 // Expect MISMATCHED_IMAGE_ASPECT
11611 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
11612 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11613 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11614 1, &region);
11615 m_errorMonitor->VerifyFound();
11616 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11617
11618 m_errorMonitor->SetDesiredFailureMsg(
11619 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11620 "If the format of srcImage is a depth, stencil, depth stencil or "
11621 "integer-based format then filter must be VK_FILTER_NEAREST");
11622 // Expect INVALID_FILTER
11623 VkImageObj intImage1(m_device);
11624 intImage1.init(128, 128, VK_FORMAT_R8_UINT,
11625 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11626 0);
11627 VkImageObj intImage2(m_device);
11628 intImage2.init(128, 128, VK_FORMAT_R8_UINT,
11629 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11630 0);
11631 VkImageBlit blitRegion = {};
11632 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11633 blitRegion.srcSubresource.baseArrayLayer = 0;
11634 blitRegion.srcSubresource.layerCount = 1;
11635 blitRegion.srcSubresource.mipLevel = 0;
11636 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11637 blitRegion.dstSubresource.baseArrayLayer = 0;
11638 blitRegion.dstSubresource.layerCount = 1;
11639 blitRegion.dstSubresource.mipLevel = 0;
11640
11641 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(),
11642 intImage1.layout(), intImage2.handle(), intImage2.layout(),
11643 16, &blitRegion, VK_FILTER_LINEAR);
11644 m_errorMonitor->VerifyFound();
11645
11646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11647 "called with 0 in ppMemoryBarriers");
11648 VkImageMemoryBarrier img_barrier;
11649 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11650 img_barrier.pNext = NULL;
11651 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11652 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11653 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11654 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11655 img_barrier.image = image.handle();
11656 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11657 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11658 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11659 img_barrier.subresourceRange.baseArrayLayer = 0;
11660 img_barrier.subresourceRange.baseMipLevel = 0;
11661 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
11662 img_barrier.subresourceRange.layerCount = 0;
11663 img_barrier.subresourceRange.levelCount = 1;
11664 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
11665 VK_PIPELINE_STAGE_HOST_BIT,
11666 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
11667 nullptr, 1, &img_barrier);
11668 m_errorMonitor->VerifyFound();
11669 img_barrier.subresourceRange.layerCount = 1;
11670}
11671
11672TEST_F(VkLayerTest, ImageFormatLimits) {
11673
11674 TEST_DESCRIPTION("Exceed the limits of image format ");
11675
11676 m_errorMonitor->SetDesiredFailureMsg(
11677 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11678 "CreateImage extents exceed allowable limits for format");
11679 VkImageCreateInfo image_create_info = {};
11680 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11681 image_create_info.pNext = NULL;
11682 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11683 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11684 image_create_info.extent.width = 32;
11685 image_create_info.extent.height = 32;
11686 image_create_info.extent.depth = 1;
11687 image_create_info.mipLevels = 1;
11688 image_create_info.arrayLayers = 1;
11689 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11690 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11691 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11692 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11693 image_create_info.flags = 0;
11694
11695 VkImage nullImg;
11696 VkImageFormatProperties imgFmtProps;
11697 vkGetPhysicalDeviceImageFormatProperties(
11698 gpu(), image_create_info.format, image_create_info.imageType,
11699 image_create_info.tiling, image_create_info.usage,
11700 image_create_info.flags, &imgFmtProps);
11701 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
11702 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11703 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11704 m_errorMonitor->VerifyFound();
11705 image_create_info.extent.depth = 1;
11706
11707 m_errorMonitor->SetDesiredFailureMsg(
11708 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11709 "exceeds allowable maximum supported by format of");
11710 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
11711 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11712 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11713 m_errorMonitor->VerifyFound();
11714 image_create_info.mipLevels = 1;
11715
11716 m_errorMonitor->SetDesiredFailureMsg(
11717 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11718 "exceeds allowable maximum supported by format of");
11719 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
11720 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11721 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11722 m_errorMonitor->VerifyFound();
11723 image_create_info.arrayLayers = 1;
11724
11725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11726 "is not supported by format");
11727 int samples = imgFmtProps.sampleCounts >> 1;
11728 image_create_info.samples = (VkSampleCountFlagBits)samples;
11729 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11730 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11731 m_errorMonitor->VerifyFound();
11732 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11733
11734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11735 "pCreateInfo->initialLayout, must be "
11736 "VK_IMAGE_LAYOUT_UNDEFINED or "
11737 "VK_IMAGE_LAYOUT_PREINITIALIZED");
11738 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11739 // Expect INVALID_LAYOUT
11740 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11741 m_errorMonitor->VerifyFound();
11742 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11743}
11744
Karl Schultz6addd812016-02-02 17:17:23 -070011745TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060011746 VkResult err;
11747 bool pass;
11748
11749 // Create color images with different format sizes and try to copy between them
11750 m_errorMonitor->SetDesiredFailureMsg(
11751 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11752 "vkCmdCopyImage called with unmatched source and dest image format sizes");
11753
11754 ASSERT_NO_FATAL_FAILURE(InitState());
11755
11756 // Create two images of different types and try to copy between them
11757 VkImage srcImage;
11758 VkImage dstImage;
11759 VkDeviceMemory srcMem;
11760 VkDeviceMemory destMem;
11761 VkMemoryRequirements memReqs;
11762
11763 VkImageCreateInfo image_create_info = {};
11764 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11765 image_create_info.pNext = NULL;
11766 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11767 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11768 image_create_info.extent.width = 32;
11769 image_create_info.extent.height = 32;
11770 image_create_info.extent.depth = 1;
11771 image_create_info.mipLevels = 1;
11772 image_create_info.arrayLayers = 1;
11773 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11774 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11775 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11776 image_create_info.flags = 0;
11777
11778 err =
11779 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
11780 ASSERT_VK_SUCCESS(err);
11781
11782 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11783 // Introduce failure by creating second image with a different-sized format.
11784 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
11785
11786 err =
11787 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
11788 ASSERT_VK_SUCCESS(err);
11789
11790 // Allocate memory
11791 VkMemoryAllocateInfo memAlloc = {};
11792 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11793 memAlloc.pNext = NULL;
11794 memAlloc.allocationSize = 0;
11795 memAlloc.memoryTypeIndex = 0;
11796
11797 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
11798 memAlloc.allocationSize = memReqs.size;
11799 pass =
11800 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11801 ASSERT_TRUE(pass);
11802 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
11803 ASSERT_VK_SUCCESS(err);
11804
11805 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
11806 memAlloc.allocationSize = memReqs.size;
11807 pass =
11808 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11809 ASSERT_TRUE(pass);
11810 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
11811 ASSERT_VK_SUCCESS(err);
11812
11813 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11814 ASSERT_VK_SUCCESS(err);
11815 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
11816 ASSERT_VK_SUCCESS(err);
11817
11818 BeginCommandBuffer();
11819 VkImageCopy copyRegion;
11820 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11821 copyRegion.srcSubresource.mipLevel = 0;
11822 copyRegion.srcSubresource.baseArrayLayer = 0;
11823 copyRegion.srcSubresource.layerCount = 0;
11824 copyRegion.srcOffset.x = 0;
11825 copyRegion.srcOffset.y = 0;
11826 copyRegion.srcOffset.z = 0;
11827 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11828 copyRegion.dstSubresource.mipLevel = 0;
11829 copyRegion.dstSubresource.baseArrayLayer = 0;
11830 copyRegion.dstSubresource.layerCount = 0;
11831 copyRegion.dstOffset.x = 0;
11832 copyRegion.dstOffset.y = 0;
11833 copyRegion.dstOffset.z = 0;
11834 copyRegion.extent.width = 1;
11835 copyRegion.extent.height = 1;
11836 copyRegion.extent.depth = 1;
11837 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11838 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
11839 EndCommandBuffer();
11840
11841 m_errorMonitor->VerifyFound();
11842
11843 vkDestroyImage(m_device->device(), srcImage, NULL);
11844 vkDestroyImage(m_device->device(), dstImage, NULL);
11845 vkFreeMemory(m_device->device(), srcMem, NULL);
11846 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011847}
11848
Karl Schultz6addd812016-02-02 17:17:23 -070011849TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
11850 VkResult err;
11851 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011852
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011853 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011854 m_errorMonitor->SetDesiredFailureMsg(
11855 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011856 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011857
Mike Stroyana3082432015-09-25 13:39:21 -060011858 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011859
11860 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011861 VkImage srcImage;
11862 VkImage dstImage;
11863 VkDeviceMemory srcMem;
11864 VkDeviceMemory destMem;
11865 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011866
11867 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011868 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11869 image_create_info.pNext = NULL;
11870 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11871 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11872 image_create_info.extent.width = 32;
11873 image_create_info.extent.height = 32;
11874 image_create_info.extent.depth = 1;
11875 image_create_info.mipLevels = 1;
11876 image_create_info.arrayLayers = 1;
11877 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11878 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11879 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11880 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011881
Karl Schultz6addd812016-02-02 17:17:23 -070011882 err =
11883 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011884 ASSERT_VK_SUCCESS(err);
11885
Karl Schultzbdb75952016-04-19 11:36:49 -060011886 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11887
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011888 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070011889 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011890 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
11891 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011892
Karl Schultz6addd812016-02-02 17:17:23 -070011893 err =
11894 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011895 ASSERT_VK_SUCCESS(err);
11896
11897 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011898 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011899 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11900 memAlloc.pNext = NULL;
11901 memAlloc.allocationSize = 0;
11902 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011903
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011904 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011905 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011906 pass =
11907 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011908 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011909 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011910 ASSERT_VK_SUCCESS(err);
11911
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011912 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011913 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011914 pass =
11915 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011916 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011917 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011918 ASSERT_VK_SUCCESS(err);
11919
11920 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11921 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011922 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011923 ASSERT_VK_SUCCESS(err);
11924
11925 BeginCommandBuffer();
11926 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011927 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011928 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011929 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011930 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011931 copyRegion.srcOffset.x = 0;
11932 copyRegion.srcOffset.y = 0;
11933 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011934 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011935 copyRegion.dstSubresource.mipLevel = 0;
11936 copyRegion.dstSubresource.baseArrayLayer = 0;
11937 copyRegion.dstSubresource.layerCount = 0;
11938 copyRegion.dstOffset.x = 0;
11939 copyRegion.dstOffset.y = 0;
11940 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011941 copyRegion.extent.width = 1;
11942 copyRegion.extent.height = 1;
11943 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011944 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11945 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011946 EndCommandBuffer();
11947
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011948 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011949
Chia-I Wuf7458c52015-10-26 21:10:41 +080011950 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011951 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011952 vkFreeMemory(m_device->device(), srcMem, NULL);
11953 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011954}
11955
Karl Schultz6addd812016-02-02 17:17:23 -070011956TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
11957 VkResult err;
11958 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011959
Karl Schultz6addd812016-02-02 17:17:23 -070011960 m_errorMonitor->SetDesiredFailureMsg(
11961 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011962 "vkCmdResolveImage called with source sample count less than 2.");
11963
Mike Stroyana3082432015-09-25 13:39:21 -060011964 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011965
11966 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070011967 VkImage srcImage;
11968 VkImage dstImage;
11969 VkDeviceMemory srcMem;
11970 VkDeviceMemory destMem;
11971 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011972
11973 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011974 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11975 image_create_info.pNext = NULL;
11976 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11977 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11978 image_create_info.extent.width = 32;
11979 image_create_info.extent.height = 1;
11980 image_create_info.extent.depth = 1;
11981 image_create_info.mipLevels = 1;
11982 image_create_info.arrayLayers = 1;
11983 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11984 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11985 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11986 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011987
Karl Schultz6addd812016-02-02 17:17:23 -070011988 err =
11989 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011990 ASSERT_VK_SUCCESS(err);
11991
Karl Schultz6addd812016-02-02 17:17:23 -070011992 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011993
Karl Schultz6addd812016-02-02 17:17:23 -070011994 err =
11995 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011996 ASSERT_VK_SUCCESS(err);
11997
11998 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011999 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012000 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12001 memAlloc.pNext = NULL;
12002 memAlloc.allocationSize = 0;
12003 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012004
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012005 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012006 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012007 pass =
12008 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012009 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012010 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012011 ASSERT_VK_SUCCESS(err);
12012
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012013 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012014 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012015 pass =
12016 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012017 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012018 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012019 ASSERT_VK_SUCCESS(err);
12020
12021 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12022 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012023 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012024 ASSERT_VK_SUCCESS(err);
12025
12026 BeginCommandBuffer();
12027 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012028 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12029 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012030 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012031 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012032 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012033 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012034 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012035 resolveRegion.srcOffset.x = 0;
12036 resolveRegion.srcOffset.y = 0;
12037 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012038 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012039 resolveRegion.dstSubresource.mipLevel = 0;
12040 resolveRegion.dstSubresource.baseArrayLayer = 0;
12041 resolveRegion.dstSubresource.layerCount = 0;
12042 resolveRegion.dstOffset.x = 0;
12043 resolveRegion.dstOffset.y = 0;
12044 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012045 resolveRegion.extent.width = 1;
12046 resolveRegion.extent.height = 1;
12047 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012048 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12049 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012050 EndCommandBuffer();
12051
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012052 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012053
Chia-I Wuf7458c52015-10-26 21:10:41 +080012054 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012055 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012056 vkFreeMemory(m_device->device(), srcMem, NULL);
12057 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012058}
12059
Karl Schultz6addd812016-02-02 17:17:23 -070012060TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
12061 VkResult err;
12062 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060012063
Karl Schultz6addd812016-02-02 17:17:23 -070012064 m_errorMonitor->SetDesiredFailureMsg(
12065 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012066 "vkCmdResolveImage called with dest sample count greater than 1.");
12067
Mike Stroyana3082432015-09-25 13:39:21 -060012068 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060012069
Chris Forbesa7530692016-05-08 12:35:39 +120012070 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070012071 VkImage srcImage;
12072 VkImage dstImage;
12073 VkDeviceMemory srcMem;
12074 VkDeviceMemory destMem;
12075 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012076
12077 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012078 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12079 image_create_info.pNext = NULL;
12080 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12081 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12082 image_create_info.extent.width = 32;
12083 image_create_info.extent.height = 1;
12084 image_create_info.extent.depth = 1;
12085 image_create_info.mipLevels = 1;
12086 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120012087 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070012088 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12089 // Note: Some implementations expect color attachment usage for any
12090 // multisample surface
12091 image_create_info.usage =
12092 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12093 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012094
Karl Schultz6addd812016-02-02 17:17:23 -070012095 err =
12096 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012097 ASSERT_VK_SUCCESS(err);
12098
Karl Schultz6addd812016-02-02 17:17:23 -070012099 // Note: Some implementations expect color attachment usage for any
12100 // multisample surface
12101 image_create_info.usage =
12102 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012103
Karl Schultz6addd812016-02-02 17:17:23 -070012104 err =
12105 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012106 ASSERT_VK_SUCCESS(err);
12107
12108 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012109 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012110 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12111 memAlloc.pNext = NULL;
12112 memAlloc.allocationSize = 0;
12113 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012114
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012115 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012116 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012117 pass =
12118 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012119 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012120 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012121 ASSERT_VK_SUCCESS(err);
12122
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012123 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012124 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012125 pass =
12126 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012127 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012128 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012129 ASSERT_VK_SUCCESS(err);
12130
12131 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12132 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012133 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012134 ASSERT_VK_SUCCESS(err);
12135
12136 BeginCommandBuffer();
12137 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012138 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12139 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012140 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012141 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012142 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012143 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012144 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012145 resolveRegion.srcOffset.x = 0;
12146 resolveRegion.srcOffset.y = 0;
12147 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012148 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012149 resolveRegion.dstSubresource.mipLevel = 0;
12150 resolveRegion.dstSubresource.baseArrayLayer = 0;
12151 resolveRegion.dstSubresource.layerCount = 0;
12152 resolveRegion.dstOffset.x = 0;
12153 resolveRegion.dstOffset.y = 0;
12154 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012155 resolveRegion.extent.width = 1;
12156 resolveRegion.extent.height = 1;
12157 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012158 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12159 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012160 EndCommandBuffer();
12161
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012162 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012163
Chia-I Wuf7458c52015-10-26 21:10:41 +080012164 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012165 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012166 vkFreeMemory(m_device->device(), srcMem, NULL);
12167 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012168}
12169
Karl Schultz6addd812016-02-02 17:17:23 -070012170TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
12171 VkResult err;
12172 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060012173
Karl Schultz6addd812016-02-02 17:17:23 -070012174 m_errorMonitor->SetDesiredFailureMsg(
12175 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012176 "vkCmdResolveImage called with unmatched source and dest formats.");
12177
Mike Stroyana3082432015-09-25 13:39:21 -060012178 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060012179
12180 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070012181 VkImage srcImage;
12182 VkImage dstImage;
12183 VkDeviceMemory srcMem;
12184 VkDeviceMemory destMem;
12185 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012186
12187 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012188 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12189 image_create_info.pNext = NULL;
12190 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12191 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12192 image_create_info.extent.width = 32;
12193 image_create_info.extent.height = 1;
12194 image_create_info.extent.depth = 1;
12195 image_create_info.mipLevels = 1;
12196 image_create_info.arrayLayers = 1;
12197 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
12198 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12199 // Note: Some implementations expect color attachment usage for any
12200 // multisample surface
12201 image_create_info.usage =
12202 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12203 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012204
Karl Schultz6addd812016-02-02 17:17:23 -070012205 err =
12206 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012207 ASSERT_VK_SUCCESS(err);
12208
Karl Schultz6addd812016-02-02 17:17:23 -070012209 // Set format to something other than source image
12210 image_create_info.format = VK_FORMAT_R32_SFLOAT;
12211 // Note: Some implementations expect color attachment usage for any
12212 // multisample surface
12213 image_create_info.usage =
12214 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12215 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012216
Karl Schultz6addd812016-02-02 17:17:23 -070012217 err =
12218 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012219 ASSERT_VK_SUCCESS(err);
12220
12221 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012222 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012223 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12224 memAlloc.pNext = NULL;
12225 memAlloc.allocationSize = 0;
12226 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012227
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012228 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012229 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012230 pass =
12231 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012232 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012233 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012234 ASSERT_VK_SUCCESS(err);
12235
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012236 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012237 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012238 pass =
12239 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012240 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012241 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012242 ASSERT_VK_SUCCESS(err);
12243
12244 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12245 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012246 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012247 ASSERT_VK_SUCCESS(err);
12248
12249 BeginCommandBuffer();
12250 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012251 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12252 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012253 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012254 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012255 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012256 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012257 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012258 resolveRegion.srcOffset.x = 0;
12259 resolveRegion.srcOffset.y = 0;
12260 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012261 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012262 resolveRegion.dstSubresource.mipLevel = 0;
12263 resolveRegion.dstSubresource.baseArrayLayer = 0;
12264 resolveRegion.dstSubresource.layerCount = 0;
12265 resolveRegion.dstOffset.x = 0;
12266 resolveRegion.dstOffset.y = 0;
12267 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012268 resolveRegion.extent.width = 1;
12269 resolveRegion.extent.height = 1;
12270 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012271 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12272 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012273 EndCommandBuffer();
12274
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012275 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012276
Chia-I Wuf7458c52015-10-26 21:10:41 +080012277 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012278 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012279 vkFreeMemory(m_device->device(), srcMem, NULL);
12280 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012281}
12282
Karl Schultz6addd812016-02-02 17:17:23 -070012283TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
12284 VkResult err;
12285 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060012286
Karl Schultz6addd812016-02-02 17:17:23 -070012287 m_errorMonitor->SetDesiredFailureMsg(
12288 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012289 "vkCmdResolveImage called with unmatched source and dest image types.");
12290
Mike Stroyana3082432015-09-25 13:39:21 -060012291 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060012292
12293 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070012294 VkImage srcImage;
12295 VkImage dstImage;
12296 VkDeviceMemory srcMem;
12297 VkDeviceMemory destMem;
12298 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012299
12300 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012301 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12302 image_create_info.pNext = NULL;
12303 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12304 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12305 image_create_info.extent.width = 32;
12306 image_create_info.extent.height = 1;
12307 image_create_info.extent.depth = 1;
12308 image_create_info.mipLevels = 1;
12309 image_create_info.arrayLayers = 1;
12310 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
12311 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12312 // Note: Some implementations expect color attachment usage for any
12313 // multisample surface
12314 image_create_info.usage =
12315 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12316 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012317
Karl Schultz6addd812016-02-02 17:17:23 -070012318 err =
12319 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012320 ASSERT_VK_SUCCESS(err);
12321
Karl Schultz6addd812016-02-02 17:17:23 -070012322 image_create_info.imageType = VK_IMAGE_TYPE_1D;
12323 // Note: Some implementations expect color attachment usage for any
12324 // multisample surface
12325 image_create_info.usage =
12326 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12327 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012328
Karl Schultz6addd812016-02-02 17:17:23 -070012329 err =
12330 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012331 ASSERT_VK_SUCCESS(err);
12332
12333 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012334 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012335 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12336 memAlloc.pNext = NULL;
12337 memAlloc.allocationSize = 0;
12338 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012339
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012340 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012341 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012342 pass =
12343 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012344 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012345 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012346 ASSERT_VK_SUCCESS(err);
12347
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012348 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012349 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012350 pass =
12351 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012352 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012353 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012354 ASSERT_VK_SUCCESS(err);
12355
12356 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12357 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012358 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012359 ASSERT_VK_SUCCESS(err);
12360
12361 BeginCommandBuffer();
12362 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012363 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12364 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012365 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012366 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012367 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012368 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012369 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012370 resolveRegion.srcOffset.x = 0;
12371 resolveRegion.srcOffset.y = 0;
12372 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012373 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012374 resolveRegion.dstSubresource.mipLevel = 0;
12375 resolveRegion.dstSubresource.baseArrayLayer = 0;
12376 resolveRegion.dstSubresource.layerCount = 0;
12377 resolveRegion.dstOffset.x = 0;
12378 resolveRegion.dstOffset.y = 0;
12379 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012380 resolveRegion.extent.width = 1;
12381 resolveRegion.extent.height = 1;
12382 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012383 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12384 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012385 EndCommandBuffer();
12386
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012387 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012388
Chia-I Wuf7458c52015-10-26 21:10:41 +080012389 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012390 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012391 vkFreeMemory(m_device->device(), srcMem, NULL);
12392 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012393}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012394
Karl Schultz6addd812016-02-02 17:17:23 -070012395TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012396 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070012397 // to using a DS format, then cause it to hit error due to COLOR_BIT not
12398 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012399 // The image format check comes 2nd in validation so we trigger it first,
12400 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070012401 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012402
Karl Schultz6addd812016-02-02 17:17:23 -070012403 m_errorMonitor->SetDesiredFailureMsg(
12404 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012405 "Combination depth/stencil image formats can have only the ");
12406
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012407 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012408
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012409 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012410 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12411 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012412
12413 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012414 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12415 ds_pool_ci.pNext = NULL;
12416 ds_pool_ci.maxSets = 1;
12417 ds_pool_ci.poolSizeCount = 1;
12418 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012419
12420 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -070012421 err =
12422 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012423 ASSERT_VK_SUCCESS(err);
12424
12425 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012426 dsl_binding.binding = 0;
12427 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12428 dsl_binding.descriptorCount = 1;
12429 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12430 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012431
12432 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012433 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12434 ds_layout_ci.pNext = NULL;
12435 ds_layout_ci.bindingCount = 1;
12436 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012437 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012438 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
12439 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012440 ASSERT_VK_SUCCESS(err);
12441
12442 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012443 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012444 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012445 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012446 alloc_info.descriptorPool = ds_pool;
12447 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012448 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
12449 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012450 ASSERT_VK_SUCCESS(err);
12451
Karl Schultz6addd812016-02-02 17:17:23 -070012452 VkImage image_bad;
12453 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012454 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060012455 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012456 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070012457 const int32_t tex_width = 32;
12458 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012459
12460 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012461 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12462 image_create_info.pNext = NULL;
12463 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12464 image_create_info.format = tex_format_bad;
12465 image_create_info.extent.width = tex_width;
12466 image_create_info.extent.height = tex_height;
12467 image_create_info.extent.depth = 1;
12468 image_create_info.mipLevels = 1;
12469 image_create_info.arrayLayers = 1;
12470 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12471 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12472 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
12473 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12474 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012475
Karl Schultz6addd812016-02-02 17:17:23 -070012476 err =
12477 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012478 ASSERT_VK_SUCCESS(err);
12479 image_create_info.format = tex_format_good;
Karl Schultz6addd812016-02-02 17:17:23 -070012480 image_create_info.usage =
12481 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12482 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
12483 &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012484 ASSERT_VK_SUCCESS(err);
12485
12486 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012487 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12488 image_view_create_info.image = image_bad;
12489 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
12490 image_view_create_info.format = tex_format_bad;
12491 image_view_create_info.subresourceRange.baseArrayLayer = 0;
12492 image_view_create_info.subresourceRange.baseMipLevel = 0;
12493 image_view_create_info.subresourceRange.layerCount = 1;
12494 image_view_create_info.subresourceRange.levelCount = 1;
12495 image_view_create_info.subresourceRange.aspectMask =
12496 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012497
12498 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070012499 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
12500 &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012501
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012502 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012503
Chia-I Wuf7458c52015-10-26 21:10:41 +080012504 vkDestroyImage(m_device->device(), image_bad, NULL);
12505 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012506 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12507 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012508}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012509
12510TEST_F(VkLayerTest, ClearImageErrors) {
12511 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
12512 "ClearDepthStencilImage with a color image.");
12513
12514 ASSERT_NO_FATAL_FAILURE(InitState());
12515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12516
12517 // Renderpass is started here so end it as Clear cmds can't be in renderpass
12518 BeginCommandBuffer();
12519 m_commandBuffer->EndRenderPass();
12520
12521 // Color image
12522 VkClearColorValue clear_color;
12523 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
12524 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
12525 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
12526 const int32_t img_width = 32;
12527 const int32_t img_height = 32;
12528 VkImageCreateInfo image_create_info = {};
12529 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12530 image_create_info.pNext = NULL;
12531 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12532 image_create_info.format = color_format;
12533 image_create_info.extent.width = img_width;
12534 image_create_info.extent.height = img_height;
12535 image_create_info.extent.depth = 1;
12536 image_create_info.mipLevels = 1;
12537 image_create_info.arrayLayers = 1;
12538 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12539 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
12540 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
12541
12542 vk_testing::Image color_image;
12543 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info,
12544 reqs);
12545
12546 const VkImageSubresourceRange color_range =
12547 vk_testing::Image::subresource_range(image_create_info,
12548 VK_IMAGE_ASPECT_COLOR_BIT);
12549
12550 // Depth/Stencil image
12551 VkClearDepthStencilValue clear_value = {0};
12552 reqs = 0; // don't need HOST_VISIBLE DS image
12553 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
12554 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
12555 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
12556 ds_image_create_info.extent.width = 64;
12557 ds_image_create_info.extent.height = 64;
12558 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12559 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12560
12561 vk_testing::Image ds_image;
12562 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info,
12563 reqs);
12564
12565 const VkImageSubresourceRange ds_range =
12566 vk_testing::Image::subresource_range(ds_image_create_info,
12567 VK_IMAGE_ASPECT_DEPTH_BIT);
12568
12569 m_errorMonitor->SetDesiredFailureMsg(
12570 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12571 "vkCmdClearColorImage called with depth/stencil image.");
12572
12573 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12574 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12575 &color_range);
12576
12577 m_errorMonitor->VerifyFound();
12578
Tony Barbour26434b92016-06-02 09:43:50 -060012579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12580 "vkCmdClearColorImage called with "
12581 "image created without "
12582 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
12583
12584 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12585 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12586 &color_range);
12587
12588 m_errorMonitor->VerifyFound();
12589
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012590 // Call CmdClearDepthStencilImage with color image
12591 m_errorMonitor->SetDesiredFailureMsg(
12592 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12593 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
12594
12595 vkCmdClearDepthStencilImage(
12596 m_commandBuffer->GetBufferHandle(), color_image.handle(),
12597 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
12598 &ds_range);
12599
12600 m_errorMonitor->VerifyFound();
12601}
Tobin Ehliscde08892015-09-22 10:11:37 -060012602#endif // IMAGE_TESTS
12603
Tony Barbour300a6082015-04-07 13:44:53 -060012604int main(int argc, char **argv) {
12605 int result;
12606
Cody Northrop8e54a402016-03-08 22:25:52 -070012607#ifdef ANDROID
12608 int vulkanSupport = InitVulkan();
12609 if (vulkanSupport == 0)
12610 return 1;
12611#endif
12612
Tony Barbour300a6082015-04-07 13:44:53 -060012613 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060012614 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060012615
12616 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
12617
12618 result = RUN_ALL_TESTS();
12619
Tony Barbour6918cd52015-04-09 12:58:51 -060012620 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060012621 return result;
12622}