blob: 31faafac32d9e4cf6d381e7fe04df53e9c36dd00 [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 Lobodzinski3780e142015-05-14 15:08:13 -050066} BsoFailSelect;
67
68struct vktriangle_vs_uniform {
69 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070070 float mvp[4][4];
71 float position[3][4];
72 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050073};
74
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050075static const char bindStateVertShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120076 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070077 "vec2 vertices[3];\n"
78 "out gl_PerVertex {\n"
79 " vec4 gl_Position;\n"
80 "};\n"
81 "void main() {\n"
82 " vertices[0] = vec2(-1.0, -1.0);\n"
83 " vertices[1] = vec2( 1.0, -1.0);\n"
84 " vertices[2] = vec2( 0.0, 1.0);\n"
85 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
86 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050087
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050088static const char bindStateFragShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120089 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070090 "\n"
91 "layout(location = 0) out vec4 uFragColor;\n"
92 "void main(){\n"
93 " uFragColor = vec4(0,1,0,1);\n"
94 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050095
Karl Schultz6addd812016-02-02 17:17:23 -070096static VKAPI_ATTR VkBool32 VKAPI_CALL
97myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
98 uint64_t srcObject, size_t location, int32_t msgCode,
99 const char *pLayerPrefix, const char *pMsg, void *pUserData);
Tony Barbour300a6082015-04-07 13:44:53 -0600100
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600101// ********************************************************
102// ErrorMonitor Usage:
103//
104// Call SetDesiredFailureMsg with a string to be compared against all
105// encountered log messages. Passing NULL will match all log messages.
106// logMsg will return true for skipCall only if msg is matched or NULL.
107//
108// Call DesiredMsgFound to determine if the desired failure message
109// was encountered.
110
Tony Barbour300a6082015-04-07 13:44:53 -0600111class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700112 public:
113 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600114 test_platform_thread_create_mutex(&m_mutex);
115 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700116 m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700117 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600118 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600119 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600120
Dustin Graves48458142016-04-29 16:11:55 -0600121 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
122
Karl Schultz6addd812016-02-02 17:17:23 -0700123 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200124 // also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600125 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600126 m_failureMsg.clear();
127 m_otherMsgs.clear();
128 m_desiredMsg = msgString;
Karl Schultz6addd812016-02-02 17:17:23 -0700129 m_msgFound = VK_FALSE;
130 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600131 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600132 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600133
Karl Schultz6addd812016-02-02 17:17:23 -0700134 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600135 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600136 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600137 if (m_bailout != NULL) {
138 *m_bailout = true;
139 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600140 string errorString(msgString);
141 if (msgFlags & m_msgFlags) {
142 if (errorString.find(m_desiredMsg) != string::npos) {
Chris Forbesc7b8ad72016-04-04 18:50:38 +1200143 if (m_msgFound) { /* if multiple matches, don't lose all but the last! */
144 m_otherMsgs.push_back(m_failureMsg);
145 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600146 m_failureMsg = errorString;
Karl Schultz6addd812016-02-02 17:17:23 -0700147 m_msgFound = VK_TRUE;
148 result = VK_TRUE;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600149 } else {
150 m_otherMsgs.push_back(errorString);
151 }
152 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600153 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600154 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600155 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600156
Karl Schultz6addd812016-02-02 17:17:23 -0700157 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600158
Karl Schultz6addd812016-02-02 17:17:23 -0700159 string GetFailureMsg(void) { return m_failureMsg; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600160
Karl Schultz6addd812016-02-02 17:17:23 -0700161 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600162
Karl Schultz6addd812016-02-02 17:17:23 -0700163 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600164
Karl Schultz6addd812016-02-02 17:17:23 -0700165 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 vector<string> otherMsgs = GetOtherFailureMsgs();
167 cout << "Other error messages logged for this test were:" << endl;
168 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
169 cout << " " << *iter << endl;
170 }
171 }
172
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200173 /* helpers */
174
175 void ExpectSuccess() {
176 // match anything
177 SetDesiredFailureMsg(~0u, "");
178 }
179
180 void VerifyFound() {
181 // Not seeing the desired message is a failure. /Before/ throwing, dump
182 // any other messages.
183 if (!DesiredMsgFound()) {
184 DumpFailureMsgs();
185 FAIL() << "Did not receive expected error '" << m_desiredMsg << "'";
186 }
187 }
188
189 void VerifyNotFound() {
190 // ExpectSuccess() configured us to match anything. Any error is a
191 // failure.
192 if (DesiredMsgFound()) {
193 DumpFailureMsgs();
194 FAIL() << "Expected to succeed but got error: " << GetFailureMsg();
195 }
196 }
197
Karl Schultz6addd812016-02-02 17:17:23 -0700198 private:
199 VkFlags m_msgFlags;
200 string m_desiredMsg;
201 string m_failureMsg;
202 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600203 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700204 bool *m_bailout;
205 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600206};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500207
Karl Schultz6addd812016-02-02 17:17:23 -0700208static VKAPI_ATTR VkBool32 VKAPI_CALL
209myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
210 uint64_t srcObject, size_t location, int32_t msgCode,
211 const char *pLayerPrefix, const char *pMsg, void *pUserData) {
212 if (msgFlags &
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700213 (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
Karl Schultz6addd812016-02-02 17:17:23 -0700214 VK_DEBUG_REPORT_ERROR_BIT_EXT)) {
Tony Barbour0b4d9562015-04-09 10:48:04 -0600215 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600216 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600217 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600218 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600219}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500220
Karl Schultz6addd812016-02-02 17:17:23 -0700221class VkLayerTest : public VkRenderFramework {
222 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800223 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
224 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700225 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText,
226 BsoFailSelect failMask);
227 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
228 VkPipelineObj &pipelineobj,
229 VkDescriptorSetObj &descriptorSet,
230 BsoFailSelect failMask);
231 void GenericDrawPreparation(VkPipelineObj &pipelineobj,
232 VkDescriptorSetObj &descriptorSet,
233 BsoFailSelect failMask) {
234 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet,
235 failMask);
236 }
Tony Barbour300a6082015-04-07 13:44:53 -0600237
Tony Barbourfe3351b2015-07-28 10:17:20 -0600238 /* Convenience functions that use built-in command buffer */
Karl Schultz6addd812016-02-02 17:17:23 -0700239 VkResult BeginCommandBuffer() {
240 return BeginCommandBuffer(*m_commandBuffer);
241 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800242 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Karl Schultz6addd812016-02-02 17:17:23 -0700243 void Draw(uint32_t vertexCount, uint32_t instanceCount,
244 uint32_t firstVertex, uint32_t firstInstance) {
245 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex,
246 firstInstance);
247 }
248 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount,
249 uint32_t firstIndex, int32_t vertexOffset,
250 uint32_t firstInstance) {
251 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex,
252 vertexOffset, firstInstance);
253 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800254 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
Karl Schultz6addd812016-02-02 17:17:23 -0700255 void QueueCommandBuffer(const VkFence &fence) {
256 m_commandBuffer->QueueCommandBuffer(fence);
257 }
258 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer,
259 VkDeviceSize offset, uint32_t binding) {
260 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
261 }
262 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
263 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
264 }
265
266 protected:
267 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600268 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600269
270 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600271 std::vector<const char *> instance_layer_names;
272 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600273 std::vector<const char *> instance_extension_names;
274 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600275
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700276 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600277 /*
278 * Since CreateDbgMsgCallback is an instance level extension call
279 * any extension / layer that utilizes that feature also needs
280 * to be enabled at create instance time.
281 */
Karl Schultz6addd812016-02-02 17:17:23 -0700282 // Use Threading layer first to protect others from
283 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700284 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600285 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800286 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700287 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800288 instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
289 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600290 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700291 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600292
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700293 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600294 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800295 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700296 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800297 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
298 device_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600299 device_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700300 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Tony Barbour300a6082015-04-07 13:44:53 -0600301
Ian Elliott2c1daf52016-05-12 09:41:46 -0600302 if (m_enableWSI) {
303 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
304 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
305#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
306#if defined(VK_USE_PLATFORM_ANDROID_KHR)
307 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
308#endif // VK_USE_PLATFORM_ANDROID_KHR
309#if defined(VK_USE_PLATFORM_MIR_KHR)
310 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
311#endif // VK_USE_PLATFORM_MIR_KHR
312#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
313 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
314#endif // VK_USE_PLATFORM_WAYLAND_KHR
315#if defined(VK_USE_PLATFORM_WIN32_KHR)
316 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
317#endif // VK_USE_PLATFORM_WIN32_KHR
318#endif // NEED_TO_TEST_THIS_ON_PLATFORM
319#if defined(VK_USE_PLATFORM_XCB_KHR)
320 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
321#elif defined(VK_USE_PLATFORM_XLIB_KHR)
322 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
323#endif // VK_USE_PLATFORM_XLIB_KHR
324 }
325
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600326 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600327 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800328 this->app_info.pApplicationName = "layer_tests";
329 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600330 this->app_info.pEngineName = "unittest";
331 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600332 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600333
Tony Barbour15524c32015-04-29 17:34:29 -0600334 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600335 InitFramework(instance_layer_names, device_layer_names,
336 instance_extension_names, device_extension_names,
337 myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600338 }
339
340 virtual void TearDown() {
341 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600342 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600343 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600344 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600345
346 VkLayerTest() {
347 m_enableWSI = false;
348 }
Tony Barbour300a6082015-04-07 13:44:53 -0600349};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500350
Karl Schultz6addd812016-02-02 17:17:23 -0700351VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600352 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600353
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800354 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600355
356 /*
357 * For render test all drawing happens in a single render pass
358 * on a single command buffer.
359 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200360 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800361 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600362 }
363
364 return result;
365}
366
Karl Schultz6addd812016-02-02 17:17:23 -0700367VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600368 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600369
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200370 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800371 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200372 }
Tony Barbour300a6082015-04-07 13:44:53 -0600373
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800374 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600375
376 return result;
377}
378
Karl Schultz6addd812016-02-02 17:17:23 -0700379void VkLayerTest::VKTriangleTest(const char *vertShaderText,
380 const char *fragShaderText,
381 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500382 // Create identity matrix
383 int i;
384 struct vktriangle_vs_uniform data;
385
386 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700387 glm::mat4 View = glm::mat4(1.0f);
388 glm::mat4 Model = glm::mat4(1.0f);
389 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500390 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700391 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500392
393 memcpy(&data.mvp, &MVP[0][0], matrixSize);
394
Karl Schultz6addd812016-02-02 17:17:23 -0700395 static const Vertex tri_data[] = {
396 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)},
397 {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)},
398 {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500399 };
400
Karl Schultz6addd812016-02-02 17:17:23 -0700401 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500402 data.position[i][0] = tri_data[i].posX;
403 data.position[i][1] = tri_data[i].posY;
404 data.position[i][2] = tri_data[i].posZ;
405 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700406 data.color[i][0] = tri_data[i].r;
407 data.color[i][1] = tri_data[i].g;
408 data.color[i][2] = tri_data[i].b;
409 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500410 }
411
412 ASSERT_NO_FATAL_FAILURE(InitState());
413 ASSERT_NO_FATAL_FAILURE(InitViewport());
414
Karl Schultz6addd812016-02-02 17:17:23 -0700415 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float),
416 (const void *)&data);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500417
Karl Schultz6addd812016-02-02 17:17:23 -0700418 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
419 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
420 this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500421
422 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800423 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500424 pipelineobj.AddShader(&vs);
425 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600426 if (failMask & BsoFailLineWidth) {
427 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600428 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
429 ia_state.sType =
430 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
431 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
432 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600433 }
434 if (failMask & BsoFailDepthBias) {
435 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600436 VkPipelineRasterizationStateCreateInfo rs_state = {};
437 rs_state.sType =
438 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
439 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600440 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600441 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600442 }
Karl Schultz6addd812016-02-02 17:17:23 -0700443 // Viewport and scissors must stay in synch or other errors will occur than
444 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600445 if (failMask & BsoFailViewport) {
446 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600447 m_viewports.clear();
448 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600449 }
450 if (failMask & BsoFailScissor) {
451 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600452 m_scissors.clear();
453 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600454 }
455 if (failMask & BsoFailBlend) {
456 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600457 VkPipelineColorBlendAttachmentState att_state = {};
458 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
459 att_state.blendEnable = VK_TRUE;
460 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600461 }
462 if (failMask & BsoFailDepthBounds) {
463 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
464 }
465 if (failMask & BsoFailStencilReadMask) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
467 }
468 if (failMask & BsoFailStencilWriteMask) {
469 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
470 }
471 if (failMask & BsoFailStencilReference) {
472 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
473 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500474
475 VkDescriptorSetObj descriptorSet(m_device);
Karl Schultz6addd812016-02-02 17:17:23 -0700476 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
477 constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500478
479 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600480 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500481
Tony Barbourfe3351b2015-07-28 10:17:20 -0600482 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500483
484 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600485 Draw(3, 1, 0, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500486
487 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600488 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500489
Tony Barbourfe3351b2015-07-28 10:17:20 -0600490 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500491}
492
Karl Schultz6addd812016-02-02 17:17:23 -0700493void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
494 VkPipelineObj &pipelineobj,
495 VkDescriptorSetObj &descriptorSet,
496 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500497 if (m_depthStencil->Initialized()) {
Karl Schultz6addd812016-02-02 17:17:23 -0700498 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
499 m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500 } else {
Karl Schultz6addd812016-02-02 17:17:23 -0700501 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
502 m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503 }
504
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800505 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700506 // Make sure depthWriteEnable is set so that Depth fail test will work
507 // correctly
508 // Make sure stencilTestEnable is set so that Stencil fail test will work
509 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600510 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800511 stencil.failOp = VK_STENCIL_OP_KEEP;
512 stencil.passOp = VK_STENCIL_OP_KEEP;
513 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
514 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600515
516 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
517 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600518 ds_ci.pNext = NULL;
519 ds_ci.depthTestEnable = VK_FALSE;
520 ds_ci.depthWriteEnable = VK_TRUE;
521 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
522 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600523 if (failMask & BsoFailDepthBounds) {
524 ds_ci.depthBoundsTestEnable = VK_TRUE;
525 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600526 ds_ci.stencilTestEnable = VK_TRUE;
527 ds_ci.front = stencil;
528 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600529
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600530 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600531 pipelineobj.SetViewport(m_viewports);
532 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800533 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700534 VkResult err = pipelineobj.CreateVKPipeline(
535 descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600536 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800537 commandBuffer->BindPipeline(pipelineobj);
538 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500539}
540
Ian Elliott2c1daf52016-05-12 09:41:46 -0600541class VkWsiEnabledLayerTest : public VkLayerTest {
542 public:
543protected:
544 VkWsiEnabledLayerTest() {
545 m_enableWSI = true;
546 }
547};
548
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500549// ********************************************************************************************************************
550// ********************************************************************************************************************
551// ********************************************************************************************************************
552// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600553#if PARAMETER_VALIDATION_TESTS
554TEST_F(VkLayerTest, RequiredParameter) {
555 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
556 "pointer, array, and array count parameters");
557
558 ASSERT_NO_FATAL_FAILURE(InitState());
559
560 m_errorMonitor->SetDesiredFailureMsg(
561 VK_DEBUG_REPORT_ERROR_BIT_EXT,
562 "required parameter pFeatures specified as NULL");
563 // Specify NULL for a pointer to a handle
564 // Expected to trigger an error with
565 // parameter_validation::validate_required_pointer
566 vkGetPhysicalDeviceFeatures(gpu(), NULL);
567 m_errorMonitor->VerifyFound();
568
569 m_errorMonitor->SetDesiredFailureMsg(
570 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600571 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600572 // Specify NULL for pointer to array count
573 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600574 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600575 m_errorMonitor->VerifyFound();
576
577 m_errorMonitor->SetDesiredFailureMsg(
578 VK_DEBUG_REPORT_ERROR_BIT_EXT,
579 "parameter viewportCount must be greater than 0");
580 // Specify 0 for a required array count
581 // Expected to trigger an error with parameter_validation::validate_array
582 VkViewport view_port = {};
583 m_commandBuffer->SetViewport(0, 0, &view_port);
584 m_errorMonitor->VerifyFound();
585
586 m_errorMonitor->SetDesiredFailureMsg(
587 VK_DEBUG_REPORT_ERROR_BIT_EXT,
588 "required parameter pViewports specified as NULL");
589 // Specify NULL for a required array
590 // Expected to trigger an error with parameter_validation::validate_array
591 m_commandBuffer->SetViewport(0, 1, NULL);
592 m_errorMonitor->VerifyFound();
593
594 m_errorMonitor->SetDesiredFailureMsg(
595 VK_DEBUG_REPORT_ERROR_BIT_EXT,
596 "required parameter memory specified as VK_NULL_HANDLE");
597 // Specify VK_NULL_HANDLE for a required handle
598 // Expected to trigger an error with
599 // parameter_validation::validate_required_handle
600 vkUnmapMemory(device(), VK_NULL_HANDLE);
601 m_errorMonitor->VerifyFound();
602
603 m_errorMonitor->SetDesiredFailureMsg(
604 VK_DEBUG_REPORT_ERROR_BIT_EXT,
605 "required parameter pFences[0] specified as VK_NULL_HANDLE");
606 // Specify VK_NULL_HANDLE for a required handle array entry
607 // Expected to trigger an error with
608 // parameter_validation::validate_required_handle_array
609 VkFence fence = VK_NULL_HANDLE;
610 vkResetFences(device(), 1, &fence);
611 m_errorMonitor->VerifyFound();
612
613 m_errorMonitor->SetDesiredFailureMsg(
614 VK_DEBUG_REPORT_ERROR_BIT_EXT,
615 "required parameter pAllocateInfo specified as NULL");
616 // Specify NULL for a required struct pointer
617 // Expected to trigger an error with
618 // parameter_validation::validate_struct_type
619 VkDeviceMemory memory = VK_NULL_HANDLE;
620 vkAllocateMemory(device(), NULL, NULL, &memory);
621 m_errorMonitor->VerifyFound();
622
623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
624 "value of faceMask must not be 0");
625 // Specify 0 for a required VkFlags parameter
626 // Expected to trigger an error with parameter_validation::validate_flags
627 m_commandBuffer->SetStencilReference(0, 0);
628 m_errorMonitor->VerifyFound();
629
630 m_errorMonitor->SetDesiredFailureMsg(
631 VK_DEBUG_REPORT_ERROR_BIT_EXT,
632 "value of pSubmits[i].pWaitDstStageMask[0] must not be 0");
633 // Specify 0 for a required VkFlags array entry
634 // Expected to trigger an error with
635 // parameter_validation::validate_flags_array
636 VkSemaphore semaphore = VK_NULL_HANDLE;
637 VkPipelineStageFlags stageFlags = 0;
638 VkSubmitInfo submitInfo = {};
639 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
640 submitInfo.waitSemaphoreCount = 1;
641 submitInfo.pWaitSemaphores = &semaphore;
642 submitInfo.pWaitDstStageMask = &stageFlags;
643 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
644 m_errorMonitor->VerifyFound();
645}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600646
Dustin Gravesfce74c02016-05-10 11:42:58 -0600647TEST_F(VkLayerTest, ReservedParameter) {
648 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
649
650 ASSERT_NO_FATAL_FAILURE(InitState());
651
652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
653 " must be 0");
654 // Specify 0 for a reserved VkFlags parameter
655 // Expected to trigger an error with
656 // parameter_validation::validate_reserved_flags
657 VkEvent event_handle = VK_NULL_HANDLE;
658 VkEventCreateInfo event_info = {};
659 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
660 event_info.flags = 1;
661 vkCreateEvent(device(), &event_info, NULL, &event_handle);
662 m_errorMonitor->VerifyFound();
663}
664
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600665TEST_F(VkLayerTest, InvalidStructSType) {
666 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
667 "structure's sType field");
668
669 ASSERT_NO_FATAL_FAILURE(InitState());
670
671 m_errorMonitor->SetDesiredFailureMsg(
672 VK_DEBUG_REPORT_ERROR_BIT_EXT,
673 "parameter pAllocateInfo->sType must be");
674 // Zero struct memory, effectively setting sType to
675 // VK_STRUCTURE_TYPE_APPLICATION_INFO
676 // Expected to trigger an error with
677 // parameter_validation::validate_struct_type
678 VkMemoryAllocateInfo alloc_info = {};
679 VkDeviceMemory memory = VK_NULL_HANDLE;
680 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
681 m_errorMonitor->VerifyFound();
682
683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
684 "parameter pSubmits[0].sType must be");
685 // Zero struct memory, effectively setting sType to
686 // VK_STRUCTURE_TYPE_APPLICATION_INFO
687 // Expected to trigger an error with
688 // parameter_validation::validate_struct_type_array
689 VkSubmitInfo submit_info = {};
690 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
691 m_errorMonitor->VerifyFound();
692}
693
694TEST_F(VkLayerTest, InvalidStructPNext) {
695 TEST_DESCRIPTION(
696 "Specify an invalid value for a Vulkan structure's pNext field");
697
698 ASSERT_NO_FATAL_FAILURE(InitState());
699
700 m_errorMonitor->SetDesiredFailureMsg(
701 VK_DEBUG_REPORT_ERROR_BIT_EXT,
702 "value of pAllocateInfo->pNext must be NULL");
703 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
704 // NULL
705 // Expected to trigger an error with
706 // parameter_validation::validate_struct_pnext
707 VkDeviceMemory memory = VK_NULL_HANDLE;
708 // Zero-initialization will provide the correct sType
709 VkApplicationInfo app_info = {};
Dustin Graves47b6cba2016-05-10 17:34:38 -0600710 VkMemoryAllocateInfo memory_alloc_info = {};
711 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
712 memory_alloc_info.pNext = &app_info;
713 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600714 m_errorMonitor->VerifyFound();
715
Dustin Graves47b6cba2016-05-10 17:34:38 -0600716 m_errorMonitor->SetDesiredFailureMsg(
717 VK_DEBUG_REPORT_ERROR_BIT_EXT,
718 " chain includes a structure with unexpected VkStructureType ");
719 // Set VkGraphicsPipelineCreateInfo::VkPipelineRasterizationStateCreateInfo::pNext to an invalid structure, when pNext is allowed to be a non-NULL value
720 // Expected to trigger an error with
721 // parameter_validation::validate_struct_pnext
722 VkDescriptorPoolSize ds_type_count = {};
723 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
724 ds_type_count.descriptorCount = 1;
725
726 VkDescriptorPoolCreateInfo ds_pool_ci = {};
727 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
728 ds_pool_ci.pNext = NULL;
729 ds_pool_ci.maxSets = 1;
730 ds_pool_ci.poolSizeCount = 1;
731 ds_pool_ci.pPoolSizes = &ds_type_count;
732
733 VkDescriptorPool ds_pool;
734 VkResult err =
735 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
736 ASSERT_VK_SUCCESS(err);
737
738 VkDescriptorSetLayoutBinding dsl_binding = {};
739 dsl_binding.binding = 0;
740 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
741 dsl_binding.descriptorCount = 1;
742 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
743 dsl_binding.pImmutableSamplers = NULL;
744
745 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
746 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
747 ds_layout_ci.pNext = NULL;
748 ds_layout_ci.bindingCount = 1;
749 ds_layout_ci.pBindings = &dsl_binding;
750
751 VkDescriptorSetLayout ds_layout;
752 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
753 &ds_layout);
754 ASSERT_VK_SUCCESS(err);
755
756 VkDescriptorSet descriptorSet;
757 VkDescriptorSetAllocateInfo ds_alloc_info = {};
758 ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
759 ds_alloc_info.descriptorSetCount = 1;
760 ds_alloc_info.descriptorPool = ds_pool;
761 ds_alloc_info.pSetLayouts = &ds_layout;
762 err = vkAllocateDescriptorSets(m_device->device(), &ds_alloc_info,
763 &descriptorSet);
764 ASSERT_VK_SUCCESS(err);
765
766 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
767 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
768 pipeline_layout_ci.setLayoutCount = 1;
769 pipeline_layout_ci.pSetLayouts = &ds_layout;
770
771 VkPipelineLayout pipeline_layout;
772 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
773 &pipeline_layout);
774 ASSERT_VK_SUCCESS(err);
775
776 VkViewport vp = {}; // Just need dummy vp to point to
777 VkRect2D sc = {}; // dummy scissor to point to
778
779 VkPipelineViewportStateCreateInfo vp_state_ci = {};
780 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
781 vp_state_ci.scissorCount = 1;
782 vp_state_ci.pScissors = &sc;
783 vp_state_ci.viewportCount = 1;
784 vp_state_ci.pViewports = &vp;
785
786 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
787 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
788 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
789 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
790 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
791 rs_state_ci.depthClampEnable = VK_FALSE;
792 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
793 rs_state_ci.depthBiasEnable = VK_FALSE;
794
795 VkGraphicsPipelineCreateInfo gp_ci = {};
796 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
797 gp_ci.pViewportState = &vp_state_ci;
798 gp_ci.pRasterizationState = &rs_state_ci;
799 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
800 gp_ci.layout = pipeline_layout;
801 gp_ci.renderPass = renderPass();
802
803 VkPipelineCacheCreateInfo pc_ci = {};
804 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
805 pc_ci.initialDataSize = 0;
806 pc_ci.pInitialData = 0;
807
808 VkPipeline pipeline;
809 VkPipelineCache pipelineCache;
810
811 err =
812 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
813 ASSERT_VK_SUCCESS(err);
814
815 // Set VkPipelineRasterizationStateCreateInfo::pNext to an invalid value
816 VkApplicationInfo invalid_pnext_struct = {};
817 rs_state_ci.pNext = &invalid_pnext_struct;
818
819 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
820 &gp_ci, NULL, &pipeline);
821 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600822}
Dustin Graves5d33d532016-05-09 16:21:12 -0600823
824TEST_F(VkLayerTest, UnrecognizedValue) {
825 TEST_DESCRIPTION(
826 "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
827
828 ASSERT_NO_FATAL_FAILURE(InitState());
829
830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
831 "does not fall within the begin..end "
832 "range of the core VkFormat "
833 "enumeration tokens");
834 // Specify an invalid VkFormat value
835 // Expected to trigger an error with
836 // parameter_validation::validate_ranged_enum
837 VkFormatProperties format_properties;
838 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000),
839 &format_properties);
840 m_errorMonitor->VerifyFound();
841
842 m_errorMonitor->SetDesiredFailureMsg(
843 VK_DEBUG_REPORT_ERROR_BIT_EXT,
844 "contains flag bits that are not recognized members of");
845 // Specify an invalid VkFlags bitmask value
846 // Expected to trigger an error with parameter_validation::validate_flags
847 VkImageFormatProperties image_format_properties;
848 vkGetPhysicalDeviceImageFormatProperties(
849 gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D,
850 VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0,
851 &image_format_properties);
852 m_errorMonitor->VerifyFound();
853
854 m_errorMonitor->SetDesiredFailureMsg(
855 VK_DEBUG_REPORT_ERROR_BIT_EXT,
856 "contains flag bits that are not recognized members of");
857 // Specify an invalid VkFlags array entry
858 // Expected to trigger an error with
859 // parameter_validation::validate_flags_array
860 VkSemaphore semaphore = VK_NULL_HANDLE;
861 VkPipelineStageFlags stage_flags =
862 static_cast<VkPipelineStageFlags>(1 << 25);
863 VkSubmitInfo submit_info = {};
864 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
865 submit_info.waitSemaphoreCount = 1;
866 submit_info.pWaitSemaphores = &semaphore;
867 submit_info.pWaitDstStageMask = &stage_flags;
868 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
869 m_errorMonitor->VerifyFound();
870
871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
872 "is neither VK_TRUE nor VK_FALSE");
873 // Specify an invalid VkBool32 value
874 // Expected to trigger a warning with
875 // parameter_validation::validate_bool32
876 VkSampler sampler = VK_NULL_HANDLE;
877 VkSamplerCreateInfo sampler_info = {};
878 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
879 sampler_info.pNext = NULL;
880 sampler_info.magFilter = VK_FILTER_NEAREST;
881 sampler_info.minFilter = VK_FILTER_NEAREST;
882 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
883 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
884 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
885 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
886 sampler_info.mipLodBias = 1.0;
887 sampler_info.maxAnisotropy = 1;
888 sampler_info.compareEnable = VK_FALSE;
889 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
890 sampler_info.minLod = 1.0;
891 sampler_info.maxLod = 1.0;
892 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
893 sampler_info.unnormalizedCoordinates = VK_FALSE;
894 // Not VK_TRUE or VK_FALSE
895 sampler_info.anisotropyEnable = 3;
896 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
897 m_errorMonitor->VerifyFound();
898}
Dustin Gravesfce74c02016-05-10 11:42:58 -0600899
900TEST_F(VkLayerTest, FailedReturnValue) {
901 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
902
903 ASSERT_NO_FATAL_FAILURE(InitState());
904
Dustin Graves13c1e2b2016-05-16 15:31:02 -0600905 // Find an unsupported image format
906 VkFormat unsupported = VK_FORMAT_UNDEFINED;
907 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
908 VkFormat format = static_cast<VkFormat>(f);
909 VkFormatProperties fProps = m_device->format_properties(format);
910 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
911 fProps.optimalTilingFeatures == 0) {
912 unsupported = format;
913 break;
914 }
915 }
916
917 if (unsupported != VK_FORMAT_UNDEFINED) {
918 m_errorMonitor->SetDesiredFailureMsg(
919 VK_DEBUG_REPORT_WARNING_BIT_EXT,
920 "the requested format is not supported on this device");
921 // Specify an unsupported VkFormat value to generate a
922 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
923 // Expected to trigger a warning from
924 // parameter_validation::validate_result
925 VkImageFormatProperties image_format_properties;
926 VkResult err = vkGetPhysicalDeviceImageFormatProperties(
927 gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
928 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
929 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
930 m_errorMonitor->VerifyFound();
931 }
Dustin Gravesfce74c02016-05-10 11:42:58 -0600932}
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600933#endif // PARAMETER_VALIDATION_TESTS
934
Tobin Ehlis0788f522015-05-26 16:11:58 -0600935#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -0700936#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800937TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500938{
939 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500940 VkFenceCreateInfo fenceInfo = {};
941 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
942 fenceInfo.pNext = NULL;
943 fenceInfo.flags = 0;
944
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600946
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500947 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -0600948
949 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
950 vk_testing::Buffer buffer;
951 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500952
Tony Barbourfe3351b2015-07-28 10:17:20 -0600953 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800954 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600955 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500956
957 testFence.init(*m_device, fenceInfo);
958
959 // Bypass framework since it does the waits automatically
960 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600961 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800962 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
963 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800964 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600965 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -0700966 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800967 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800968 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800969 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600970 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600971
972 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500973 ASSERT_VK_SUCCESS( err );
974
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500975 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800976 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500977
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200978 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500979}
980
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800981TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500982{
983 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500984 VkFenceCreateInfo fenceInfo = {};
985 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
986 fenceInfo.pNext = NULL;
987 fenceInfo.flags = 0;
988
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600990
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500991 ASSERT_NO_FATAL_FAILURE(InitState());
992 ASSERT_NO_FATAL_FAILURE(InitViewport());
993 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
994
Tony Barbourfe3351b2015-07-28 10:17:20 -0600995 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800996 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600997 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500998
999 testFence.init(*m_device, fenceInfo);
1000
1001 // Bypass framework since it does the waits automatically
1002 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001003 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001004 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1005 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001006 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001007 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001008 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001009 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001010 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001011 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001012 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001013
1014 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001015 ASSERT_VK_SUCCESS( err );
1016
Jon Ashburnf19916e2016-01-11 13:12:43 -07001017 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001018 VkCommandBufferBeginInfo info = {};
1019 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1020 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001021 info.renderPass = VK_NULL_HANDLE;
1022 info.subpass = 0;
1023 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001024 info.occlusionQueryEnable = VK_FALSE;
1025 info.queryFlags = 0;
1026 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001027
1028 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001029 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001030
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001031 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001032}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001033#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001034
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001035// This is a positive test. No failures are expected.
1036TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1037 VkResult err;
1038 bool pass;
1039
1040 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1041 "the buffer, create an image, and bind the same memory to "
1042 "it");
1043
1044 m_errorMonitor->ExpectSuccess();
1045
1046 ASSERT_NO_FATAL_FAILURE(InitState());
1047
1048 VkBuffer buffer;
1049 VkImage image;
1050 VkDeviceMemory mem;
1051 VkMemoryRequirements mem_reqs;
1052
1053 VkBufferCreateInfo buf_info = {};
1054 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1055 buf_info.pNext = NULL;
1056 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1057 buf_info.size = 256;
1058 buf_info.queueFamilyIndexCount = 0;
1059 buf_info.pQueueFamilyIndices = NULL;
1060 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1061 buf_info.flags = 0;
1062 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1063 ASSERT_VK_SUCCESS(err);
1064
1065 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1066
1067 VkMemoryAllocateInfo alloc_info = {};
1068 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1069 alloc_info.pNext = NULL;
1070 alloc_info.memoryTypeIndex = 0;
1071
1072 // Ensure memory is big enough for both bindings
1073 alloc_info.allocationSize = 0x10000;
1074
1075 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1076 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1077 if (!pass) {
1078 vkDestroyBuffer(m_device->device(), buffer, NULL);
1079 return;
1080 }
1081
1082 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1083 ASSERT_VK_SUCCESS(err);
1084
1085 uint8_t *pData;
1086 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1087 (void **)&pData);
1088 ASSERT_VK_SUCCESS(err);
1089
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001090 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001091
1092 vkUnmapMemory(m_device->device(), mem);
1093
1094 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1095 ASSERT_VK_SUCCESS(err);
1096
1097 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1098 // memory. In fact, it was never used by the GPU.
1099 // Just be be sure, wait for idle.
1100 vkDestroyBuffer(m_device->device(), buffer, NULL);
1101 vkDeviceWaitIdle(m_device->device());
1102
1103 VkImageCreateInfo image_create_info = {};
1104 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1105 image_create_info.pNext = NULL;
1106 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1107 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1108 image_create_info.extent.width = 64;
1109 image_create_info.extent.height = 64;
1110 image_create_info.extent.depth = 1;
1111 image_create_info.mipLevels = 1;
1112 image_create_info.arrayLayers = 1;
1113 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1114 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1115 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1116 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1117 image_create_info.queueFamilyIndexCount = 0;
1118 image_create_info.pQueueFamilyIndices = NULL;
1119 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1120 image_create_info.flags = 0;
1121
1122 VkMemoryAllocateInfo mem_alloc = {};
1123 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1124 mem_alloc.pNext = NULL;
1125 mem_alloc.allocationSize = 0;
1126 mem_alloc.memoryTypeIndex = 0;
1127
1128 /* Create a mappable image. It will be the texture if linear images are ok
1129 * to be textures or it will be the staging image if they are not.
1130 */
1131 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1132 ASSERT_VK_SUCCESS(err);
1133
1134 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1135
1136 mem_alloc.allocationSize = mem_reqs.size;
1137
1138 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc,
1139 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1140 if (!pass) {
1141 vkDestroyImage(m_device->device(), image, NULL);
1142 return;
1143 }
1144
Tobin Ehlis077ded32016-05-12 17:39:13 -06001145 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001146 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1147 ASSERT_VK_SUCCESS(err);
1148
1149 m_errorMonitor->VerifyNotFound();
1150
1151 vkDestroyBuffer(m_device->device(), buffer, NULL);
1152 vkDestroyImage(m_device->device(), image, NULL);
1153}
1154
Tobin Ehlisf11be982016-05-11 13:52:53 -06001155TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1156 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1157 "buffer and image to memory such that they will alias.");
1158 VkResult err;
1159 bool pass;
1160 ASSERT_NO_FATAL_FAILURE(InitState());
1161
Tobin Ehlis077ded32016-05-12 17:39:13 -06001162 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001163 VkImage image;
1164 VkDeviceMemory mem; // buffer will be bound first
1165 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001166 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001167
1168 VkBufferCreateInfo buf_info = {};
1169 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1170 buf_info.pNext = NULL;
1171 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1172 buf_info.size = 256;
1173 buf_info.queueFamilyIndexCount = 0;
1174 buf_info.pQueueFamilyIndices = NULL;
1175 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1176 buf_info.flags = 0;
1177 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1178 ASSERT_VK_SUCCESS(err);
1179
Tobin Ehlis077ded32016-05-12 17:39:13 -06001180 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001181
1182 VkImageCreateInfo image_create_info = {};
1183 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1184 image_create_info.pNext = NULL;
1185 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1186 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1187 image_create_info.extent.width = 64;
1188 image_create_info.extent.height = 64;
1189 image_create_info.extent.depth = 1;
1190 image_create_info.mipLevels = 1;
1191 image_create_info.arrayLayers = 1;
1192 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1193 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1194 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1195 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1196 image_create_info.queueFamilyIndexCount = 0;
1197 image_create_info.pQueueFamilyIndices = NULL;
1198 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1199 image_create_info.flags = 0;
1200
Tobin Ehlisf11be982016-05-11 13:52:53 -06001201 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1202 ASSERT_VK_SUCCESS(err);
1203
Tobin Ehlis077ded32016-05-12 17:39:13 -06001204 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1205
1206 VkMemoryAllocateInfo alloc_info = {};
1207 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1208 alloc_info.pNext = NULL;
1209 alloc_info.memoryTypeIndex = 0;
1210 // Ensure memory is big enough for both bindings
1211 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
1212 pass = m_device->phy().set_memory_type(
1213 buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info,
1214 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001215 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001216 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001217 vkDestroyImage(m_device->device(), image, NULL);
1218 return;
1219 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001220 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1221 ASSERT_VK_SUCCESS(err);
1222 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1223 ASSERT_VK_SUCCESS(err);
1224
Tobin Ehlisf11be982016-05-11 13:52:53 -06001225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1226 " is aliased with buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001227 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001228 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1229 m_errorMonitor->VerifyFound();
1230
1231 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001232 // aliasing buffer2
1233 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1234 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001235 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1236 ASSERT_VK_SUCCESS(err);
1237 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1238 ASSERT_VK_SUCCESS(err);
1239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1240 " is aliased with image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001241 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001242 m_errorMonitor->VerifyFound();
1243
1244 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001245 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001246 vkDestroyImage(m_device->device(), image, NULL);
1247 vkFreeMemory(m_device->device(), mem, NULL);
1248 vkFreeMemory(m_device->device(), mem_img, NULL);
1249}
1250
Tobin Ehlis35372522016-05-12 08:32:31 -06001251TEST_F(VkLayerTest, InvalidMemoryMapping) {
1252 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1253 VkResult err;
1254 bool pass;
1255 ASSERT_NO_FATAL_FAILURE(InitState());
1256
1257 VkBuffer buffer;
1258 VkDeviceMemory mem;
1259 VkMemoryRequirements mem_reqs;
1260
1261 VkBufferCreateInfo buf_info = {};
1262 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1263 buf_info.pNext = NULL;
1264 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1265 buf_info.size = 256;
1266 buf_info.queueFamilyIndexCount = 0;
1267 buf_info.pQueueFamilyIndices = NULL;
1268 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1269 buf_info.flags = 0;
1270 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1271 ASSERT_VK_SUCCESS(err);
1272
1273 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1274 VkMemoryAllocateInfo alloc_info = {};
1275 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1276 alloc_info.pNext = NULL;
1277 alloc_info.memoryTypeIndex = 0;
1278
1279 // Ensure memory is big enough for both bindings
1280 static const VkDeviceSize allocation_size = 0x10000;
1281 alloc_info.allocationSize = allocation_size;
1282 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1283 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1284 if (!pass) {
1285 vkDestroyBuffer(m_device->device(), buffer, NULL);
1286 return;
1287 }
1288 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1289 ASSERT_VK_SUCCESS(err);
1290
1291 uint8_t *pData;
1292 // Attempt to map memory size 0 is invalid
1293 m_errorMonitor->SetDesiredFailureMsg(
1294 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1295 "VkMapMemory: Attempting to map memory range of size zero");
1296 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1297 m_errorMonitor->VerifyFound();
1298 // Map memory twice
1299 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1300 (void **)&pData);
1301 ASSERT_VK_SUCCESS(err);
1302 m_errorMonitor->SetDesiredFailureMsg(
1303 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1304 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1305 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1306 (void **)&pData);
1307 m_errorMonitor->VerifyFound();
1308
1309 // Unmap the memory to avoid re-map error
1310 vkUnmapMemory(m_device->device(), mem);
1311 // overstep allocation with VK_WHOLE_SIZE
1312 m_errorMonitor->SetDesiredFailureMsg(
1313 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1314 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1315 err = vkMapMemory(m_device->device(), mem, allocation_size + 1,
1316 VK_WHOLE_SIZE, 0, (void **)&pData);
1317 m_errorMonitor->VerifyFound();
1318 // overstep allocation w/o VK_WHOLE_SIZE
1319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1320 " oversteps total array size 0x");
1321 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0,
1322 (void **)&pData);
1323 m_errorMonitor->VerifyFound();
1324 // Now error due to unmapping memory that's not mapped
1325 m_errorMonitor->SetDesiredFailureMsg(
1326 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1327 "Unmapping Memory without memory being mapped: ");
1328 vkUnmapMemory(m_device->device(), mem);
1329 m_errorMonitor->VerifyFound();
1330 // Now map memory and cause errors due to flushing invalid ranges
1331 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0,
1332 (void **)&pData);
1333 ASSERT_VK_SUCCESS(err);
1334 VkMappedMemoryRange mmr = {};
1335 mmr.memory = mem;
1336 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
1337 m_errorMonitor->SetDesiredFailureMsg(
1338 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1339 ") is less than Memory Object's offset (");
1340 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1341 m_errorMonitor->VerifyFound();
1342 // Now flush range that oversteps mapped range
1343 vkUnmapMemory(m_device->device(), mem);
1344 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1345 ASSERT_VK_SUCCESS(err);
1346 mmr.offset = 16;
1347 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
1348 m_errorMonitor->SetDesiredFailureMsg(
1349 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1350 ") exceeds the Memory Object's upper-bound (");
1351 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1352 m_errorMonitor->VerifyFound();
1353
1354 pass =
1355 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1356 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1357 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
1358 if (!pass) {
1359 vkFreeMemory(m_device->device(), mem, NULL);
1360 vkDestroyBuffer(m_device->device(), buffer, NULL);
1361 return;
1362 }
1363 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1364 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1365
1366 vkDestroyBuffer(m_device->device(), buffer, NULL);
1367 vkFreeMemory(m_device->device(), mem, NULL);
1368}
1369
Ian Elliott1c32c772016-04-28 14:47:13 -06001370TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1371 VkResult err;
1372 bool pass;
1373
Ian Elliott489eec02016-05-05 14:12:44 -06001374// FIXME: After we turn on this code for non-Linux platforms, uncomment the
1375// following declaration (which is temporarily being moved below):
1376// VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001377 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1378 VkSwapchainCreateInfoKHR swapchain_create_info = {};
1379 uint32_t swapchain_image_count = 0;
1380// VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1381 uint32_t image_index = 0;
1382// VkPresentInfoKHR present_info = {};
1383
1384 ASSERT_NO_FATAL_FAILURE(InitState());
1385
Ian Elliott3f06ce52016-04-29 14:46:21 -06001386#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1387#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1388 // Use the functions from the VK_KHR_android_surface extension without
1389 // enabling that extension:
1390
1391 // Create a surface:
1392 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001393 m_errorMonitor->SetDesiredFailureMsg(
1394 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1395 "extension was not enabled for this");
1396 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL,
1397 &surface);
1398 pass = (err != VK_SUCCESS);
1399 ASSERT_TRUE(pass);
1400 m_errorMonitor->VerifyFound();
1401#endif // VK_USE_PLATFORM_ANDROID_KHR
1402
1403
1404#if defined(VK_USE_PLATFORM_MIR_KHR)
1405 // Use the functions from the VK_KHR_mir_surface extension without enabling
1406 // that extension:
1407
1408 // Create a surface:
1409 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001410 m_errorMonitor->SetDesiredFailureMsg(
1411 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1412 "extension was not enabled for this");
1413 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1414 pass = (err != VK_SUCCESS);
1415 ASSERT_TRUE(pass);
1416 m_errorMonitor->VerifyFound();
1417
1418 // Tell whether an mir_connection supports presentation:
1419 MirConnection *mir_connection = NULL;
1420 m_errorMonitor->SetDesiredFailureMsg(
1421 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1422 "extension was not enabled for this");
1423 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection,
1424 visual_id);
1425 m_errorMonitor->VerifyFound();
1426#endif // VK_USE_PLATFORM_MIR_KHR
1427
1428
1429#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1430 // Use the functions from the VK_KHR_wayland_surface extension without
1431 // enabling that extension:
1432
1433 // Create a surface:
1434 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001435 m_errorMonitor->SetDesiredFailureMsg(
1436 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1437 "extension was not enabled for this");
1438 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL,
1439 &surface);
1440 pass = (err != VK_SUCCESS);
1441 ASSERT_TRUE(pass);
1442 m_errorMonitor->VerifyFound();
1443
1444 // Tell whether an wayland_display supports presentation:
1445 struct wl_display wayland_display = {};
1446 m_errorMonitor->SetDesiredFailureMsg(
1447 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1448 "extension was not enabled for this");
1449 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0,
1450 &wayland_display);
1451 m_errorMonitor->VerifyFound();
1452#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001453#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001454
1455
1456#if defined(VK_USE_PLATFORM_WIN32_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001457// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1458// TO NON-LINUX PLATFORMS:
1459VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001460 // Use the functions from the VK_KHR_win32_surface extension without
1461 // enabling that extension:
1462
1463 // Create a surface:
1464 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001465 m_errorMonitor->SetDesiredFailureMsg(
1466 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1467 "extension was not enabled for this");
1468 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL,
1469 &surface);
1470 pass = (err != VK_SUCCESS);
1471 ASSERT_TRUE(pass);
1472 m_errorMonitor->VerifyFound();
1473
1474 // Tell whether win32 supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001475 m_errorMonitor->SetDesiredFailureMsg(
1476 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1477 "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001478 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001479 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001480// Set this (for now, until all platforms are supported and tested):
1481#define NEED_TO_TEST_THIS_ON_PLATFORM
1482#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001483
1484
Ian Elliott1c32c772016-04-28 14:47:13 -06001485#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001486// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1487// TO NON-LINUX PLATFORMS:
1488VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001489 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1490 // that extension:
1491
1492 // Create a surface:
1493 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001494 m_errorMonitor->SetDesiredFailureMsg(
1495 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1496 "extension was not enabled for this");
1497 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1498 pass = (err != VK_SUCCESS);
1499 ASSERT_TRUE(pass);
1500 m_errorMonitor->VerifyFound();
1501
1502 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001503 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001504 xcb_visualid_t visual_id = 0;
1505 m_errorMonitor->SetDesiredFailureMsg(
1506 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1507 "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001508 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection,
Ian Elliott1c32c772016-04-28 14:47:13 -06001509 visual_id);
1510 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001511// Set this (for now, until all platforms are supported and tested):
1512#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001513#endif // VK_USE_PLATFORM_XCB_KHR
1514
1515
Ian Elliott12630812016-04-29 14:35:43 -06001516#if defined(VK_USE_PLATFORM_XLIB_KHR)
1517 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1518 // that extension:
1519
1520 // Create a surface:
1521 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Ian Elliott12630812016-04-29 14:35:43 -06001522 m_errorMonitor->SetDesiredFailureMsg(
1523 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1524 "extension was not enabled for this");
1525 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1526 pass = (err != VK_SUCCESS);
1527 ASSERT_TRUE(pass);
1528 m_errorMonitor->VerifyFound();
1529
1530 // Tell whether an Xlib VisualID supports presentation:
1531 Display *dpy = NULL;
1532 VisualID visual = 0;
1533 m_errorMonitor->SetDesiredFailureMsg(
1534 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1535 "extension was not enabled for this");
1536 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1537 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001538// Set this (for now, until all platforms are supported and tested):
1539#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001540#endif // VK_USE_PLATFORM_XLIB_KHR
1541
1542
Ian Elliott1c32c772016-04-28 14:47:13 -06001543 // Use the functions from the VK_KHR_surface extension without enabling
1544 // that extension:
1545
Ian Elliott489eec02016-05-05 14:12:44 -06001546#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001547 // Destroy a surface:
1548 m_errorMonitor->SetDesiredFailureMsg(
1549 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1550 "extension was not enabled for this");
1551 vkDestroySurfaceKHR(instance(), surface, NULL);
1552 m_errorMonitor->VerifyFound();
1553
1554 // Check if surface supports presentation:
1555 VkBool32 supported = false;
1556 m_errorMonitor->SetDesiredFailureMsg(
1557 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1558 "extension was not enabled for this");
1559 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1560 pass = (err != VK_SUCCESS);
1561 ASSERT_TRUE(pass);
1562 m_errorMonitor->VerifyFound();
1563
1564 // Check surface capabilities:
1565 VkSurfaceCapabilitiesKHR capabilities = {};
1566 m_errorMonitor->SetDesiredFailureMsg(
1567 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1568 "extension was not enabled for this");
1569 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1570 &capabilities);
1571 pass = (err != VK_SUCCESS);
1572 ASSERT_TRUE(pass);
1573 m_errorMonitor->VerifyFound();
1574
1575 // Check surface formats:
1576 uint32_t format_count = 0;
1577 VkSurfaceFormatKHR *formats = NULL;
1578 m_errorMonitor->SetDesiredFailureMsg(
1579 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1580 "extension was not enabled for this");
1581 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1582 &format_count, formats);
1583 pass = (err != VK_SUCCESS);
1584 ASSERT_TRUE(pass);
1585 m_errorMonitor->VerifyFound();
1586
1587 // Check surface present modes:
1588 uint32_t present_mode_count = 0;
1589 VkSurfaceFormatKHR *present_modes = NULL;
1590 m_errorMonitor->SetDesiredFailureMsg(
1591 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1592 "extension was not enabled for this");
1593 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1594 &present_mode_count, present_modes);
1595 pass = (err != VK_SUCCESS);
1596 ASSERT_TRUE(pass);
1597 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001598#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001599
1600
1601 // Use the functions from the VK_KHR_swapchain extension without enabling
1602 // that extension:
1603
1604 // Create a swapchain:
1605 m_errorMonitor->SetDesiredFailureMsg(
1606 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1607 "extension was not enabled for this");
1608 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1609 swapchain_create_info.pNext = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001610 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info,
1611 NULL, &swapchain);
1612 pass = (err != VK_SUCCESS);
1613 ASSERT_TRUE(pass);
1614 m_errorMonitor->VerifyFound();
1615
1616 // Get the images from the swapchain:
1617 m_errorMonitor->SetDesiredFailureMsg(
1618 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1619 "extension was not enabled for this");
1620 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain,
1621 &swapchain_image_count, NULL);
1622 pass = (err != VK_SUCCESS);
1623 ASSERT_TRUE(pass);
1624 m_errorMonitor->VerifyFound();
1625
1626 // Try to acquire an image:
1627 m_errorMonitor->SetDesiredFailureMsg(
1628 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1629 "extension was not enabled for this");
1630 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0,
1631 VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index);
1632 pass = (err != VK_SUCCESS);
1633 ASSERT_TRUE(pass);
1634 m_errorMonitor->VerifyFound();
1635
1636 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001637 //
1638 // NOTE: Currently can't test this because a real swapchain is needed (as
1639 // opposed to the fake one we created) in order for the layer to lookup the
1640 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001641
1642 // Destroy the swapchain:
1643 m_errorMonitor->SetDesiredFailureMsg(
1644 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1645 "extension was not enabled for this");
1646 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1647 m_errorMonitor->VerifyFound();
1648}
1649
Ian Elliott2c1daf52016-05-12 09:41:46 -06001650TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06001651
Dustin Graves6c6d8982016-05-17 10:09:21 -06001652#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06001653 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001654
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001655 VkResult err;
1656 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06001657 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1658 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001659 // uint32_t swapchain_image_count = 0;
1660 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1661 // uint32_t image_index = 0;
1662 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06001663
1664 ASSERT_NO_FATAL_FAILURE(InitState());
1665
1666 // Use the create function from one of the VK_KHR_*_surface extension in
1667 // order to create a surface, testing all known errors in the process,
1668 // before successfully creating a surface:
1669 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1671 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001672 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
1673 pass = (err != VK_SUCCESS);
1674 ASSERT_TRUE(pass);
1675 m_errorMonitor->VerifyFound();
1676
1677 // Next, try to create a surface with the wrong
1678 // VkXcbSurfaceCreateInfoKHR::sType:
1679 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
1680 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1682 "called with the wrong value for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001683 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1684 pass = (err != VK_SUCCESS);
1685 ASSERT_TRUE(pass);
1686 m_errorMonitor->VerifyFound();
1687
Ian Elliott2c1daf52016-05-12 09:41:46 -06001688 // Create a native window, and then correctly create a surface:
1689 xcb_connection_t *connection;
1690 xcb_screen_t *screen;
1691 xcb_window_t xcb_window;
1692 xcb_intern_atom_reply_t *atom_wm_delete_window;
1693
1694 const xcb_setup_t *setup;
1695 xcb_screen_iterator_t iter;
1696 int scr;
1697 uint32_t value_mask, value_list[32];
1698 int width = 1;
1699 int height = 1;
1700
1701 connection = xcb_connect(NULL, &scr);
1702 ASSERT_TRUE(connection != NULL);
1703 setup = xcb_get_setup(connection);
1704 iter = xcb_setup_roots_iterator(setup);
1705 while (scr-- > 0)
1706 xcb_screen_next(&iter);
1707 screen = iter.data;
1708
1709 xcb_window = xcb_generate_id(connection);
1710
1711 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
1712 value_list[0] = screen->black_pixel;
1713 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE |
1714 XCB_EVENT_MASK_STRUCTURE_NOTIFY;
1715
1716 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window,
1717 screen->root, 0, 0, width, height, 0,
1718 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual,
1719 value_mask, value_list);
1720
1721 /* Magic code that will send notification when window is destroyed */
1722 xcb_intern_atom_cookie_t cookie =
1723 xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
1724 xcb_intern_atom_reply_t *reply =
1725 xcb_intern_atom_reply(connection, cookie, 0);
1726
1727 xcb_intern_atom_cookie_t cookie2 =
1728 xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001729 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001730 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window,
1731 (*reply).atom, 4, 32, 1,
1732 &(*atom_wm_delete_window).atom);
1733 free(reply);
1734
1735 xcb_map_window(connection, xcb_window);
1736
1737 // Force the x/y coordinates to 100,100 results are identical in consecutive
1738 // runs
1739 const uint32_t coords[] = {100, 100};
1740 xcb_configure_window(connection, xcb_window,
1741 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
1742
Ian Elliott2c1daf52016-05-12 09:41:46 -06001743 // Finally, try to correctly create a surface:
1744 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
1745 xcb_create_info.pNext = NULL;
1746 xcb_create_info.flags = 0;
1747 xcb_create_info.connection = connection;
1748 xcb_create_info.window = xcb_window;
1749 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1750 pass = (err == VK_SUCCESS);
1751 ASSERT_TRUE(pass);
1752
Ian Elliott2c1daf52016-05-12 09:41:46 -06001753 // Check if surface supports presentation:
1754
1755 // 1st, do so without having queried the queue families:
1756 VkBool32 supported = false;
1757 // TODO: Get the following error to come out:
1758 m_errorMonitor->SetDesiredFailureMsg(
1759 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1760 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
1761 "function");
1762 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1763 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001764 // ASSERT_TRUE(pass);
1765 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06001766
1767 // Next, query a queue family index that's too large:
1768 m_errorMonitor->SetDesiredFailureMsg(
1769 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1770 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001771 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface,
1772 &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001773 pass = (err != VK_SUCCESS);
1774 ASSERT_TRUE(pass);
1775 m_errorMonitor->VerifyFound();
1776
1777 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001778 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
1779 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06001780 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1781 pass = (err == VK_SUCCESS);
1782 ASSERT_TRUE(pass);
1783
Ian Elliott2c1daf52016-05-12 09:41:46 -06001784 // Before proceeding, try to create a swapchain without having called
1785 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
1786 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1787 swapchain_create_info.pNext = NULL;
1788 swapchain_create_info.flags = 0;
1789 m_errorMonitor->SetDesiredFailureMsg(
1790 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1791 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001792 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1793 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001794 pass = (err != VK_SUCCESS);
1795 ASSERT_TRUE(pass);
1796 m_errorMonitor->VerifyFound();
1797
Ian Elliott2c1daf52016-05-12 09:41:46 -06001798 // Get the surface capabilities:
1799 VkSurfaceCapabilitiesKHR surface_capabilities;
1800
1801 // Do so correctly (only error logged by this entrypoint is if the
1802 // extension isn't enabled):
1803 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1804 &surface_capabilities);
1805 pass = (err == VK_SUCCESS);
1806 ASSERT_TRUE(pass);
1807
Ian Elliott2c1daf52016-05-12 09:41:46 -06001808 // Get the surface formats:
1809 uint32_t surface_format_count;
1810
1811 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1813 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001814 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
1815 pass = (err == VK_SUCCESS);
1816 ASSERT_TRUE(pass);
1817 m_errorMonitor->VerifyFound();
1818
1819 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
1820 // correctly done a 1st try (to get the count):
1821 m_errorMonitor->SetDesiredFailureMsg(
1822 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1823 "but no prior positive value has been seen for");
1824 surface_format_count = 0;
1825 vkGetPhysicalDeviceSurfaceFormatsKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001826 gpu(), surface, &surface_format_count,
1827 (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001828 pass = (err == VK_SUCCESS);
1829 ASSERT_TRUE(pass);
1830 m_errorMonitor->VerifyFound();
1831
1832 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001833 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1834 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001835 pass = (err == VK_SUCCESS);
1836 ASSERT_TRUE(pass);
1837
1838 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001839 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(
1840 surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001841
1842 // Next, do a 2nd try with surface_format_count being set too high:
1843 surface_format_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1845 "that is greater than the value");
1846 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001847 surface_formats);
1848 pass = (err == VK_SUCCESS);
1849 ASSERT_TRUE(pass);
1850 m_errorMonitor->VerifyFound();
1851
1852 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001853 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1854 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001855 pass = (err == VK_SUCCESS);
1856 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001857 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001858 surface_formats);
1859 pass = (err == VK_SUCCESS);
1860 ASSERT_TRUE(pass);
1861
Ian Elliott2c1daf52016-05-12 09:41:46 -06001862 // Get the surface present modes:
1863 uint32_t surface_present_mode_count;
1864
1865 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1867 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001868 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
1869 pass = (err == VK_SUCCESS);
1870 ASSERT_TRUE(pass);
1871 m_errorMonitor->VerifyFound();
1872
1873 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
1874 // correctly done a 1st try (to get the count):
1875 m_errorMonitor->SetDesiredFailureMsg(
1876 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1877 "but no prior positive value has been seen for");
1878 surface_present_mode_count = 0;
1879 vkGetPhysicalDeviceSurfacePresentModesKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001880 gpu(), surface, &surface_present_mode_count,
1881 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001882 pass = (err == VK_SUCCESS);
1883 ASSERT_TRUE(pass);
1884 m_errorMonitor->VerifyFound();
1885
1886 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001887 vkGetPhysicalDeviceSurfacePresentModesKHR(
1888 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001889 pass = (err == VK_SUCCESS);
1890 ASSERT_TRUE(pass);
1891
1892 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001893 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(
1894 surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001895
1896 // Next, do a 2nd try with surface_format_count being set too high:
1897 surface_present_mode_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1899 "that is greater than the value");
1900 vkGetPhysicalDeviceSurfacePresentModesKHR(
1901 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001902 pass = (err == VK_SUCCESS);
1903 ASSERT_TRUE(pass);
1904 m_errorMonitor->VerifyFound();
1905
1906 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001907 vkGetPhysicalDeviceSurfacePresentModesKHR(
1908 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001909 pass = (err == VK_SUCCESS);
1910 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001911 vkGetPhysicalDeviceSurfacePresentModesKHR(
1912 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001913 pass = (err == VK_SUCCESS);
1914 ASSERT_TRUE(pass);
1915
Ian Elliott2c1daf52016-05-12 09:41:46 -06001916 // Create a swapchain:
1917
1918 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1920 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001921 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
1922 pass = (err != VK_SUCCESS);
1923 ASSERT_TRUE(pass);
1924 m_errorMonitor->VerifyFound();
1925
1926 // Next, call with a non-NULL swapchain_create_info, that has the wrong
1927 // sType:
1928 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1930 "called with the wrong value for");
1931 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1932 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001933 pass = (err != VK_SUCCESS);
1934 ASSERT_TRUE(pass);
1935 m_errorMonitor->VerifyFound();
1936
1937 // Next, call with a NULL swapchain pointer:
1938 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1939 swapchain_create_info.pNext = NULL;
1940 swapchain_create_info.flags = 0;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1942 "called with NULL pointer");
1943 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1944 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001945 pass = (err != VK_SUCCESS);
1946 ASSERT_TRUE(pass);
1947 m_errorMonitor->VerifyFound();
1948
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001949 // TODO: Enhance swapchain layer so that
1950 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06001951
1952 // Next, call with a queue family index that's too large:
1953 uint32_t queueFamilyIndex[2] = {100000, 0};
1954 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
1955 swapchain_create_info.queueFamilyIndexCount = 2;
1956 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
1957 m_errorMonitor->SetDesiredFailureMsg(
1958 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1959 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001960 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1961 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001962 pass = (err != VK_SUCCESS);
1963 ASSERT_TRUE(pass);
1964 m_errorMonitor->VerifyFound();
1965
1966 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
1967 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
1968 swapchain_create_info.queueFamilyIndexCount = 1;
1969 m_errorMonitor->SetDesiredFailureMsg(
1970 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1971 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
1972 "pCreateInfo->pQueueFamilyIndices).");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001973 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1974 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001975 pass = (err != VK_SUCCESS);
1976 ASSERT_TRUE(pass);
1977 m_errorMonitor->VerifyFound();
1978
1979 // Next, call with an invalid imageSharingMode:
1980 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
1981 swapchain_create_info.queueFamilyIndexCount = 1;
1982 m_errorMonitor->SetDesiredFailureMsg(
1983 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1984 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001985 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1986 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001987 pass = (err != VK_SUCCESS);
1988 ASSERT_TRUE(pass);
1989 m_errorMonitor->VerifyFound();
1990 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001991 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
1992 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06001993 swapchain_create_info.queueFamilyIndexCount = 0;
1994 queueFamilyIndex[0] = 0;
1995 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
1996
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001997 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06001998 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001999 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002000 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002001 // Destroy the swapchain:
2002
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002003 // TODOs:
2004 //
2005 // - Try destroying the device without first destroying the swapchain
2006 //
2007 // - Try destroying the device without first destroying the surface
2008 //
2009 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002010
2011 // Destroy the surface:
2012 vkDestroySurfaceKHR(instance(), surface, NULL);
2013
Ian Elliott2c1daf52016-05-12 09:41:46 -06002014 // Tear down the window:
2015 xcb_destroy_window(connection, xcb_window);
2016 xcb_disconnect(connection);
2017
2018#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002019 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002020#endif // VK_USE_PLATFORM_XCB_KHR
2021}
2022
Karl Schultz6addd812016-02-02 17:17:23 -07002023TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2024 VkResult err;
2025 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002026
Karl Schultz6addd812016-02-02 17:17:23 -07002027 m_errorMonitor->SetDesiredFailureMsg(
2028 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002029 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
2030
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002031 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002032
2033 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002034 VkImage image;
2035 VkDeviceMemory mem;
2036 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002037
Karl Schultz6addd812016-02-02 17:17:23 -07002038 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2039 const int32_t tex_width = 32;
2040 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002041
Tony Barboureb254902015-07-15 12:50:33 -06002042 VkImageCreateInfo image_create_info = {};
2043 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002044 image_create_info.pNext = NULL;
2045 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2046 image_create_info.format = tex_format;
2047 image_create_info.extent.width = tex_width;
2048 image_create_info.extent.height = tex_height;
2049 image_create_info.extent.depth = 1;
2050 image_create_info.mipLevels = 1;
2051 image_create_info.arrayLayers = 1;
2052 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2053 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2054 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2055 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002056
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002057 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002058 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002059 mem_alloc.pNext = NULL;
2060 mem_alloc.allocationSize = 0;
2061 // Introduce failure, do NOT set memProps to
2062 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
2063 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002064
Chia-I Wuf7458c52015-10-26 21:10:41 +08002065 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002066 ASSERT_VK_SUCCESS(err);
2067
Karl Schultz6addd812016-02-02 17:17:23 -07002068 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002069
Mark Lobodzinski23065352015-05-29 09:32:35 -05002070 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002071
Karl Schultz6addd812016-02-02 17:17:23 -07002072 pass =
2073 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0,
2074 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
2075 if (!pass) { // If we can't find any unmappable memory this test doesn't
2076 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002077 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002078 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002079 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002080
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002081 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002082 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002083 ASSERT_VK_SUCCESS(err);
2084
2085 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002086 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002087 ASSERT_VK_SUCCESS(err);
2088
2089 // Map memory as if to initialize the image
2090 void *mappedAddress = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07002091 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0,
2092 &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002093
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002094 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002095
Chia-I Wuf7458c52015-10-26 21:10:41 +08002096 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002097}
2098
Karl Schultz6addd812016-02-02 17:17:23 -07002099TEST_F(VkLayerTest, RebindMemory) {
2100 VkResult err;
2101 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002102
Karl Schultz6addd812016-02-02 17:17:23 -07002103 m_errorMonitor->SetDesiredFailureMsg(
2104 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002105 "which has already been bound to mem object");
2106
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002107 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002108
2109 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002110 VkImage image;
2111 VkDeviceMemory mem1;
2112 VkDeviceMemory mem2;
2113 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002114
Karl Schultz6addd812016-02-02 17:17:23 -07002115 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2116 const int32_t tex_width = 32;
2117 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002118
Tony Barboureb254902015-07-15 12:50:33 -06002119 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002120 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2121 image_create_info.pNext = NULL;
2122 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2123 image_create_info.format = tex_format;
2124 image_create_info.extent.width = tex_width;
2125 image_create_info.extent.height = tex_height;
2126 image_create_info.extent.depth = 1;
2127 image_create_info.mipLevels = 1;
2128 image_create_info.arrayLayers = 1;
2129 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2130 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2131 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2132 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002133
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002134 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002135 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2136 mem_alloc.pNext = NULL;
2137 mem_alloc.allocationSize = 0;
2138 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002139
Karl Schultz6addd812016-02-02 17:17:23 -07002140 // Introduce failure, do NOT set memProps to
2141 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002142 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002143 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002144 ASSERT_VK_SUCCESS(err);
2145
Karl Schultz6addd812016-02-02 17:17:23 -07002146 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002147
2148 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002149 pass =
2150 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002151 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002152
2153 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002154 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002155 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002156 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002157 ASSERT_VK_SUCCESS(err);
2158
2159 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002160 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002161 ASSERT_VK_SUCCESS(err);
2162
Karl Schultz6addd812016-02-02 17:17:23 -07002163 // Introduce validation failure, try to bind a different memory object to
2164 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002165 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002166
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002167 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002168
Chia-I Wuf7458c52015-10-26 21:10:41 +08002169 vkDestroyImage(m_device->device(), image, NULL);
2170 vkFreeMemory(m_device->device(), mem1, NULL);
2171 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002172}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002173
Karl Schultz6addd812016-02-02 17:17:23 -07002174TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002175 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002176
Karl Schultz6addd812016-02-02 17:17:23 -07002177 m_errorMonitor->SetDesiredFailureMsg(
2178 VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2179 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002180
2181 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002182 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2183 fenceInfo.pNext = NULL;
2184 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002185
Tony Barbour300a6082015-04-07 13:44:53 -06002186 ASSERT_NO_FATAL_FAILURE(InitState());
2187 ASSERT_NO_FATAL_FAILURE(InitViewport());
2188 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2189
Tony Barbourfe3351b2015-07-28 10:17:20 -06002190 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002191 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
2192 m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002193 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002194
2195 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002196
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002197 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002198 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2199 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002200 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002201 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002202 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002203 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002204 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002205 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002206 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002207
2208 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002209 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002210
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002211 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002212}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002213// This is a positive test. We used to expect error in this case but spec now
2214// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002215TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002216 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002217 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002218 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002219 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2220 fenceInfo.pNext = NULL;
2221
Tony Barbour0b4d9562015-04-09 10:48:04 -06002222 ASSERT_NO_FATAL_FAILURE(InitState());
2223 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002224 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002225 VkResult result = vkResetFences(m_device->device(), 1, fences);
2226 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002227
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002228 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002229}
Tobin Ehlis41376e12015-07-03 08:45:14 -06002230
2231TEST_F(VkLayerTest, InvalidUsageBits)
2232{
Tony Barbourf92621a2016-05-02 14:28:12 -06002233 TEST_DESCRIPTION(
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002234 "Specify wrong usage for image then create conflicting view of image "
Tony Barbourf92621a2016-05-02 14:28:12 -06002235 "Initialize buffer with wrong usage then perform copy expecting errors "
2236 "from both the image and the buffer (2 calls)");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002238 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002239
2240 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002241 VkImageObj image(m_device);
2242 // Initialize image with USAGE_INPUT_ATTACHMENT
Tobin Ehlis8b313c02016-05-25 15:01:52 -06002243 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT,
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002244 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
2245 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002246
Tony Barbourf92621a2016-05-02 14:28:12 -06002247 VkImageView dsv;
2248 VkImageViewCreateInfo dsvci = {};
2249 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2250 dsvci.image = image.handle();
2251 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2252 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2253 dsvci.subresourceRange.layerCount = 1;
2254 dsvci.subresourceRange.baseMipLevel = 0;
2255 dsvci.subresourceRange.levelCount = 1;
2256 dsvci.subresourceRange.aspectMask =
2257 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002258
Tony Barbourf92621a2016-05-02 14:28:12 -06002259 // Create a view with depth / stencil aspect for image with different usage
2260 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002261
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002262 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002263
2264 // Initialize buffer with TRANSFER_DST usage
2265 vk_testing::Buffer buffer;
2266 VkMemoryPropertyFlags reqs = 0;
2267 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2268 VkBufferImageCopy region = {};
2269 region.bufferRowLength = 128;
2270 region.bufferImageHeight = 128;
2271 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2272 region.imageSubresource.layerCount = 1;
2273 region.imageExtent.height = 16;
2274 region.imageExtent.width = 16;
2275 region.imageExtent.depth = 1;
2276
2277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2278 "Invalid usage flag for buffer ");
2279 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2280 // TRANSFER_DST
2281 BeginCommandBuffer();
2282 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2283 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2284 1, &region);
2285 m_errorMonitor->VerifyFound();
2286
2287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2288 "Invalid usage flag for image ");
2289 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2290 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2291 1, &region);
2292 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002293}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002294#endif // MEM_TRACKER_TESTS
2295
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002296#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002297
2298TEST_F(VkLayerTest, LeakAnObject) {
2299 VkResult err;
2300
2301 TEST_DESCRIPTION(
2302 "Create a fence and destroy its device without first destroying the fence.");
2303
2304 // Note that we have to create a new device since destroying the
2305 // framework's device causes Teardown() to fail and just calling Teardown
2306 // will destroy the errorMonitor.
2307
2308 m_errorMonitor->SetDesiredFailureMsg(
2309 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2310 "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object");
2311
2312 ASSERT_NO_FATAL_FAILURE(InitState());
2313
2314 const std::vector<VkQueueFamilyProperties> queue_props =
2315 m_device->queue_props;
2316 std::vector<VkDeviceQueueCreateInfo> queue_info;
2317 queue_info.reserve(queue_props.size());
2318 std::vector<std::vector<float>> queue_priorities;
2319 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2320 VkDeviceQueueCreateInfo qi = {};
2321 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2322 qi.pNext = NULL;
2323 qi.queueFamilyIndex = i;
2324 qi.queueCount = queue_props[i].queueCount;
2325 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2326 qi.pQueuePriorities = queue_priorities[i].data();
2327 queue_info.push_back(qi);
2328 }
2329
2330 std::vector<const char *> device_layer_names;
2331 std::vector<const char *> device_extension_names;
2332 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
2333 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
2334 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
2335 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
2336 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
2337 device_layer_names.push_back("VK_LAYER_LUNARG_image");
2338 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
2339
2340 // The sacrificial device object
2341 VkDevice testDevice;
2342 VkDeviceCreateInfo device_create_info = {};
2343 auto features = m_device->phy().features();
2344 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2345 device_create_info.pNext = NULL;
2346 device_create_info.queueCreateInfoCount = queue_info.size();
2347 device_create_info.pQueueCreateInfos = queue_info.data();
2348 device_create_info.enabledLayerCount = device_layer_names.size();
2349 device_create_info.ppEnabledLayerNames = device_layer_names.data();
2350 device_create_info.pEnabledFeatures = &features;
2351 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2352 ASSERT_VK_SUCCESS(err);
2353
2354 VkFence fence;
2355 VkFenceCreateInfo fence_create_info = {};
2356 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2357 fence_create_info.pNext = NULL;
2358 fence_create_info.flags = 0;
2359 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2360 ASSERT_VK_SUCCESS(err);
2361
2362 // Induce failure by not calling vkDestroyFence
2363 vkDestroyDevice(testDevice, NULL);
2364 m_errorMonitor->VerifyFound();
2365}
2366
2367TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2368
2369 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2370 "attempt to delete them from another.");
2371
2372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2373 "FreeCommandBuffers is attempting to free Command Buffer");
2374
2375 VkCommandPool command_pool_one;
2376 VkCommandPool command_pool_two;
2377
2378 VkCommandPoolCreateInfo pool_create_info{};
2379 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2380 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2381 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2382
2383 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2384 &command_pool_one);
2385
2386 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2387 &command_pool_two);
2388
2389 VkCommandBuffer command_buffer[9];
2390 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2391 command_buffer_allocate_info.sType =
2392 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2393 command_buffer_allocate_info.commandPool = command_pool_one;
2394 command_buffer_allocate_info.commandBufferCount = 9;
2395 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2396 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2397 command_buffer);
2398
2399 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4,
2400 &command_buffer[3]);
2401
2402 m_errorMonitor->VerifyFound();
2403
2404 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2405 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2406}
2407
2408TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2409 VkResult err;
2410
2411 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
2412 "attempt to delete them from another.");
2413
2414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2415 "FreeDescriptorSets is attempting to free descriptorSet");
2416
2417 ASSERT_NO_FATAL_FAILURE(InitState());
2418 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2419
2420 VkDescriptorPoolSize ds_type_count = {};
2421 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2422 ds_type_count.descriptorCount = 1;
2423
2424 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2425 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2426 ds_pool_ci.pNext = NULL;
2427 ds_pool_ci.flags = 0;
2428 ds_pool_ci.maxSets = 1;
2429 ds_pool_ci.poolSizeCount = 1;
2430 ds_pool_ci.pPoolSizes = &ds_type_count;
2431
2432 VkDescriptorPool ds_pool_one;
2433 err =
2434 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
2435 ASSERT_VK_SUCCESS(err);
2436
2437 // Create a second descriptor pool
2438 VkDescriptorPool ds_pool_two;
2439 err =
2440 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
2441 ASSERT_VK_SUCCESS(err);
2442
2443 VkDescriptorSetLayoutBinding dsl_binding = {};
2444 dsl_binding.binding = 0;
2445 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2446 dsl_binding.descriptorCount = 1;
2447 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2448 dsl_binding.pImmutableSamplers = NULL;
2449
2450 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2451 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2452 ds_layout_ci.pNext = NULL;
2453 ds_layout_ci.bindingCount = 1;
2454 ds_layout_ci.pBindings = &dsl_binding;
2455
2456 VkDescriptorSetLayout ds_layout;
2457 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2458 &ds_layout);
2459 ASSERT_VK_SUCCESS(err);
2460
2461 VkDescriptorSet descriptorSet;
2462 VkDescriptorSetAllocateInfo alloc_info = {};
2463 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2464 alloc_info.descriptorSetCount = 1;
2465 alloc_info.descriptorPool = ds_pool_one;
2466 alloc_info.pSetLayouts = &ds_layout;
2467 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2468 &descriptorSet);
2469 ASSERT_VK_SUCCESS(err);
2470
2471 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2472
2473 m_errorMonitor->VerifyFound();
2474
2475 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2476 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2477 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2478}
2479
2480TEST_F(VkLayerTest, CreateUnknownObject) {
2481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2482 "Invalid VkImage Object ");
2483
2484 TEST_DESCRIPTION(
2485 "Pass an invalid image object handle into a Vulkan API call.");
2486
2487 ASSERT_NO_FATAL_FAILURE(InitState());
2488
2489 // Pass bogus handle into GetImageMemoryRequirements
2490 VkMemoryRequirements mem_reqs;
2491 uint64_t fakeImageHandle = 0xCADECADE;
2492 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2493
2494 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2495
2496 m_errorMonitor->VerifyFound();
2497}
2498
Karl Schultz6addd812016-02-02 17:17:23 -07002499TEST_F(VkLayerTest, PipelineNotBound) {
2500 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002501
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002502 TEST_DESCRIPTION(
2503 "Pass in an invalid pipeline object handle into a Vulkan API call.");
2504
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002506 "Invalid VkPipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002507
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002508 ASSERT_NO_FATAL_FAILURE(InitState());
2509 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002510
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002511 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002512 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2513 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002514
2515 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002516 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2517 ds_pool_ci.pNext = NULL;
2518 ds_pool_ci.maxSets = 1;
2519 ds_pool_ci.poolSizeCount = 1;
2520 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002521
2522 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002523 err =
2524 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002525 ASSERT_VK_SUCCESS(err);
2526
2527 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002528 dsl_binding.binding = 0;
2529 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2530 dsl_binding.descriptorCount = 1;
2531 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2532 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002533
2534 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002535 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2536 ds_layout_ci.pNext = NULL;
2537 ds_layout_ci.bindingCount = 1;
2538 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002539
2540 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002541 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2542 &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002543 ASSERT_VK_SUCCESS(err);
2544
2545 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002546 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002547 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002548 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002549 alloc_info.descriptorPool = ds_pool;
2550 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002551 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2552 &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002553 ASSERT_VK_SUCCESS(err);
2554
2555 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002556 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2557 pipeline_layout_ci.pNext = NULL;
2558 pipeline_layout_ci.setLayoutCount = 1;
2559 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002560
2561 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002562 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2563 &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002564 ASSERT_VK_SUCCESS(err);
2565
Mark Youngad779052016-01-06 14:26:04 -07002566 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002567
2568 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002569 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
2570 VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002571
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002572 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002573
Chia-I Wuf7458c52015-10-26 21:10:41 +08002574 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2575 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2576 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002577}
2578
Karl Schultz6addd812016-02-02 17:17:23 -07002579TEST_F(VkLayerTest, BindInvalidMemory) {
2580 VkResult err;
2581 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002582
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002584 "Invalid VkDeviceMemory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002585
Tobin Ehlisec598302015-09-15 15:02:17 -06002586 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002587
2588 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002589 VkImage image;
2590 VkDeviceMemory mem;
2591 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002592
Karl Schultz6addd812016-02-02 17:17:23 -07002593 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2594 const int32_t tex_width = 32;
2595 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002596
2597 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002598 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2599 image_create_info.pNext = NULL;
2600 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2601 image_create_info.format = tex_format;
2602 image_create_info.extent.width = tex_width;
2603 image_create_info.extent.height = tex_height;
2604 image_create_info.extent.depth = 1;
2605 image_create_info.mipLevels = 1;
2606 image_create_info.arrayLayers = 1;
2607 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2608 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2609 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2610 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002611
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002612 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002613 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2614 mem_alloc.pNext = NULL;
2615 mem_alloc.allocationSize = 0;
2616 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002617
Chia-I Wuf7458c52015-10-26 21:10:41 +08002618 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002619 ASSERT_VK_SUCCESS(err);
2620
Karl Schultz6addd812016-02-02 17:17:23 -07002621 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002622
2623 mem_alloc.allocationSize = mem_reqs.size;
2624
Karl Schultz6addd812016-02-02 17:17:23 -07002625 pass =
2626 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002627 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002628
2629 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002630 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002631 ASSERT_VK_SUCCESS(err);
2632
2633 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002634 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002635
2636 // Try to bind free memory that has been freed
2637 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2638 // This may very well return an error.
2639 (void)err;
2640
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002641 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002642
Chia-I Wuf7458c52015-10-26 21:10:41 +08002643 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002644}
2645
Karl Schultz6addd812016-02-02 17:17:23 -07002646TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2647 VkResult err;
2648 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002649
Karl Schultz6addd812016-02-02 17:17:23 -07002650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2651 "Invalid VkImage Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002652
Tobin Ehlisec598302015-09-15 15:02:17 -06002653 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002654
Karl Schultz6addd812016-02-02 17:17:23 -07002655 // Create an image object, allocate memory, destroy the object and then try
2656 // to bind it
2657 VkImage image;
2658 VkDeviceMemory mem;
2659 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002660
Karl Schultz6addd812016-02-02 17:17:23 -07002661 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2662 const int32_t tex_width = 32;
2663 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002664
2665 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002666 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2667 image_create_info.pNext = NULL;
2668 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2669 image_create_info.format = tex_format;
2670 image_create_info.extent.width = tex_width;
2671 image_create_info.extent.height = tex_height;
2672 image_create_info.extent.depth = 1;
2673 image_create_info.mipLevels = 1;
2674 image_create_info.arrayLayers = 1;
2675 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2676 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2677 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2678 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002679
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002680 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002681 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2682 mem_alloc.pNext = NULL;
2683 mem_alloc.allocationSize = 0;
2684 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002685
Chia-I Wuf7458c52015-10-26 21:10:41 +08002686 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002687 ASSERT_VK_SUCCESS(err);
2688
Karl Schultz6addd812016-02-02 17:17:23 -07002689 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002690
2691 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002692 pass =
2693 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002694 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002695
2696 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002697 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002698 ASSERT_VK_SUCCESS(err);
2699
2700 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002701 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002702 ASSERT_VK_SUCCESS(err);
2703
2704 // Now Try to bind memory to this destroyed object
2705 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2706 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002707 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002708
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002709 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002710
Chia-I Wuf7458c52015-10-26 21:10:41 +08002711 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002712}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002713
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002714#endif // OBJ_TRACKER_TESTS
2715
Tobin Ehlis0788f522015-05-26 16:11:58 -06002716#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002717
2718// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05002719TEST_F(VkLayerTest, WaitEventThenSet) {
2720 TEST_DESCRIPTION(
2721 "Wait on a event then set it after the wait has been submitted.");
2722
2723 if ((m_device->queue_props.empty()) ||
2724 (m_device->queue_props[0].queueCount < 2))
2725 return;
2726
2727 m_errorMonitor->ExpectSuccess();
2728
2729 VkEvent event;
2730 VkEventCreateInfo event_create_info{};
2731 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2732 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
2733
2734 VkCommandPool command_pool;
2735 VkCommandPoolCreateInfo pool_create_info{};
2736 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2737 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2738 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2739 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2740 &command_pool);
2741
2742 VkCommandBuffer command_buffer;
2743 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2744 command_buffer_allocate_info.sType =
2745 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2746 command_buffer_allocate_info.commandPool = command_pool;
2747 command_buffer_allocate_info.commandBufferCount = 1;
2748 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2749 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2750 &command_buffer);
2751
2752 VkQueue queue = VK_NULL_HANDLE;
2753 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2754 1, &queue);
2755
2756 {
2757 VkCommandBufferBeginInfo begin_info{};
2758 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2759 vkBeginCommandBuffer(command_buffer, &begin_info);
2760
2761 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT,
2762 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
2763 nullptr, 0, nullptr);
2764 vkCmdResetEvent(command_buffer, event,
2765 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
2766 vkEndCommandBuffer(command_buffer);
2767 }
2768 {
2769 VkSubmitInfo submit_info{};
2770 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2771 submit_info.commandBufferCount = 1;
2772 submit_info.pCommandBuffers = &command_buffer;
2773 submit_info.signalSemaphoreCount = 0;
2774 submit_info.pSignalSemaphores = nullptr;
2775 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2776 }
2777 { vkSetEvent(m_device->device(), event); }
2778
2779 vkQueueWaitIdle(queue);
2780
2781 vkDestroyEvent(m_device->device(), event, nullptr);
2782 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
2783 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2784
2785 m_errorMonitor->VerifyNotFound();
2786}
Michael Lentine5627e692016-05-20 17:45:02 -05002787// This is a positive test. No errors should be generated.
2788TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
2789 TEST_DESCRIPTION(
2790 "Issue a query and copy from it on a second command buffer.");
2791
2792 if ((m_device->queue_props.empty()) ||
2793 (m_device->queue_props[0].queueCount < 2))
2794 return;
2795
2796 m_errorMonitor->ExpectSuccess();
2797
2798 VkQueryPool query_pool;
2799 VkQueryPoolCreateInfo query_pool_create_info{};
2800 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
2801 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
2802 query_pool_create_info.queryCount = 1;
2803 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr,
2804 &query_pool);
2805
2806 VkCommandPool command_pool;
2807 VkCommandPoolCreateInfo pool_create_info{};
2808 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2809 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2810 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2811 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2812 &command_pool);
2813
2814 VkCommandBuffer command_buffer[2];
2815 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2816 command_buffer_allocate_info.sType =
2817 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2818 command_buffer_allocate_info.commandPool = command_pool;
2819 command_buffer_allocate_info.commandBufferCount = 2;
2820 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2821 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2822 command_buffer);
2823
2824 VkQueue queue = VK_NULL_HANDLE;
2825 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2826 1, &queue);
2827
2828 uint32_t qfi = 0;
2829 VkBufferCreateInfo buff_create_info = {};
2830 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2831 buff_create_info.size = 1024;
2832 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
2833 buff_create_info.queueFamilyIndexCount = 1;
2834 buff_create_info.pQueueFamilyIndices = &qfi;
2835
2836 VkResult err;
2837 VkBuffer buffer;
2838 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
2839 ASSERT_VK_SUCCESS(err);
2840 VkMemoryAllocateInfo mem_alloc = {};
2841 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2842 mem_alloc.pNext = NULL;
2843 mem_alloc.allocationSize = 1024;
2844 mem_alloc.memoryTypeIndex = 0;
2845
2846 VkMemoryRequirements memReqs;
2847 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
2848 bool pass =
2849 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
2850 if (!pass) {
2851 vkDestroyBuffer(m_device->device(), buffer, NULL);
2852 return;
2853 }
2854
2855 VkDeviceMemory mem;
2856 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2857 ASSERT_VK_SUCCESS(err);
2858 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
2859 ASSERT_VK_SUCCESS(err);
2860
2861 {
2862 VkCommandBufferBeginInfo begin_info{};
2863 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2864 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2865
2866 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
2867 vkCmdWriteTimestamp(command_buffer[0],
2868 VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
2869
2870 vkEndCommandBuffer(command_buffer[0]);
2871
2872 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2873
2874 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer,
2875 0, 0, 0);
2876
2877 vkEndCommandBuffer(command_buffer[1]);
2878 }
2879 {
2880 VkSubmitInfo submit_info{};
2881 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2882 submit_info.commandBufferCount = 2;
2883 submit_info.pCommandBuffers = command_buffer;
2884 submit_info.signalSemaphoreCount = 0;
2885 submit_info.pSignalSemaphores = nullptr;
2886 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2887 }
2888
2889 vkQueueWaitIdle(queue);
2890
2891 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
2892 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
2893 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2894
2895 m_errorMonitor->VerifyNotFound();
2896}
Michael Lentine860b0fe2016-05-20 10:14:00 -05002897
2898TEST_F(VkLayerTest, ResetEventThenSet) {
2899 TEST_DESCRIPTION(
2900 "Reset an event then set it after the reset has been submitted.");
2901
2902 if ((m_device->queue_props.empty()) ||
2903 (m_device->queue_props[0].queueCount < 2))
2904 return;
2905
2906 m_errorMonitor->ExpectSuccess();
2907
2908 VkEvent event;
2909 VkEventCreateInfo event_create_info{};
2910 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2911 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
2912
2913 VkCommandPool command_pool;
2914 VkCommandPoolCreateInfo pool_create_info{};
2915 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2916 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2917 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2918 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2919 &command_pool);
2920
2921 VkCommandBuffer command_buffer;
2922 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2923 command_buffer_allocate_info.sType =
2924 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2925 command_buffer_allocate_info.commandPool = command_pool;
2926 command_buffer_allocate_info.commandBufferCount = 1;
2927 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2928 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2929 &command_buffer);
2930
2931 VkQueue queue = VK_NULL_HANDLE;
2932 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2933 1, &queue);
2934
2935 {
2936 VkCommandBufferBeginInfo begin_info{};
2937 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2938 vkBeginCommandBuffer(command_buffer, &begin_info);
2939
2940 vkCmdResetEvent(command_buffer, event,
2941 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
2942 vkCmdWaitEvents(command_buffer, 1, &event,
2943 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2944 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
2945 nullptr, 0, nullptr);
2946 vkEndCommandBuffer(command_buffer);
2947 }
2948 {
2949 VkSubmitInfo submit_info{};
2950 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2951 submit_info.commandBufferCount = 1;
2952 submit_info.pCommandBuffers = &command_buffer;
2953 submit_info.signalSemaphoreCount = 0;
2954 submit_info.pSignalSemaphores = nullptr;
2955 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2956 }
2957 {
2958 m_errorMonitor->SetDesiredFailureMsg(
2959 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event "
2960 "0x1 that is already in use by a "
2961 "command buffer.");
2962 vkSetEvent(m_device->device(), event);
2963 m_errorMonitor->VerifyFound();
2964 }
2965
2966 vkQueueWaitIdle(queue);
2967
2968 vkDestroyEvent(m_device->device(), event, nullptr);
2969 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
2970 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2971}
2972
2973// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06002974TEST_F(VkLayerTest, TwoFencesThreeFrames) {
2975 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
2976 "run through a Submit & WaitForFences cycle 3 times. This "
2977 "previously revealed a bug so running this positive test "
2978 "to prevent a regression.");
2979 m_errorMonitor->ExpectSuccess();
2980
2981 ASSERT_NO_FATAL_FAILURE(InitState());
2982 VkQueue queue = VK_NULL_HANDLE;
2983 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2984 0, &queue);
2985
2986 static const uint32_t NUM_OBJECTS = 2;
2987 static const uint32_t NUM_FRAMES = 3;
2988 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
2989 VkFence fences[NUM_OBJECTS] = {};
2990
2991 VkCommandPool cmd_pool;
2992 VkCommandPoolCreateInfo cmd_pool_ci = {};
2993 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2994 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
2995 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2996 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci,
2997 nullptr, &cmd_pool);
2998 ASSERT_VK_SUCCESS(err);
2999
3000 VkCommandBufferAllocateInfo cmd_buf_info = {};
3001 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3002 cmd_buf_info.commandPool = cmd_pool;
3003 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3004 cmd_buf_info.commandBufferCount = 1;
3005
3006 VkFenceCreateInfo fence_ci = {};
3007 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3008 fence_ci.pNext = nullptr;
3009 fence_ci.flags = 0;
3010
3011 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3012 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info,
3013 &cmd_buffers[i]);
3014 ASSERT_VK_SUCCESS(err);
3015 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
3016 ASSERT_VK_SUCCESS(err);
3017 }
3018
3019 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06003020 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
3021 // Create empty cmd buffer
3022 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3023 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003024
Tobin Ehlisf9025162016-05-26 06:55:21 -06003025 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
3026 ASSERT_VK_SUCCESS(err);
3027 err = vkEndCommandBuffer(cmd_buffers[obj]);
3028 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003029
Tobin Ehlisf9025162016-05-26 06:55:21 -06003030 VkSubmitInfo submit_info = {};
3031 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3032 submit_info.commandBufferCount = 1;
3033 submit_info.pCommandBuffers = &cmd_buffers[obj];
3034 // Submit cmd buffer and wait for fence
3035 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
3036 ASSERT_VK_SUCCESS(err);
3037 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE,
3038 UINT64_MAX);
3039 ASSERT_VK_SUCCESS(err);
3040 err = vkResetFences(m_device->device(), 1, &fences[obj]);
3041 ASSERT_VK_SUCCESS(err);
3042 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003043 }
3044 m_errorMonitor->VerifyNotFound();
3045}
3046// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003047TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
3048
3049 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3050 "submitted on separate queues followed by a QueueWaitIdle.");
3051
Dustin Graves48458142016-04-29 16:11:55 -06003052 if ((m_device->queue_props.empty()) ||
3053 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003054 return;
3055
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003056 m_errorMonitor->ExpectSuccess();
3057
3058 VkSemaphore semaphore;
3059 VkSemaphoreCreateInfo semaphore_create_info{};
3060 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3061 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3062 &semaphore);
3063
3064 VkCommandPool command_pool;
3065 VkCommandPoolCreateInfo pool_create_info{};
3066 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3067 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3068 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3069 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3070 &command_pool);
3071
3072 VkCommandBuffer command_buffer[2];
3073 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3074 command_buffer_allocate_info.sType =
3075 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3076 command_buffer_allocate_info.commandPool = command_pool;
3077 command_buffer_allocate_info.commandBufferCount = 2;
3078 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3079 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3080 command_buffer);
3081
3082 VkQueue queue = VK_NULL_HANDLE;
3083 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3084 1, &queue);
3085
3086 {
3087 VkCommandBufferBeginInfo begin_info{};
3088 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3089 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3090
3091 vkCmdPipelineBarrier(command_buffer[0],
3092 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3093 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3094 0, nullptr, 0, nullptr);
3095
3096 VkViewport viewport{};
3097 viewport.maxDepth = 1.0f;
3098 viewport.minDepth = 0.0f;
3099 viewport.width = 512;
3100 viewport.height = 512;
3101 viewport.x = 0;
3102 viewport.y = 0;
3103 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3104 vkEndCommandBuffer(command_buffer[0]);
3105 }
3106 {
3107 VkCommandBufferBeginInfo begin_info{};
3108 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3109 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3110
3111 VkViewport viewport{};
3112 viewport.maxDepth = 1.0f;
3113 viewport.minDepth = 0.0f;
3114 viewport.width = 512;
3115 viewport.height = 512;
3116 viewport.x = 0;
3117 viewport.y = 0;
3118 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3119 vkEndCommandBuffer(command_buffer[1]);
3120 }
3121 {
3122 VkSubmitInfo submit_info{};
3123 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3124 submit_info.commandBufferCount = 1;
3125 submit_info.pCommandBuffers = &command_buffer[0];
3126 submit_info.signalSemaphoreCount = 1;
3127 submit_info.pSignalSemaphores = &semaphore;
3128 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3129 }
3130 {
3131 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3132 VkSubmitInfo submit_info{};
3133 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3134 submit_info.commandBufferCount = 1;
3135 submit_info.pCommandBuffers = &command_buffer[1];
3136 submit_info.waitSemaphoreCount = 1;
3137 submit_info.pWaitSemaphores = &semaphore;
3138 submit_info.pWaitDstStageMask = flags;
3139 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3140 }
3141
3142 vkQueueWaitIdle(m_device->m_queue);
3143
3144 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3145 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3146 &command_buffer[0]);
3147 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3148
3149 m_errorMonitor->VerifyNotFound();
3150}
3151
3152// This is a positive test. No errors should be generated.
3153TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
3154
3155 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3156 "submitted on separate queues, the second having a fence"
3157 "followed by a QueueWaitIdle.");
3158
Dustin Graves48458142016-04-29 16:11:55 -06003159 if ((m_device->queue_props.empty()) ||
3160 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003161 return;
3162
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003163 m_errorMonitor->ExpectSuccess();
3164
3165 VkFence fence;
3166 VkFenceCreateInfo fence_create_info{};
3167 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3168 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3169
3170 VkSemaphore semaphore;
3171 VkSemaphoreCreateInfo semaphore_create_info{};
3172 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3173 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3174 &semaphore);
3175
3176 VkCommandPool command_pool;
3177 VkCommandPoolCreateInfo pool_create_info{};
3178 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3179 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3180 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3181 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3182 &command_pool);
3183
3184 VkCommandBuffer command_buffer[2];
3185 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3186 command_buffer_allocate_info.sType =
3187 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3188 command_buffer_allocate_info.commandPool = command_pool;
3189 command_buffer_allocate_info.commandBufferCount = 2;
3190 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3191 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3192 command_buffer);
3193
3194 VkQueue queue = VK_NULL_HANDLE;
3195 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3196 1, &queue);
3197
3198 {
3199 VkCommandBufferBeginInfo begin_info{};
3200 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3201 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3202
3203 vkCmdPipelineBarrier(command_buffer[0],
3204 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3205 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3206 0, nullptr, 0, nullptr);
3207
3208 VkViewport viewport{};
3209 viewport.maxDepth = 1.0f;
3210 viewport.minDepth = 0.0f;
3211 viewport.width = 512;
3212 viewport.height = 512;
3213 viewport.x = 0;
3214 viewport.y = 0;
3215 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3216 vkEndCommandBuffer(command_buffer[0]);
3217 }
3218 {
3219 VkCommandBufferBeginInfo begin_info{};
3220 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3221 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3222
3223 VkViewport viewport{};
3224 viewport.maxDepth = 1.0f;
3225 viewport.minDepth = 0.0f;
3226 viewport.width = 512;
3227 viewport.height = 512;
3228 viewport.x = 0;
3229 viewport.y = 0;
3230 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3231 vkEndCommandBuffer(command_buffer[1]);
3232 }
3233 {
3234 VkSubmitInfo submit_info{};
3235 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3236 submit_info.commandBufferCount = 1;
3237 submit_info.pCommandBuffers = &command_buffer[0];
3238 submit_info.signalSemaphoreCount = 1;
3239 submit_info.pSignalSemaphores = &semaphore;
3240 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3241 }
3242 {
3243 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3244 VkSubmitInfo submit_info{};
3245 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3246 submit_info.commandBufferCount = 1;
3247 submit_info.pCommandBuffers = &command_buffer[1];
3248 submit_info.waitSemaphoreCount = 1;
3249 submit_info.pWaitSemaphores = &semaphore;
3250 submit_info.pWaitDstStageMask = flags;
3251 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3252 }
3253
3254 vkQueueWaitIdle(m_device->m_queue);
3255
3256 vkDestroyFence(m_device->device(), fence, nullptr);
3257 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3258 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3259 &command_buffer[0]);
3260 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3261
3262 m_errorMonitor->VerifyNotFound();
3263}
3264
3265// This is a positive test. No errors should be generated.
3266TEST_F(VkLayerTest,
3267 TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
3268
3269 TEST_DESCRIPTION(
3270 "Two command buffers, each in a separate QueueSubmit call "
3271 "submitted on separate queues, the second having a fence"
3272 "followed by two consecutive WaitForFences calls on the same fence.");
3273
Dustin Graves48458142016-04-29 16:11:55 -06003274 if ((m_device->queue_props.empty()) ||
3275 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003276 return;
3277
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003278 m_errorMonitor->ExpectSuccess();
3279
3280 VkFence fence;
3281 VkFenceCreateInfo fence_create_info{};
3282 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3283 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3284
3285 VkSemaphore semaphore;
3286 VkSemaphoreCreateInfo semaphore_create_info{};
3287 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3288 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3289 &semaphore);
3290
3291 VkCommandPool command_pool;
3292 VkCommandPoolCreateInfo pool_create_info{};
3293 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3294 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3295 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3296 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3297 &command_pool);
3298
3299 VkCommandBuffer command_buffer[2];
3300 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3301 command_buffer_allocate_info.sType =
3302 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3303 command_buffer_allocate_info.commandPool = command_pool;
3304 command_buffer_allocate_info.commandBufferCount = 2;
3305 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3306 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3307 command_buffer);
3308
3309 VkQueue queue = VK_NULL_HANDLE;
3310 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3311 1, &queue);
3312
3313 {
3314 VkCommandBufferBeginInfo begin_info{};
3315 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3316 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3317
3318 vkCmdPipelineBarrier(command_buffer[0],
3319 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3320 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3321 0, nullptr, 0, nullptr);
3322
3323 VkViewport viewport{};
3324 viewport.maxDepth = 1.0f;
3325 viewport.minDepth = 0.0f;
3326 viewport.width = 512;
3327 viewport.height = 512;
3328 viewport.x = 0;
3329 viewport.y = 0;
3330 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3331 vkEndCommandBuffer(command_buffer[0]);
3332 }
3333 {
3334 VkCommandBufferBeginInfo begin_info{};
3335 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3336 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3337
3338 VkViewport viewport{};
3339 viewport.maxDepth = 1.0f;
3340 viewport.minDepth = 0.0f;
3341 viewport.width = 512;
3342 viewport.height = 512;
3343 viewport.x = 0;
3344 viewport.y = 0;
3345 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3346 vkEndCommandBuffer(command_buffer[1]);
3347 }
3348 {
3349 VkSubmitInfo submit_info{};
3350 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3351 submit_info.commandBufferCount = 1;
3352 submit_info.pCommandBuffers = &command_buffer[0];
3353 submit_info.signalSemaphoreCount = 1;
3354 submit_info.pSignalSemaphores = &semaphore;
3355 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3356 }
3357 {
3358 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3359 VkSubmitInfo submit_info{};
3360 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3361 submit_info.commandBufferCount = 1;
3362 submit_info.pCommandBuffers = &command_buffer[1];
3363 submit_info.waitSemaphoreCount = 1;
3364 submit_info.pWaitSemaphores = &semaphore;
3365 submit_info.pWaitDstStageMask = flags;
3366 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3367 }
3368
3369 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3370 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3371
3372 vkDestroyFence(m_device->device(), fence, nullptr);
3373 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3374 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3375 &command_buffer[0]);
3376 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3377
3378 m_errorMonitor->VerifyNotFound();
3379}
3380
3381// This is a positive test. No errors should be generated.
3382TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
3383
3384 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3385 "submitted on separate queues, the second having a fence, "
3386 "followed by a WaitForFences call.");
3387
Dustin Graves48458142016-04-29 16:11:55 -06003388 if ((m_device->queue_props.empty()) ||
3389 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003390 return;
3391
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003392 m_errorMonitor->ExpectSuccess();
3393
3394 VkFence fence;
3395 VkFenceCreateInfo fence_create_info{};
3396 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3397 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3398
3399 VkSemaphore semaphore;
3400 VkSemaphoreCreateInfo semaphore_create_info{};
3401 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3402 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3403 &semaphore);
3404
3405 VkCommandPool command_pool;
3406 VkCommandPoolCreateInfo pool_create_info{};
3407 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3408 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3409 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3410 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3411 &command_pool);
3412
3413 VkCommandBuffer command_buffer[2];
3414 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3415 command_buffer_allocate_info.sType =
3416 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3417 command_buffer_allocate_info.commandPool = command_pool;
3418 command_buffer_allocate_info.commandBufferCount = 2;
3419 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3420 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3421 command_buffer);
3422
3423 VkQueue queue = VK_NULL_HANDLE;
3424 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3425 1, &queue);
3426
3427
3428 {
3429 VkCommandBufferBeginInfo begin_info{};
3430 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3431 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3432
3433 vkCmdPipelineBarrier(command_buffer[0],
3434 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3435 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3436 0, nullptr, 0, nullptr);
3437
3438 VkViewport viewport{};
3439 viewport.maxDepth = 1.0f;
3440 viewport.minDepth = 0.0f;
3441 viewport.width = 512;
3442 viewport.height = 512;
3443 viewport.x = 0;
3444 viewport.y = 0;
3445 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3446 vkEndCommandBuffer(command_buffer[0]);
3447 }
3448 {
3449 VkCommandBufferBeginInfo begin_info{};
3450 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3451 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3452
3453 VkViewport viewport{};
3454 viewport.maxDepth = 1.0f;
3455 viewport.minDepth = 0.0f;
3456 viewport.width = 512;
3457 viewport.height = 512;
3458 viewport.x = 0;
3459 viewport.y = 0;
3460 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3461 vkEndCommandBuffer(command_buffer[1]);
3462 }
3463 {
3464 VkSubmitInfo submit_info{};
3465 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3466 submit_info.commandBufferCount = 1;
3467 submit_info.pCommandBuffers = &command_buffer[0];
3468 submit_info.signalSemaphoreCount = 1;
3469 submit_info.pSignalSemaphores = &semaphore;
3470 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3471 }
3472 {
3473 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3474 VkSubmitInfo submit_info{};
3475 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3476 submit_info.commandBufferCount = 1;
3477 submit_info.pCommandBuffers = &command_buffer[1];
3478 submit_info.waitSemaphoreCount = 1;
3479 submit_info.pWaitSemaphores = &semaphore;
3480 submit_info.pWaitDstStageMask = flags;
3481 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3482 }
3483
3484 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3485
3486 vkDestroyFence(m_device->device(), fence, nullptr);
3487 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3488 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3489 &command_buffer[0]);
3490 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3491
3492 m_errorMonitor->VerifyNotFound();
3493}
3494
3495// This is a positive test. No errors should be generated.
3496TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
3497
3498 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3499 "on the same queue, sharing a signal/wait semaphore, the "
3500 "second having a fence, "
3501 "followed by a WaitForFences call.");
3502
3503 m_errorMonitor->ExpectSuccess();
3504
3505 VkFence fence;
3506 VkFenceCreateInfo fence_create_info{};
3507 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3508 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3509
3510 VkSemaphore semaphore;
3511 VkSemaphoreCreateInfo semaphore_create_info{};
3512 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3513 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3514 &semaphore);
3515
3516 VkCommandPool command_pool;
3517 VkCommandPoolCreateInfo pool_create_info{};
3518 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3519 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3520 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3521 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3522 &command_pool);
3523
3524 VkCommandBuffer command_buffer[2];
3525 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3526 command_buffer_allocate_info.sType =
3527 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3528 command_buffer_allocate_info.commandPool = command_pool;
3529 command_buffer_allocate_info.commandBufferCount = 2;
3530 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3531 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3532 command_buffer);
3533
3534 {
3535 VkCommandBufferBeginInfo begin_info{};
3536 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3537 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3538
3539 vkCmdPipelineBarrier(command_buffer[0],
3540 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3541 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3542 0, nullptr, 0, nullptr);
3543
3544 VkViewport viewport{};
3545 viewport.maxDepth = 1.0f;
3546 viewport.minDepth = 0.0f;
3547 viewport.width = 512;
3548 viewport.height = 512;
3549 viewport.x = 0;
3550 viewport.y = 0;
3551 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3552 vkEndCommandBuffer(command_buffer[0]);
3553 }
3554 {
3555 VkCommandBufferBeginInfo begin_info{};
3556 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3557 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3558
3559 VkViewport viewport{};
3560 viewport.maxDepth = 1.0f;
3561 viewport.minDepth = 0.0f;
3562 viewport.width = 512;
3563 viewport.height = 512;
3564 viewport.x = 0;
3565 viewport.y = 0;
3566 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3567 vkEndCommandBuffer(command_buffer[1]);
3568 }
3569 {
3570 VkSubmitInfo submit_info{};
3571 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3572 submit_info.commandBufferCount = 1;
3573 submit_info.pCommandBuffers = &command_buffer[0];
3574 submit_info.signalSemaphoreCount = 1;
3575 submit_info.pSignalSemaphores = &semaphore;
3576 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3577 }
3578 {
3579 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3580 VkSubmitInfo submit_info{};
3581 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3582 submit_info.commandBufferCount = 1;
3583 submit_info.pCommandBuffers = &command_buffer[1];
3584 submit_info.waitSemaphoreCount = 1;
3585 submit_info.pWaitSemaphores = &semaphore;
3586 submit_info.pWaitDstStageMask = flags;
3587 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3588 }
3589
3590 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3591
3592 vkDestroyFence(m_device->device(), fence, nullptr);
3593 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3594 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3595 &command_buffer[0]);
3596 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3597
3598 m_errorMonitor->VerifyNotFound();
3599}
3600
3601// This is a positive test. No errors should be generated.
3602TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
3603
3604 TEST_DESCRIPTION(
3605 "Two command buffers, each in a separate QueueSubmit call "
3606 "on the same queue, no fences, followed by a third QueueSubmit with NO "
3607 "SubmitInfos but with a fence, followed by a WaitForFences call.");
3608
3609 m_errorMonitor->ExpectSuccess();
3610
3611 VkFence fence;
3612 VkFenceCreateInfo fence_create_info{};
3613 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3614 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3615
3616 VkCommandPool command_pool;
3617 VkCommandPoolCreateInfo pool_create_info{};
3618 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3619 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3620 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3621 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3622 &command_pool);
3623
3624 VkCommandBuffer command_buffer[2];
3625 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3626 command_buffer_allocate_info.sType =
3627 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3628 command_buffer_allocate_info.commandPool = command_pool;
3629 command_buffer_allocate_info.commandBufferCount = 2;
3630 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3631 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3632 command_buffer);
3633
3634 {
3635 VkCommandBufferBeginInfo begin_info{};
3636 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3637 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3638
3639 vkCmdPipelineBarrier(command_buffer[0],
3640 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3641 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3642 0, nullptr, 0, nullptr);
3643
3644 VkViewport viewport{};
3645 viewport.maxDepth = 1.0f;
3646 viewport.minDepth = 0.0f;
3647 viewport.width = 512;
3648 viewport.height = 512;
3649 viewport.x = 0;
3650 viewport.y = 0;
3651 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3652 vkEndCommandBuffer(command_buffer[0]);
3653 }
3654 {
3655 VkCommandBufferBeginInfo begin_info{};
3656 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3657 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3658
3659 VkViewport viewport{};
3660 viewport.maxDepth = 1.0f;
3661 viewport.minDepth = 0.0f;
3662 viewport.width = 512;
3663 viewport.height = 512;
3664 viewport.x = 0;
3665 viewport.y = 0;
3666 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3667 vkEndCommandBuffer(command_buffer[1]);
3668 }
3669 {
3670 VkSubmitInfo submit_info{};
3671 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3672 submit_info.commandBufferCount = 1;
3673 submit_info.pCommandBuffers = &command_buffer[0];
3674 submit_info.signalSemaphoreCount = 0;
3675 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
3676 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3677 }
3678 {
3679 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3680 VkSubmitInfo submit_info{};
3681 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3682 submit_info.commandBufferCount = 1;
3683 submit_info.pCommandBuffers = &command_buffer[1];
3684 submit_info.waitSemaphoreCount = 0;
3685 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
3686 submit_info.pWaitDstStageMask = flags;
3687 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3688 }
3689
3690 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
3691
3692 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3693
3694 vkDestroyFence(m_device->device(), fence, nullptr);
3695 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3696 &command_buffer[0]);
3697 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3698
3699 m_errorMonitor->VerifyNotFound();
3700}
3701
3702// This is a positive test. No errors should be generated.
3703TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
3704
3705 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3706 "on the same queue, the second having a fence, followed "
3707 "by a WaitForFences call.");
3708
3709 m_errorMonitor->ExpectSuccess();
3710
3711 VkFence fence;
3712 VkFenceCreateInfo fence_create_info{};
3713 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3714 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3715
3716 VkCommandPool command_pool;
3717 VkCommandPoolCreateInfo pool_create_info{};
3718 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3719 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3720 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3721 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3722 &command_pool);
3723
3724 VkCommandBuffer command_buffer[2];
3725 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3726 command_buffer_allocate_info.sType =
3727 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3728 command_buffer_allocate_info.commandPool = command_pool;
3729 command_buffer_allocate_info.commandBufferCount = 2;
3730 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3731 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3732 command_buffer);
3733
3734 {
3735 VkCommandBufferBeginInfo begin_info{};
3736 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3737 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3738
3739 vkCmdPipelineBarrier(command_buffer[0],
3740 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3741 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3742 0, nullptr, 0, nullptr);
3743
3744 VkViewport viewport{};
3745 viewport.maxDepth = 1.0f;
3746 viewport.minDepth = 0.0f;
3747 viewport.width = 512;
3748 viewport.height = 512;
3749 viewport.x = 0;
3750 viewport.y = 0;
3751 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3752 vkEndCommandBuffer(command_buffer[0]);
3753 }
3754 {
3755 VkCommandBufferBeginInfo begin_info{};
3756 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3757 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3758
3759 VkViewport viewport{};
3760 viewport.maxDepth = 1.0f;
3761 viewport.minDepth = 0.0f;
3762 viewport.width = 512;
3763 viewport.height = 512;
3764 viewport.x = 0;
3765 viewport.y = 0;
3766 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3767 vkEndCommandBuffer(command_buffer[1]);
3768 }
3769 {
3770 VkSubmitInfo submit_info{};
3771 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3772 submit_info.commandBufferCount = 1;
3773 submit_info.pCommandBuffers = &command_buffer[0];
3774 submit_info.signalSemaphoreCount = 0;
3775 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
3776 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3777 }
3778 {
3779 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3780 VkSubmitInfo submit_info{};
3781 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3782 submit_info.commandBufferCount = 1;
3783 submit_info.pCommandBuffers = &command_buffer[1];
3784 submit_info.waitSemaphoreCount = 0;
3785 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
3786 submit_info.pWaitDstStageMask = flags;
3787 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3788 }
3789
3790 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3791
3792 vkDestroyFence(m_device->device(), fence, nullptr);
3793 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3794 &command_buffer[0]);
3795 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3796
3797 m_errorMonitor->VerifyNotFound();
3798}
3799
3800// This is a positive test. No errors should be generated.
3801TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
3802
3803 TEST_DESCRIPTION(
3804 "Two command buffers each in a separate SubmitInfo sent in a single "
3805 "QueueSubmit call followed by a WaitForFences call.");
3806
3807 m_errorMonitor->ExpectSuccess();
3808
3809 VkFence fence;
3810 VkFenceCreateInfo fence_create_info{};
3811 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3812 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3813
3814 VkSemaphore semaphore;
3815 VkSemaphoreCreateInfo semaphore_create_info{};
3816 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3817 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3818 &semaphore);
3819
3820 VkCommandPool command_pool;
3821 VkCommandPoolCreateInfo pool_create_info{};
3822 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3823 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3824 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3825 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3826 &command_pool);
3827
3828 VkCommandBuffer command_buffer[2];
3829 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3830 command_buffer_allocate_info.sType =
3831 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3832 command_buffer_allocate_info.commandPool = command_pool;
3833 command_buffer_allocate_info.commandBufferCount = 2;
3834 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3835 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3836 command_buffer);
3837
3838 {
3839 VkCommandBufferBeginInfo begin_info{};
3840 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3841 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3842
3843 vkCmdPipelineBarrier(command_buffer[0],
3844 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3845 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3846 0, nullptr, 0, nullptr);
3847
3848 VkViewport viewport{};
3849 viewport.maxDepth = 1.0f;
3850 viewport.minDepth = 0.0f;
3851 viewport.width = 512;
3852 viewport.height = 512;
3853 viewport.x = 0;
3854 viewport.y = 0;
3855 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3856 vkEndCommandBuffer(command_buffer[0]);
3857 }
3858 {
3859 VkCommandBufferBeginInfo begin_info{};
3860 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3861 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3862
3863 VkViewport viewport{};
3864 viewport.maxDepth = 1.0f;
3865 viewport.minDepth = 0.0f;
3866 viewport.width = 512;
3867 viewport.height = 512;
3868 viewport.x = 0;
3869 viewport.y = 0;
3870 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3871 vkEndCommandBuffer(command_buffer[1]);
3872 }
3873 {
3874 VkSubmitInfo submit_info[2];
3875 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3876
3877 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3878 submit_info[0].pNext = NULL;
3879 submit_info[0].commandBufferCount = 1;
3880 submit_info[0].pCommandBuffers = &command_buffer[0];
3881 submit_info[0].signalSemaphoreCount = 1;
3882 submit_info[0].pSignalSemaphores = &semaphore;
3883 submit_info[0].waitSemaphoreCount = 0;
3884 submit_info[0].pWaitSemaphores = NULL;
3885 submit_info[0].pWaitDstStageMask = 0;
3886
3887 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3888 submit_info[1].pNext = NULL;
3889 submit_info[1].commandBufferCount = 1;
3890 submit_info[1].pCommandBuffers = &command_buffer[1];
3891 submit_info[1].waitSemaphoreCount = 1;
3892 submit_info[1].pWaitSemaphores = &semaphore;
3893 submit_info[1].pWaitDstStageMask = flags;
3894 submit_info[1].signalSemaphoreCount = 0;
3895 submit_info[1].pSignalSemaphores = NULL;
3896 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
3897 }
3898
3899 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3900
3901 vkDestroyFence(m_device->device(), fence, nullptr);
3902 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3903 &command_buffer[0]);
3904 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3905
3906 m_errorMonitor->VerifyNotFound();
3907}
3908
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003909TEST_F(VkLayerTest, DynamicStatesNotBound) {
3910 TEST_DESCRIPTION(
3911 "Run a series of simple draw calls to validate all the different "
3912 "failure cases that can occur when dynamic state is required but not "
3913 "correctly bound."
3914 "Here are the different dynamic state cases verified by this test:\n"
3915 "-Line Width\n-Depth Bias\n-Viewport State\n-Scissor State\n-Blend "
3916 "State\n-Depth Bounds\n-Stencil Read Mask\n-Stencil Write "
3917 "Mask\n-Stencil Reference");
3918
3919 // Dynamic line width
Karl Schultz6addd812016-02-02 17:17:23 -07003920 m_errorMonitor->SetDesiredFailureMsg(
3921 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003922 "Dynamic line width state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003923 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3924 BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003925 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003926 // Dynamic depth bias
Karl Schultz6addd812016-02-02 17:17:23 -07003927 m_errorMonitor->SetDesiredFailureMsg(
3928 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003929 "Dynamic depth bias state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003930 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3931 BsoFailDepthBias);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003932 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003933 // Dynamic viewport state
Karl Schultz6addd812016-02-02 17:17:23 -07003934 m_errorMonitor->SetDesiredFailureMsg(
3935 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003936 "Dynamic viewport state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003937 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3938 BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003939 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003940 // Dynamic scissor state
Karl Schultz6addd812016-02-02 17:17:23 -07003941 m_errorMonitor->SetDesiredFailureMsg(
3942 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003943 "Dynamic scissor state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003944 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3945 BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003946 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003947 // Dynamic blend state
Karl Schultz6addd812016-02-02 17:17:23 -07003948 m_errorMonitor->SetDesiredFailureMsg(
3949 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003950 "Dynamic depth bounds state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003951 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3952 BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003953 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003954 // Dynamic stencil read mask
Karl Schultz6addd812016-02-02 17:17:23 -07003955 m_errorMonitor->SetDesiredFailureMsg(
3956 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003957 "Dynamic stencil read mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003958 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3959 BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003960 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003961 // Dynamic stencil write mask
Karl Schultz6addd812016-02-02 17:17:23 -07003962 m_errorMonitor->SetDesiredFailureMsg(
3963 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003964 "Dynamic stencil write mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003965 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3966 BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003967 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003968 // Dynamic stencil reference
Karl Schultz6addd812016-02-02 17:17:23 -07003969 m_errorMonitor->SetDesiredFailureMsg(
3970 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003971 "Dynamic stencil reference state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003972 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3973 BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003974 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003975}
3976
Karl Schultz6addd812016-02-02 17:17:23 -07003977TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003978 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003979
Karl Schultz6addd812016-02-02 17:17:23 -07003980 m_errorMonitor->SetDesiredFailureMsg(
3981 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3982 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3983 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003984
3985 VkFenceCreateInfo fenceInfo = {};
3986 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3987 fenceInfo.pNext = NULL;
3988 fenceInfo.flags = 0;
3989
3990 ASSERT_NO_FATAL_FAILURE(InitState());
3991 ASSERT_NO_FATAL_FAILURE(InitViewport());
3992 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3993
Karl Schultz6addd812016-02-02 17:17:23 -07003994 // We luck out b/c by default the framework creates CB w/ the
3995 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003996 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07003997 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
3998 m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003999 EndCommandBuffer();
4000
4001 testFence.init(*m_device, fenceInfo);
4002
4003 // Bypass framework since it does the waits automatically
4004 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004005 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004006 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4007 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004008 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004009 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004010 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004011 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004012 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004013 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004014 submit_info.pSignalSemaphores = NULL;
4015
Karl Schultz6addd812016-02-02 17:17:23 -07004016 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
4017 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004018
Karl Schultz6addd812016-02-02 17:17:23 -07004019 // Cause validation error by re-submitting cmd buffer that should only be
4020 // submitted once
4021 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004022
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004023 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004024}
4025
Karl Schultz6addd812016-02-02 17:17:23 -07004026TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004027 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07004028 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004029
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004031 "Unable to allocate 1 descriptors of "
4032 "type "
4033 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004034
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004035 ASSERT_NO_FATAL_FAILURE(InitState());
4036 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004037
Karl Schultz6addd812016-02-02 17:17:23 -07004038 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4039 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004040 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004041 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
4042 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004043
4044 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004045 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4046 ds_pool_ci.pNext = NULL;
4047 ds_pool_ci.flags = 0;
4048 ds_pool_ci.maxSets = 1;
4049 ds_pool_ci.poolSizeCount = 1;
4050 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004051
4052 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004053 err =
4054 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004055 ASSERT_VK_SUCCESS(err);
4056
4057 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004058 dsl_binding.binding = 0;
4059 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4060 dsl_binding.descriptorCount = 1;
4061 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4062 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004063
4064 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004065 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4066 ds_layout_ci.pNext = NULL;
4067 ds_layout_ci.bindingCount = 1;
4068 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004069
4070 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004071 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4072 &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004073 ASSERT_VK_SUCCESS(err);
4074
4075 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004076 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004077 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004078 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004079 alloc_info.descriptorPool = ds_pool;
4080 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004081 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4082 &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004083
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004084 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004085
Chia-I Wuf7458c52015-10-26 21:10:41 +08004086 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4087 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004088}
4089
Karl Schultz6addd812016-02-02 17:17:23 -07004090TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4091 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004092
Karl Schultz6addd812016-02-02 17:17:23 -07004093 m_errorMonitor->SetDesiredFailureMsg(
4094 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4095 "It is invalid to call vkFreeDescriptorSets() with a pool created "
4096 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004097
Tobin Ehlise735c692015-10-08 13:13:50 -06004098 ASSERT_NO_FATAL_FAILURE(InitState());
4099 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004100
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004101 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004102 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4103 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004104
4105 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004106 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4107 ds_pool_ci.pNext = NULL;
4108 ds_pool_ci.maxSets = 1;
4109 ds_pool_ci.poolSizeCount = 1;
4110 ds_pool_ci.flags = 0;
4111 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4112 // app can only call vkResetDescriptorPool on this pool.;
4113 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004114
4115 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004116 err =
4117 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004118 ASSERT_VK_SUCCESS(err);
4119
4120 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004121 dsl_binding.binding = 0;
4122 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4123 dsl_binding.descriptorCount = 1;
4124 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4125 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004126
4127 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004128 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4129 ds_layout_ci.pNext = NULL;
4130 ds_layout_ci.bindingCount = 1;
4131 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004132
4133 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004134 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4135 &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004136 ASSERT_VK_SUCCESS(err);
4137
4138 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004139 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004140 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004141 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004142 alloc_info.descriptorPool = ds_pool;
4143 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004144 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4145 &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004146 ASSERT_VK_SUCCESS(err);
4147
4148 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004149 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004150
Chia-I Wuf7458c52015-10-26 21:10:41 +08004151 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4152 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004153}
4154
Karl Schultz6addd812016-02-02 17:17:23 -07004155TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004156 // Attempt to clear Descriptor Pool with bad object.
4157 // ObjectTracker should catch this.
4158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4159 "Invalid VkDescriptorPool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004160 uint64_t fake_pool_handle = 0xbaad6001;
4161 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4162 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004163 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004164}
4165
Karl Schultz6addd812016-02-02 17:17:23 -07004166TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004167 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4168 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004169 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004170 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004171
4172 uint64_t fake_set_handle = 0xbaad6001;
4173 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004174 VkResult err;
4175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4176 "Invalid VkDescriptorSet Object 0xbaad6001");
4177
4178 ASSERT_NO_FATAL_FAILURE(InitState());
4179
4180 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4181 layout_bindings[0].binding = 0;
4182 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4183 layout_bindings[0].descriptorCount = 1;
4184 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4185 layout_bindings[0].pImmutableSamplers = NULL;
4186
4187 VkDescriptorSetLayout descriptor_set_layout;
4188 VkDescriptorSetLayoutCreateInfo dslci = {};
4189 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4190 dslci.pNext = NULL;
4191 dslci.bindingCount = 1;
4192 dslci.pBindings = layout_bindings;
4193 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004194 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004195
4196 VkPipelineLayout pipeline_layout;
4197 VkPipelineLayoutCreateInfo plci = {};
4198 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4199 plci.pNext = NULL;
4200 plci.setLayoutCount = 1;
4201 plci.pSetLayouts = &descriptor_set_layout;
4202 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004203 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004204
4205 BeginCommandBuffer();
4206 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004207 pipeline_layout, 0, 1, &bad_set, 0, NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004208 m_errorMonitor->VerifyFound();
4209 EndCommandBuffer();
4210 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4211 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004212}
4213
Karl Schultz6addd812016-02-02 17:17:23 -07004214TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004215 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4216 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004217 uint64_t fake_layout_handle = 0xbaad6001;
4218 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4220 "Invalid VkDescriptorSetLayout Object 0xbaad6001");
4221
4222 VkPipelineLayout pipeline_layout;
4223 VkPipelineLayoutCreateInfo plci = {};
4224 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4225 plci.pNext = NULL;
4226 plci.setLayoutCount = 1;
4227 plci.pSetLayouts = &bad_layout;
4228 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4229
4230 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004231}
4232
Karl Schultz6addd812016-02-02 17:17:23 -07004233TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004234 // Attempt to bind an invalid Pipeline to a valid Command Buffer
4235 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004236 // Create a valid cmd buffer
4237 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004238 uint64_t fake_pipeline_handle = 0xbaad6001;
4239 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4241 "Invalid VkPipeline Object 0xbaad6001");
4242 ASSERT_NO_FATAL_FAILURE(InitState());
4243 BeginCommandBuffer();
4244 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4245 VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
4246 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004247
4248 // Now issue a draw call with no pipeline bound
4249 m_errorMonitor->SetDesiredFailureMsg(
4250 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4251 "At Draw/Dispatch time no valid VkPipeline is bound!");
4252 ASSERT_NO_FATAL_FAILURE(InitState());
4253 BeginCommandBuffer();
4254 Draw(1, 0, 0, 0);
4255 m_errorMonitor->VerifyFound();
4256 // Finally same check once more but with Dispatch/Compute
4257 m_errorMonitor->SetDesiredFailureMsg(
4258 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4259 "At Draw/Dispatch time no valid VkPipeline is bound!");
4260 ASSERT_NO_FATAL_FAILURE(InitState());
4261 BeginCommandBuffer();
4262 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
4263 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004264}
4265
Karl Schultz6addd812016-02-02 17:17:23 -07004266TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
4267 // Create and update CommandBuffer then call QueueSubmit w/o calling End on
4268 // CommandBuffer
4269 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004270
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07004271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004272 " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004273
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004274 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06004275 ASSERT_NO_FATAL_FAILURE(InitViewport());
4276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004277 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004278 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4279 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004280
4281 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004282 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4283 ds_pool_ci.pNext = NULL;
4284 ds_pool_ci.maxSets = 1;
4285 ds_pool_ci.poolSizeCount = 1;
4286 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06004287
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004288 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004289 err =
4290 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004291 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004292
Tony Barboureb254902015-07-15 12:50:33 -06004293 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004294 dsl_binding.binding = 0;
4295 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4296 dsl_binding.descriptorCount = 1;
4297 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4298 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004299
Tony Barboureb254902015-07-15 12:50:33 -06004300 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004301 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4302 ds_layout_ci.pNext = NULL;
4303 ds_layout_ci.bindingCount = 1;
4304 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004305 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004306 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4307 &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004308 ASSERT_VK_SUCCESS(err);
4309
4310 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004311 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004312 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004313 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004314 alloc_info.descriptorPool = ds_pool;
4315 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004316 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4317 &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004318 ASSERT_VK_SUCCESS(err);
4319
Tony Barboureb254902015-07-15 12:50:33 -06004320 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004321 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4322 pipeline_layout_ci.pNext = NULL;
4323 pipeline_layout_ci.setLayoutCount = 1;
4324 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004325
4326 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004327 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4328 &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004329 ASSERT_VK_SUCCESS(err);
4330
Karl Schultz6addd812016-02-02 17:17:23 -07004331 VkShaderObj vs(m_device, bindStateVertShaderText,
4332 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06004333 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07004334 // on more devices
4335 VkShaderObj fs(m_device, bindStateFragShaderText,
4336 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004337
Tony Barbourc95e4ac2015-08-04 17:05:26 -06004338 VkPipelineObj pipe(m_device);
4339 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06004340 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06004341 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06004342 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004343
4344 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004345 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4346 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4347 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4348 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4349 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004350
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004351 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06004352
Chia-I Wuf7458c52015-10-26 21:10:41 +08004353 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4354 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4355 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004356}
4357
Karl Schultz6addd812016-02-02 17:17:23 -07004358TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004359 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07004360 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004361
Karl Schultz6addd812016-02-02 17:17:23 -07004362 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004363 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
4364 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004365
4366 ASSERT_NO_FATAL_FAILURE(InitState());
4367 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004368 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
4369 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004370
4371 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004372 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4373 ds_pool_ci.pNext = NULL;
4374 ds_pool_ci.maxSets = 1;
4375 ds_pool_ci.poolSizeCount = 1;
4376 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004377
4378 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004379 err =
4380 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004381 ASSERT_VK_SUCCESS(err);
4382
4383 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004384 dsl_binding.binding = 0;
4385 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
4386 dsl_binding.descriptorCount = 1;
4387 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4388 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004389
4390 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004391 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4392 ds_layout_ci.pNext = NULL;
4393 ds_layout_ci.bindingCount = 1;
4394 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004395 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004396 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4397 &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004398 ASSERT_VK_SUCCESS(err);
4399
4400 VkDescriptorSet descriptorSet;
4401 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004402 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004403 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004404 alloc_info.descriptorPool = ds_pool;
4405 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004406 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4407 &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004408 ASSERT_VK_SUCCESS(err);
4409
Karl Schultz6addd812016-02-02 17:17:23 -07004410 VkBufferView view =
4411 (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004412 VkWriteDescriptorSet descriptor_write;
4413 memset(&descriptor_write, 0, sizeof(descriptor_write));
4414 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4415 descriptor_write.dstSet = descriptorSet;
4416 descriptor_write.dstBinding = 0;
4417 descriptor_write.descriptorCount = 1;
4418 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
4419 descriptor_write.pTexelBufferView = &view;
4420
4421 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4422
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004423 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004424
4425 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4426 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4427}
4428
Karl Schultz6addd812016-02-02 17:17:23 -07004429TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
4430 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
4431 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07004432 // 1. No dynamicOffset supplied
4433 // 2. Too many dynamicOffsets supplied
4434 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07004435 VkResult err;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004437 " requires 1 dynamicOffsets, but only "
4438 "0 dynamicOffsets are left in "
4439 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004440
4441 ASSERT_NO_FATAL_FAILURE(InitState());
4442 ASSERT_NO_FATAL_FAILURE(InitViewport());
4443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4444
4445 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004446 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
4447 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004448
4449 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004450 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4451 ds_pool_ci.pNext = NULL;
4452 ds_pool_ci.maxSets = 1;
4453 ds_pool_ci.poolSizeCount = 1;
4454 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004455
4456 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004457 err =
4458 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004459 ASSERT_VK_SUCCESS(err);
4460
4461 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004462 dsl_binding.binding = 0;
4463 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
4464 dsl_binding.descriptorCount = 1;
4465 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4466 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004467
4468 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004469 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4470 ds_layout_ci.pNext = NULL;
4471 ds_layout_ci.bindingCount = 1;
4472 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004473 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004474 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4475 &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004476 ASSERT_VK_SUCCESS(err);
4477
4478 VkDescriptorSet descriptorSet;
4479 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004480 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004481 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004482 alloc_info.descriptorPool = ds_pool;
4483 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004484 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4485 &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004486 ASSERT_VK_SUCCESS(err);
4487
4488 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004489 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4490 pipeline_layout_ci.pNext = NULL;
4491 pipeline_layout_ci.setLayoutCount = 1;
4492 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004493
4494 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004495 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4496 &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004497 ASSERT_VK_SUCCESS(err);
4498
4499 // Create a buffer to update the descriptor with
4500 uint32_t qfi = 0;
4501 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004502 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4503 buffCI.size = 1024;
4504 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4505 buffCI.queueFamilyIndexCount = 1;
4506 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004507
4508 VkBuffer dyub;
4509 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4510 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004511 // Allocate memory and bind to buffer so we can make it to the appropriate
4512 // error
4513 VkMemoryAllocateInfo mem_alloc = {};
4514 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4515 mem_alloc.pNext = NULL;
4516 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12004517 mem_alloc.memoryTypeIndex = 0;
4518
4519 VkMemoryRequirements memReqs;
4520 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
4521 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc,
4522 0);
4523 if (!pass) {
4524 vkDestroyBuffer(m_device->device(), dyub, NULL);
4525 return;
4526 }
4527
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004528 VkDeviceMemory mem;
4529 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4530 ASSERT_VK_SUCCESS(err);
4531 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4532 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004533 // Correctly update descriptor to avoid "NOT_UPDATED" error
4534 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004535 buffInfo.buffer = dyub;
4536 buffInfo.offset = 0;
4537 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004538
4539 VkWriteDescriptorSet descriptor_write;
4540 memset(&descriptor_write, 0, sizeof(descriptor_write));
4541 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4542 descriptor_write.dstSet = descriptorSet;
4543 descriptor_write.dstBinding = 0;
4544 descriptor_write.descriptorCount = 1;
4545 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
4546 descriptor_write.pBufferInfo = &buffInfo;
4547
4548 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4549
4550 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004551 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4552 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4553 1, &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004554 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07004555 uint32_t pDynOff[2] = {512, 756};
4556 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Karl Schultz6addd812016-02-02 17:17:23 -07004557 m_errorMonitor->SetDesiredFailureMsg(
4558 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07004559 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
Karl Schultz6addd812016-02-02 17:17:23 -07004560 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4561 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4562 1, &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12004563 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07004564 // Finally cause error due to dynamicOffset being too big
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4566 " dynamic offset 512 combined with "
4567 "offset 0 and range 1024 that "
4568 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07004569 // Create PSO to be used for draw-time errors below
4570 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12004571 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07004572 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07004573 "out gl_PerVertex { \n"
4574 " vec4 gl_Position;\n"
4575 "};\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07004576 "void main(){\n"
4577 " gl_Position = vec4(1);\n"
4578 "}\n";
4579 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12004580 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07004581 "\n"
4582 "layout(location=0) out vec4 x;\n"
4583 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4584 "void main(){\n"
4585 " x = vec4(bar.y);\n"
4586 "}\n";
4587 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4588 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4589 VkPipelineObj pipe(m_device);
4590 pipe.AddShader(&vs);
4591 pipe.AddShader(&fs);
4592 pipe.AddColorAttachment();
4593 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4594
Karl Schultz6addd812016-02-02 17:17:23 -07004595 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4596 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4597 // This update should succeed, but offset size of 512 will overstep buffer
4598 // /w range 1024 & size 1024
4599 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4600 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4601 1, &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004602 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004603 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004604
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004605 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06004606 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004607
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004608 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4609 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4610}
4611
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004612TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004613 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004614 ASSERT_NO_FATAL_FAILURE(InitState());
4615 ASSERT_NO_FATAL_FAILURE(InitViewport());
4616 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4617
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004618 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004619 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004620 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4621 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4622 pipeline_layout_ci.pushConstantRangeCount = 1;
4623 pipeline_layout_ci.pPushConstantRanges = &pc_range;
4624
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004625 //
4626 // Check for invalid push constant ranges in pipeline layouts.
4627 //
4628 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06004629 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004630 char const *msg;
4631 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004632
Karl Schultzc81037d2016-05-12 08:11:23 -06004633 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
4634 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
4635 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
4636 "vkCreatePipelineLayout() call has push constants index 0 with "
4637 "size 0."},
4638 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
4639 "vkCreatePipelineLayout() call has push constants index 0 with "
4640 "size 1."},
4641 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
4642 "vkCreatePipelineLayout() call has push constants index 0 with "
4643 "size 1."},
4644 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
4645 "vkCreatePipelineLayout() call has push constants index 0 with "
4646 "size 0."},
4647 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
4648 "vkCreatePipelineLayout() call has push constants index 0 with "
4649 "offset 1. Offset must"},
4650 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
4651 "vkCreatePipelineLayout() call has push constants index 0 "
4652 "with offset "},
4653 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
4654 "vkCreatePipelineLayout() call has push constants "
4655 "index 0 with offset "},
4656 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
4657 "vkCreatePipelineLayout() call has push constants index 0 "
4658 "with offset "},
4659 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
4660 "vkCreatePipelineLayout() call has push "
4661 "constants index 0 with offset "},
4662 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
4663 "vkCreatePipelineLayout() call has push "
4664 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004665 }};
4666
4667 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06004668 for (const auto &iter : range_tests) {
4669 pc_range = iter.range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4671 iter.msg);
4672 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
4673 NULL, &pipeline_layout);
4674 m_errorMonitor->VerifyFound();
4675 if (VK_SUCCESS == err) {
4676 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4677 }
4678 }
4679
4680 // Check for invalid stage flag
4681 pc_range.offset = 0;
4682 pc_range.size = 16;
4683 pc_range.stageFlags = 0;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004684 m_errorMonitor->SetDesiredFailureMsg(
4685 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004686 "vkCreatePipelineLayout() call has no stageFlags set.");
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004687 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4688 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004689 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004690 if (VK_SUCCESS == err) {
4691 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4692 }
4693
4694 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06004695 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004696 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06004697 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004698 char const *msg;
4699 };
4700
Karl Schultzc81037d2016-05-12 08:11:23 -06004701 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004702 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4703 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4704 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4705 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4706 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4707 "vkCreatePipelineLayout() call has push constants with overlapping "
4708 "ranges: 0:[0, 4), 1:[0, 4)"},
4709 {
4710 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4711 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4712 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4713 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
4714 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
4715 "vkCreatePipelineLayout() call has push constants with "
4716 "overlapping "
4717 "ranges: 3:[12, 20), 4:[16, 20)",
4718 },
4719 {
4720 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4721 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
4722 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4723 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4724 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4725 "vkCreatePipelineLayout() call has push constants with "
4726 "overlapping "
4727 "ranges: 0:[16, 20), 1:[12, 20)",
4728 },
4729 {
4730 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4731 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4732 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4733 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
4734 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4735 "vkCreatePipelineLayout() call has push constants with "
4736 "overlapping "
4737 "ranges: 0:[16, 20), 3:[12, 20)",
4738 },
4739 {
4740 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4741 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
4742 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
4743 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
4744 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
4745 "vkCreatePipelineLayout() call has push constants with "
4746 "overlapping "
4747 "ranges: 0:[16, 20), 2:[4, 100)",
4748 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004749
Karl Schultzc81037d2016-05-12 08:11:23 -06004750 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004751 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06004752 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
4753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004754 iter.msg);
4755 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
4756 NULL, &pipeline_layout);
4757 m_errorMonitor->VerifyFound();
4758 if (VK_SUCCESS == err) {
4759 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4760 }
4761 }
4762
4763 // Run some positive tests to make sure overlap checking in the layer is OK
Karl Schultzc81037d2016-05-12 08:11:23 -06004764 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos =
4765 {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4766 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4767 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4768 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
4769 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
4770 ""},
4771 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
4772 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
4773 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
4774 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
4775 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4776 ""}}};
4777 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004778 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
4779 m_errorMonitor->ExpectSuccess();
4780 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
4781 NULL, &pipeline_layout);
4782 m_errorMonitor->VerifyNotFound();
4783 if (VK_SUCCESS == err) {
4784 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4785 }
4786 }
4787
4788 //
4789 // CmdPushConstants tests
4790 //
Karl Schultzc81037d2016-05-12 08:11:23 -06004791 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004792
4793 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzc81037d2016-05-12 08:11:23 -06004794 const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{
4795 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
4796 "vkCmdPushConstants() call has push constants with size 0. Size "
4797 "must be greater than zero and a multiple of 4."},
4798 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
4799 "vkCmdPushConstants() call has push constants with size 1. Size "
4800 "must be greater than zero and a multiple of 4."},
4801 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
4802 "vkCmdPushConstants() call has push constants with size 1. Size "
4803 "must be greater than zero and a multiple of 4."},
4804 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
4805 "vkCmdPushConstants() call has push constants with offset 1. "
4806 "Offset must be a multiple of 4."},
4807 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
4808 "vkCmdPushConstants() call has push constants with offset 1. "
4809 "Offset must be a multiple of 4."},
4810 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
4811 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
4812 "0x1 not within flag-matching ranges in pipeline layout"},
4813 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
4814 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
4815 "0x1 not within flag-matching ranges in pipeline layout"},
4816 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
4817 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
4818 "0x1 not within flag-matching ranges in pipeline layout"},
4819 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
4820 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
4821 "0x1 not within flag-matching ranges in pipeline layout"},
4822 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
4823 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
4824 "any of the ranges in pipeline layout"},
4825 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
4826 0, 16},
4827 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
4828 "any of the ranges in pipeline layout"},
4829 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004830 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004831 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004832 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004833 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004834 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004835 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004836 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004837 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004838 "vkCmdPushConstants() call has push constants with offset "},
4839 }};
4840
4841 // Two ranges for testing robustness
Karl Schultzc81037d2016-05-12 08:11:23 -06004842 const VkPushConstantRange pc_range2[] = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004843 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06004844 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004845 };
Karl Schultzc81037d2016-05-12 08:11:23 -06004846 pipeline_layout_ci.pushConstantRangeCount =
4847 sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004848 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004849 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4850 &pipeline_layout);
4851 ASSERT_VK_SUCCESS(err);
4852 BeginCommandBuffer();
Karl Schultzc81037d2016-05-12 08:11:23 -06004853 for (const auto &iter : cmd_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4855 iter.msg);
4856 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
Karl Schultzc81037d2016-05-12 08:11:23 -06004857 iter.range.stageFlags, iter.range.offset,
4858 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004859 m_errorMonitor->VerifyFound();
4860 }
4861
4862 // Check for invalid stage flag
4863 m_errorMonitor->SetDesiredFailureMsg(
4864 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4865 "vkCmdPushConstants() call has no stageFlags set.");
4866 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0,
Karl Schultzc81037d2016-05-12 08:11:23 -06004867 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004868 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06004869 EndCommandBuffer();
4870 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
4871 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004872
Karl Schultzc81037d2016-05-12 08:11:23 -06004873 // overlapping range tests with cmd
4874 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
4875 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
4876 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
4877 "0x1 not within flag-matching ranges in pipeline layout"},
4878 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4879 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
4880 "0x1 not within flag-matching ranges in pipeline layout"},
4881 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
4882 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
4883 "0x1 not within flag-matching ranges in pipeline layout"},
4884 }};
4885 const VkPushConstantRange pc_range3[] = {
4886 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
4887 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
4888 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4889 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
4890 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
4891 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
4892 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
4893 };
4894 pipeline_layout_ci.pushConstantRangeCount =
4895 sizeof(pc_range3) / sizeof(VkPushConstantRange);
4896 pipeline_layout_ci.pPushConstantRanges = pc_range3;
4897 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4898 &pipeline_layout);
4899 ASSERT_VK_SUCCESS(err);
4900 BeginCommandBuffer();
4901 for (const auto &iter : cmd_overlap_tests) {
4902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4903 iter.msg);
4904 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
4905 iter.range.stageFlags, iter.range.offset,
4906 iter.range.size, dummy_values);
4907 m_errorMonitor->VerifyFound();
4908 }
4909 EndCommandBuffer();
4910 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
4911 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4912
4913 // positive overlapping range tests with cmd
4914 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
4915 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
4916 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
4917 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
4918 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
4919 }};
4920 const VkPushConstantRange pc_range4[] = {
4921 {VK_SHADER_STAGE_VERTEX_BIT, 0, 64},
4922 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
4923 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
4924 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4925 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
4926 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
4927 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
4928 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
4929 };
4930 pipeline_layout_ci.pushConstantRangeCount =
4931 sizeof(pc_range4) / sizeof(VkPushConstantRange);
4932 pipeline_layout_ci.pPushConstantRanges = pc_range4;
4933 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4934 &pipeline_layout);
4935 ASSERT_VK_SUCCESS(err);
4936 BeginCommandBuffer();
4937 for (const auto &iter : cmd_overlap_tests_pos) {
4938 m_errorMonitor->ExpectSuccess();
4939 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
4940 iter.range.stageFlags, iter.range.offset,
4941 iter.range.size, dummy_values);
4942 m_errorMonitor->VerifyNotFound();
4943 }
4944 EndCommandBuffer();
4945 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004946 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4947}
4948
Karl Schultz6addd812016-02-02 17:17:23 -07004949TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07004950 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07004951 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07004952
4953 ASSERT_NO_FATAL_FAILURE(InitState());
4954 ASSERT_NO_FATAL_FAILURE(InitViewport());
4955 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4956
4957 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
4958 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004959 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4960 ds_type_count[0].descriptorCount = 10;
4961 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
4962 ds_type_count[1].descriptorCount = 2;
4963 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
4964 ds_type_count[2].descriptorCount = 2;
4965 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
4966 ds_type_count[3].descriptorCount = 5;
4967 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
4968 // type
4969 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4970 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4971 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07004972
4973 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004974 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4975 ds_pool_ci.pNext = NULL;
4976 ds_pool_ci.maxSets = 5;
4977 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
4978 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07004979
4980 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004981 err =
4982 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07004983 ASSERT_VK_SUCCESS(err);
4984
4985 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
4986 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004987 dsl_binding[0].binding = 0;
4988 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4989 dsl_binding[0].descriptorCount = 5;
4990 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4991 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07004992
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004993 // Create layout identical to set0 layout but w/ different stageFlags
4994 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004995 dsl_fs_stage_only.binding = 0;
4996 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4997 dsl_fs_stage_only.descriptorCount = 5;
4998 dsl_fs_stage_only.stageFlags =
4999 VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
5000 // bind time
5001 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005002 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005003 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5004 ds_layout_ci.pNext = NULL;
5005 ds_layout_ci.bindingCount = 1;
5006 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005007 static const uint32_t NUM_LAYOUTS = 4;
5008 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005009 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005010 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
5011 // layout for error case
5012 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5013 &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005014 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005015 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005016 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5017 &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005018 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005019 dsl_binding[0].binding = 0;
5020 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005021 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005022 dsl_binding[1].binding = 1;
5023 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5024 dsl_binding[1].descriptorCount = 2;
5025 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
5026 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005027 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005028 ds_layout_ci.bindingCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005029 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5030 &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005031 ASSERT_VK_SUCCESS(err);
5032 dsl_binding[0].binding = 0;
5033 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005034 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005035 ds_layout_ci.bindingCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07005036 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5037 &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005038 ASSERT_VK_SUCCESS(err);
5039 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005040 dsl_binding[0].descriptorCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005041 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5042 &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005043 ASSERT_VK_SUCCESS(err);
5044
5045 static const uint32_t NUM_SETS = 4;
5046 VkDescriptorSet descriptorSet[NUM_SETS] = {};
5047 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005048 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005049 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005050 alloc_info.descriptorPool = ds_pool;
5051 alloc_info.pSetLayouts = ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005052 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5053 descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005054 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005055 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005056 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005057 alloc_info.pSetLayouts = &ds_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005058 err =
5059 vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005060 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005061
5062 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005063 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5064 pipeline_layout_ci.pNext = NULL;
5065 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
5066 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005067
5068 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005069 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5070 &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005071 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005072 // Create pipelineLayout with only one setLayout
5073 pipeline_layout_ci.setLayoutCount = 1;
5074 VkPipelineLayout single_pipe_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005075 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5076 &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005077 ASSERT_VK_SUCCESS(err);
5078 // Create pipelineLayout with 2 descriptor setLayout at index 0
5079 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
5080 VkPipelineLayout pipe_layout_one_desc;
Karl Schultz6addd812016-02-02 17:17:23 -07005081 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5082 &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005083 ASSERT_VK_SUCCESS(err);
5084 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
5085 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
5086 VkPipelineLayout pipe_layout_five_samp;
Karl Schultz6addd812016-02-02 17:17:23 -07005087 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5088 &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005089 ASSERT_VK_SUCCESS(err);
5090 // Create pipelineLayout with UB type, but stageFlags for FS only
5091 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
5092 VkPipelineLayout pipe_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005093 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5094 &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005095 ASSERT_VK_SUCCESS(err);
5096 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
5097 VkDescriptorSetLayout pl_bad_s0[2] = {};
5098 pl_bad_s0[0] = ds_layout_fs_only;
5099 pl_bad_s0[1] = ds_layout[1];
5100 pipeline_layout_ci.setLayoutCount = 2;
5101 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
5102 VkPipelineLayout pipe_layout_bad_set0;
Karl Schultz6addd812016-02-02 17:17:23 -07005103 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5104 &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005105 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005106
5107 // Create a buffer to update the descriptor with
5108 uint32_t qfi = 0;
5109 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005110 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5111 buffCI.size = 1024;
5112 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5113 buffCI.queueFamilyIndexCount = 1;
5114 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005115
5116 VkBuffer dyub;
5117 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5118 ASSERT_VK_SUCCESS(err);
5119 // Correctly update descriptor to avoid "NOT_UPDATED" error
5120 static const uint32_t NUM_BUFFS = 5;
5121 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005122 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005123 buffInfo[i].buffer = dyub;
5124 buffInfo[i].offset = 0;
5125 buffInfo[i].range = 1024;
5126 }
Karl Schultz6addd812016-02-02 17:17:23 -07005127 VkImage image;
5128 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5129 const int32_t tex_width = 32;
5130 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005131 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005132 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5133 image_create_info.pNext = NULL;
5134 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5135 image_create_info.format = tex_format;
5136 image_create_info.extent.width = tex_width;
5137 image_create_info.extent.height = tex_height;
5138 image_create_info.extent.depth = 1;
5139 image_create_info.mipLevels = 1;
5140 image_create_info.arrayLayers = 1;
5141 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5142 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5143 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5144 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005145 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5146 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005147
Karl Schultz6addd812016-02-02 17:17:23 -07005148 VkMemoryRequirements memReqs;
5149 VkDeviceMemory imageMem;
5150 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005151 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005152 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5153 memAlloc.pNext = NULL;
5154 memAlloc.allocationSize = 0;
5155 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005156 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
5157 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07005158 pass =
5159 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005160 ASSERT_TRUE(pass);
5161 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
5162 ASSERT_VK_SUCCESS(err);
5163 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
5164 ASSERT_VK_SUCCESS(err);
5165
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005166 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005167 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5168 image_view_create_info.image = image;
5169 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5170 image_view_create_info.format = tex_format;
5171 image_view_create_info.subresourceRange.layerCount = 1;
5172 image_view_create_info.subresourceRange.baseMipLevel = 0;
5173 image_view_create_info.subresourceRange.levelCount = 1;
5174 image_view_create_info.subresourceRange.aspectMask =
5175 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005176
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005177 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07005178 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
5179 &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005180 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005181 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005182 imageInfo[0].imageView = view;
5183 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5184 imageInfo[1].imageView = view;
5185 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005186 imageInfo[2].imageView = view;
5187 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5188 imageInfo[3].imageView = view;
5189 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005190
5191 static const uint32_t NUM_SET_UPDATES = 3;
5192 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
5193 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5194 descriptor_write[0].dstSet = descriptorSet[0];
5195 descriptor_write[0].dstBinding = 0;
5196 descriptor_write[0].descriptorCount = 5;
5197 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5198 descriptor_write[0].pBufferInfo = buffInfo;
5199 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5200 descriptor_write[1].dstSet = descriptorSet[1];
5201 descriptor_write[1].dstBinding = 0;
5202 descriptor_write[1].descriptorCount = 2;
5203 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5204 descriptor_write[1].pImageInfo = imageInfo;
5205 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5206 descriptor_write[2].dstSet = descriptorSet[1];
5207 descriptor_write[2].dstBinding = 1;
5208 descriptor_write[2].descriptorCount = 2;
5209 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005210 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005211
5212 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005213
Tobin Ehlis88452832015-12-03 09:40:56 -07005214 // Create PSO to be used for draw-time errors below
5215 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005216 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005217 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005218 "out gl_PerVertex {\n"
5219 " vec4 gl_Position;\n"
5220 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005221 "void main(){\n"
5222 " gl_Position = vec4(1);\n"
5223 "}\n";
5224 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005225 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005226 "\n"
5227 "layout(location=0) out vec4 x;\n"
5228 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5229 "void main(){\n"
5230 " x = vec4(bar.y);\n"
5231 "}\n";
5232 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5233 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005234 VkPipelineObj pipe(m_device);
5235 pipe.AddShader(&vs);
5236 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07005237 pipe.AddColorAttachment();
5238 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07005239
5240 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07005241
Karl Schultz6addd812016-02-02 17:17:23 -07005242 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5243 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5244 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
5245 // of PSO
5246 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
5247 // cmd_pipeline.c
5248 // due to the fact that cmd_alloc_dset_data() has not been called in
5249 // cmd_bind_graphics_pipeline()
5250 // TODO : Want to cause various binding incompatibility issues here to test
5251 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07005252 // First cause various verify_layout_compatibility() fails
5253 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005254 // verify_set_layout_compatibility fail cases:
5255 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultz6addd812016-02-02 17:17:23 -07005256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5257 " due to: invalid VkPipelineLayout ");
5258 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5259 VK_PIPELINE_BIND_POINT_GRAPHICS,
5260 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1,
5261 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005262 m_errorMonitor->VerifyFound();
5263
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005264 // 2. layoutIndex exceeds # of layouts in layout
Karl Schultz6addd812016-02-02 17:17:23 -07005265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5266 " attempting to bind set to index 1");
5267 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5268 VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout,
5269 0, 2, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005270 m_errorMonitor->VerifyFound();
5271
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005272 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005273 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
5274 // descriptors
5275 m_errorMonitor->SetDesiredFailureMsg(
5276 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005277 " has 2 descriptors, but DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005278 vkCmdBindDescriptorSets(
5279 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5280 pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005281 m_errorMonitor->VerifyFound();
5282
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005283 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
5284 // 4. same # of descriptors but mismatch in type
Karl Schultz6addd812016-02-02 17:17:23 -07005285 m_errorMonitor->SetDesiredFailureMsg(
5286 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005287 " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
Karl Schultz6addd812016-02-02 17:17:23 -07005288 vkCmdBindDescriptorSets(
5289 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5290 pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005291 m_errorMonitor->VerifyFound();
5292
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005293 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
5294 // 5. same # of descriptors but mismatch in stageFlags
Karl Schultz6addd812016-02-02 17:17:23 -07005295 m_errorMonitor->SetDesiredFailureMsg(
5296 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005297 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005298 vkCmdBindDescriptorSets(
5299 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5300 pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005301 m_errorMonitor->VerifyFound();
5302
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005303 // Cause INFO messages due to disturbing previously bound Sets
5304 // First bind sets 0 & 1
Karl Schultz6addd812016-02-02 17:17:23 -07005305 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5306 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5307 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005308 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Karl Schultz6addd812016-02-02 17:17:23 -07005309 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07005310 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005311 " previously bound as set #0 was disturbed ");
5312 vkCmdBindDescriptorSets(
5313 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5314 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005315 m_errorMonitor->VerifyFound();
5316
Karl Schultz6addd812016-02-02 17:17:23 -07005317 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5318 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5319 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005320 // 2. Disturb set after last bound set
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07005321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005322 " newly bound as set #0 so set #1 and "
5323 "any subsequent sets were disturbed ");
5324 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5325 VK_PIPELINE_BIND_POINT_GRAPHICS,
5326 pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005327 m_errorMonitor->VerifyFound();
5328
Tobin Ehlis88452832015-12-03 09:40:56 -07005329 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07005330 // 1. Error due to not binding required set (we actually use same code as
5331 // above to disturb set0)
5332 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5333 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5334 2, &descriptorSet[0], 0, NULL);
5335 vkCmdBindDescriptorSets(
5336 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5337 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
5338 m_errorMonitor->SetDesiredFailureMsg(
5339 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5340 " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07005341 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005342 m_errorMonitor->VerifyFound();
5343
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005344 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005345 // 2. Error due to bound set not being compatible with PSO's
5346 // VkPipelineLayout (diff stageFlags in this case)
5347 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5348 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5349 2, &descriptorSet[0], 0, NULL);
5350 m_errorMonitor->SetDesiredFailureMsg(
5351 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5352 " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07005353 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005354 m_errorMonitor->VerifyFound();
5355
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005356 // Remaining clean-up
5357 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005358 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005359 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
5360 }
5361 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06005362 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
5363 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005364 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005365 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5366 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5367}
Tobin Ehlis559c6382015-11-05 09:52:49 -07005368
Karl Schultz6addd812016-02-02 17:17:23 -07005369TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005370
Karl Schultz6addd812016-02-02 17:17:23 -07005371 m_errorMonitor->SetDesiredFailureMsg(
5372 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005373 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005374
5375 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005376 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005377 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005378 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005379
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005380 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005381}
5382
Karl Schultz6addd812016-02-02 17:17:23 -07005383TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
5384 VkResult err;
5385 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005386
Karl Schultz6addd812016-02-02 17:17:23 -07005387 m_errorMonitor->SetDesiredFailureMsg(
5388 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005389 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005390
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005391 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005392
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005393 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005394 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06005395 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005396 cmd.commandPool = m_commandPool;
5397 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005398 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06005399
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005400 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06005401 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005402
5403 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005404 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005405 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005406 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06005407 cmd_buf_info.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07005408 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
5409 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005410 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005411
5412 // The error should be caught by validation of the BeginCommandBuffer call
5413 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
5414
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005415 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005416 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005417}
5418
Karl Schultz6addd812016-02-02 17:17:23 -07005419TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005420 // Cause error due to Begin while recording CB
5421 // Then cause 2 errors for attempting to reset CB w/o having
5422 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
5423 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005425 "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005426
5427 ASSERT_NO_FATAL_FAILURE(InitState());
5428
5429 // Calls AllocateCommandBuffers
5430 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
5431
Karl Schultz6addd812016-02-02 17:17:23 -07005432 // Force the failure by setting the Renderpass and Framebuffer fields with
5433 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005434 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005435 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005436 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5437 cmd_buf_info.pNext = NULL;
5438 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005439 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005440
5441 // Begin CB to transition to recording state
5442 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
5443 // Can't re-begin. This should trigger error
5444 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005445 m_errorMonitor->VerifyFound();
5446
Karl Schultz6addd812016-02-02 17:17:23 -07005447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5448 "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005449 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
5450 // Reset attempt will trigger error due to incorrect CommandPool state
5451 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005452 m_errorMonitor->VerifyFound();
5453
Karl Schultz6addd812016-02-02 17:17:23 -07005454 m_errorMonitor->SetDesiredFailureMsg(
5455 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5456 " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005457 // Transition CB to RECORDED state
5458 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
5459 // Now attempting to Begin will implicitly reset, which triggers error
5460 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005461 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005462}
5463
Karl Schultz6addd812016-02-02 17:17:23 -07005464TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005465 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07005466 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005467
Karl Schultz6addd812016-02-02 17:17:23 -07005468 m_errorMonitor->SetDesiredFailureMsg(
5469 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005470 "Invalid Pipeline CreateInfo State: Vtx Shader required");
5471
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005472 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06005473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005474
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005475 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005476 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5477 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005478
5479 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005480 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5481 ds_pool_ci.pNext = NULL;
5482 ds_pool_ci.maxSets = 1;
5483 ds_pool_ci.poolSizeCount = 1;
5484 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005485
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005486 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005487 err =
5488 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005489 ASSERT_VK_SUCCESS(err);
5490
Tony Barboureb254902015-07-15 12:50:33 -06005491 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005492 dsl_binding.binding = 0;
5493 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5494 dsl_binding.descriptorCount = 1;
5495 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5496 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005497
Tony Barboureb254902015-07-15 12:50:33 -06005498 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005499 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5500 ds_layout_ci.pNext = NULL;
5501 ds_layout_ci.bindingCount = 1;
5502 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06005503
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005504 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005505 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5506 &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005507 ASSERT_VK_SUCCESS(err);
5508
5509 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005510 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005511 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005512 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005513 alloc_info.descriptorPool = ds_pool;
5514 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005515 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5516 &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005517 ASSERT_VK_SUCCESS(err);
5518
Tony Barboureb254902015-07-15 12:50:33 -06005519 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005520 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5521 pipeline_layout_ci.setLayoutCount = 1;
5522 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005523
5524 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005525 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5526 &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005527 ASSERT_VK_SUCCESS(err);
5528
Tobin Ehlise68360f2015-10-01 11:15:13 -06005529 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07005530 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06005531
5532 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005533 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5534 vp_state_ci.scissorCount = 1;
5535 vp_state_ci.pScissors = &sc;
5536 vp_state_ci.viewportCount = 1;
5537 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005538
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005539 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
5540 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5541 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
5542 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
5543 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
5544 rs_state_ci.depthClampEnable = VK_FALSE;
5545 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
5546 rs_state_ci.depthBiasEnable = VK_FALSE;
5547
Tony Barboureb254902015-07-15 12:50:33 -06005548 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005549 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5550 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005551 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07005552 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5553 gp_ci.layout = pipeline_layout;
5554 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06005555
5556 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005557 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5558 pc_ci.initialDataSize = 0;
5559 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005560
5561 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06005562 VkPipelineCache pipelineCache;
5563
Karl Schultz6addd812016-02-02 17:17:23 -07005564 err =
5565 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06005566 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005567 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5568 &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005569
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005570 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005571
Chia-I Wuf7458c52015-10-26 21:10:41 +08005572 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5573 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5574 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5575 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005576}
Tobin Ehlis912df022015-09-17 08:46:18 -06005577/*// TODO : This test should be good, but needs Tess support in compiler to run
5578TEST_F(VkLayerTest, InvalidPatchControlPoints)
5579{
5580 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06005581 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005582
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005584 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
5585primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005586
Tobin Ehlis912df022015-09-17 08:46:18 -06005587 ASSERT_NO_FATAL_FAILURE(InitState());
5588 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06005589
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005590 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06005591 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005592 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06005593
5594 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5595 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5596 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005597 ds_pool_ci.poolSizeCount = 1;
5598 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06005599
5600 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005601 err = vkCreateDescriptorPool(m_device->device(),
5602VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06005603 ASSERT_VK_SUCCESS(err);
5604
5605 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08005606 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06005607 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08005608 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06005609 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5610 dsl_binding.pImmutableSamplers = NULL;
5611
5612 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005613 ds_layout_ci.sType =
5614VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06005615 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005616 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005617 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06005618
5619 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005620 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5621&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06005622 ASSERT_VK_SUCCESS(err);
5623
5624 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07005625 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
5626VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06005627 ASSERT_VK_SUCCESS(err);
5628
5629 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005630 pipeline_layout_ci.sType =
5631VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06005632 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005633 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06005634 pipeline_layout_ci.pSetLayouts = &ds_layout;
5635
5636 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005637 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5638&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06005639 ASSERT_VK_SUCCESS(err);
5640
5641 VkPipelineShaderStageCreateInfo shaderStages[3];
5642 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
5643
Karl Schultz6addd812016-02-02 17:17:23 -07005644 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
5645this);
Tobin Ehlis912df022015-09-17 08:46:18 -06005646 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07005647 VkShaderObj
5648tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
5649this);
5650 VkShaderObj
5651te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
5652this);
Tobin Ehlis912df022015-09-17 08:46:18 -06005653
Karl Schultz6addd812016-02-02 17:17:23 -07005654 shaderStages[0].sType =
5655VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005656 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06005657 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07005658 shaderStages[1].sType =
5659VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005660 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06005661 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07005662 shaderStages[2].sType =
5663VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005664 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06005665 shaderStages[2].shader = te.handle();
5666
5667 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005668 iaCI.sType =
5669VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08005670 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06005671
5672 VkPipelineTessellationStateCreateInfo tsCI = {};
5673 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
5674 tsCI.patchControlPoints = 0; // This will cause an error
5675
5676 VkGraphicsPipelineCreateInfo gp_ci = {};
5677 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5678 gp_ci.pNext = NULL;
5679 gp_ci.stageCount = 3;
5680 gp_ci.pStages = shaderStages;
5681 gp_ci.pVertexInputState = NULL;
5682 gp_ci.pInputAssemblyState = &iaCI;
5683 gp_ci.pTessellationState = &tsCI;
5684 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005685 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06005686 gp_ci.pMultisampleState = NULL;
5687 gp_ci.pDepthStencilState = NULL;
5688 gp_ci.pColorBlendState = NULL;
5689 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5690 gp_ci.layout = pipeline_layout;
5691 gp_ci.renderPass = renderPass();
5692
5693 VkPipelineCacheCreateInfo pc_ci = {};
5694 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5695 pc_ci.pNext = NULL;
5696 pc_ci.initialSize = 0;
5697 pc_ci.initialData = 0;
5698 pc_ci.maxSize = 0;
5699
5700 VkPipeline pipeline;
5701 VkPipelineCache pipelineCache;
5702
Karl Schultz6addd812016-02-02 17:17:23 -07005703 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
5704&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06005705 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005706 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5707&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06005708
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005709 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005710
Chia-I Wuf7458c52015-10-26 21:10:41 +08005711 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5712 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5713 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5714 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06005715}
5716*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06005717// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07005718TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07005719 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005720
Karl Schultz6addd812016-02-02 17:17:23 -07005721 m_errorMonitor->SetDesiredFailureMsg(
5722 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005723 "Gfx Pipeline viewport count (1) must match scissor count (0).");
5724
Tobin Ehlise68360f2015-10-01 11:15:13 -06005725 ASSERT_NO_FATAL_FAILURE(InitState());
5726 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06005727
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005728 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005729 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5730 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005731
5732 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005733 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5734 ds_pool_ci.maxSets = 1;
5735 ds_pool_ci.poolSizeCount = 1;
5736 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005737
5738 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005739 err =
5740 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005741 ASSERT_VK_SUCCESS(err);
5742
5743 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005744 dsl_binding.binding = 0;
5745 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5746 dsl_binding.descriptorCount = 1;
5747 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005748
5749 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005750 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5751 ds_layout_ci.bindingCount = 1;
5752 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005753
5754 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005755 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5756 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005757 ASSERT_VK_SUCCESS(err);
5758
5759 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005760 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005761 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005762 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005763 alloc_info.descriptorPool = ds_pool;
5764 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005765 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5766 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005767 ASSERT_VK_SUCCESS(err);
5768
5769 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005770 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5771 pipeline_layout_ci.setLayoutCount = 1;
5772 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005773
5774 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005775 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5776 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005777 ASSERT_VK_SUCCESS(err);
5778
5779 VkViewport vp = {}; // Just need dummy vp to point to
5780
5781 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005782 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5783 vp_state_ci.scissorCount = 0;
5784 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
5785 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005786
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005787 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
5788 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5789 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
5790 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
5791 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
5792 rs_state_ci.depthClampEnable = VK_FALSE;
5793 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
5794 rs_state_ci.depthBiasEnable = VK_FALSE;
5795
Cody Northropeb3a6c12015-10-05 14:44:45 -06005796 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07005797 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06005798
Karl Schultz6addd812016-02-02 17:17:23 -07005799 VkShaderObj vs(m_device, bindStateVertShaderText,
5800 VK_SHADER_STAGE_VERTEX_BIT, this);
5801 VkShaderObj fs(m_device, bindStateFragShaderText,
5802 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06005803 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07005804 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08005805 shaderStages[0] = vs.GetStageCreateInfo();
5806 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005807
5808 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005809 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5810 gp_ci.stageCount = 2;
5811 gp_ci.pStages = shaderStages;
5812 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005813 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07005814 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5815 gp_ci.layout = pipeline_layout;
5816 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005817
5818 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005819 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005820
5821 VkPipeline pipeline;
5822 VkPipelineCache pipelineCache;
5823
Karl Schultz6addd812016-02-02 17:17:23 -07005824 err =
5825 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005826 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005827 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5828 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005829
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005830 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005831
Chia-I Wuf7458c52015-10-26 21:10:41 +08005832 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5833 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5834 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5835 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005836}
Karl Schultz6addd812016-02-02 17:17:23 -07005837// Don't set viewport state in PSO. This is an error b/c we always need this
5838// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06005839// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07005840TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06005841 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07005842 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005843
Karl Schultz6addd812016-02-02 17:17:23 -07005844 m_errorMonitor->SetDesiredFailureMsg(
5845 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005846 "Gfx Pipeline pViewportState is null. Even if ");
5847
Tobin Ehlise68360f2015-10-01 11:15:13 -06005848 ASSERT_NO_FATAL_FAILURE(InitState());
5849 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06005850
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005851 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005852 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5853 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005854
5855 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005856 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5857 ds_pool_ci.maxSets = 1;
5858 ds_pool_ci.poolSizeCount = 1;
5859 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005860
5861 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005862 err =
5863 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005864 ASSERT_VK_SUCCESS(err);
5865
5866 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005867 dsl_binding.binding = 0;
5868 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5869 dsl_binding.descriptorCount = 1;
5870 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005871
5872 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005873 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5874 ds_layout_ci.bindingCount = 1;
5875 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005876
5877 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005878 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5879 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005880 ASSERT_VK_SUCCESS(err);
5881
5882 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005883 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005884 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005885 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005886 alloc_info.descriptorPool = ds_pool;
5887 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005888 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5889 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005890 ASSERT_VK_SUCCESS(err);
5891
5892 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005893 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5894 pipeline_layout_ci.setLayoutCount = 1;
5895 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005896
5897 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005898 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5899 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005900 ASSERT_VK_SUCCESS(err);
5901
5902 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
5903 // Set scissor as dynamic to avoid second error
5904 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005905 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
5906 dyn_state_ci.dynamicStateCount = 1;
5907 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005908
Cody Northropeb3a6c12015-10-05 14:44:45 -06005909 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07005910 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06005911
Karl Schultz6addd812016-02-02 17:17:23 -07005912 VkShaderObj vs(m_device, bindStateVertShaderText,
5913 VK_SHADER_STAGE_VERTEX_BIT, this);
5914 VkShaderObj fs(m_device, bindStateFragShaderText,
5915 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06005916 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07005917 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08005918 shaderStages[0] = vs.GetStageCreateInfo();
5919 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005920
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005921
5922 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
5923 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5924 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
5925 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
5926 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
5927 rs_state_ci.depthClampEnable = VK_FALSE;
5928 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
5929 rs_state_ci.depthBiasEnable = VK_FALSE;
5930
Tobin Ehlise68360f2015-10-01 11:15:13 -06005931 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005932 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5933 gp_ci.stageCount = 2;
5934 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005935 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07005936 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
5937 // should cause validation error
5938 gp_ci.pDynamicState = &dyn_state_ci;
5939 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5940 gp_ci.layout = pipeline_layout;
5941 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005942
5943 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005944 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005945
5946 VkPipeline pipeline;
5947 VkPipelineCache pipelineCache;
5948
Karl Schultz6addd812016-02-02 17:17:23 -07005949 err =
5950 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005951 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005952 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5953 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005954
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005955 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005956
Chia-I Wuf7458c52015-10-26 21:10:41 +08005957 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5958 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5959 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5960 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005961}
5962// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07005963// Then run second test where dynamic scissor count doesn't match PSO scissor
5964// count
5965TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
5966 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005967
Karl Schultz6addd812016-02-02 17:17:23 -07005968 m_errorMonitor->SetDesiredFailureMsg(
5969 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005970 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
5971
Tobin Ehlise68360f2015-10-01 11:15:13 -06005972 ASSERT_NO_FATAL_FAILURE(InitState());
5973 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06005974
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005975 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005976 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5977 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005978
5979 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005980 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5981 ds_pool_ci.maxSets = 1;
5982 ds_pool_ci.poolSizeCount = 1;
5983 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005984
5985 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005986 err =
5987 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005988 ASSERT_VK_SUCCESS(err);
5989
5990 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005991 dsl_binding.binding = 0;
5992 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5993 dsl_binding.descriptorCount = 1;
5994 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005995
5996 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005997 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5998 ds_layout_ci.bindingCount = 1;
5999 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006000
6001 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006002 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6003 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006004 ASSERT_VK_SUCCESS(err);
6005
6006 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006007 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006008 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006009 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006010 alloc_info.descriptorPool = ds_pool;
6011 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006012 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6013 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006014 ASSERT_VK_SUCCESS(err);
6015
6016 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006017 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6018 pipeline_layout_ci.setLayoutCount = 1;
6019 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006020
6021 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006022 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6023 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006024 ASSERT_VK_SUCCESS(err);
6025
6026 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006027 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6028 vp_state_ci.viewportCount = 1;
6029 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
6030 vp_state_ci.scissorCount = 1;
6031 vp_state_ci.pScissors =
6032 NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06006033
6034 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6035 // Set scissor as dynamic to avoid that error
6036 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006037 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6038 dyn_state_ci.dynamicStateCount = 1;
6039 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006040
Cody Northropeb3a6c12015-10-05 14:44:45 -06006041 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006042 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006043
Karl Schultz6addd812016-02-02 17:17:23 -07006044 VkShaderObj vs(m_device, bindStateVertShaderText,
6045 VK_SHADER_STAGE_VERTEX_BIT, this);
6046 VkShaderObj fs(m_device, bindStateFragShaderText,
6047 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006048 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006049 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006050 shaderStages[0] = vs.GetStageCreateInfo();
6051 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006052
Cody Northropf6622dc2015-10-06 10:33:21 -06006053 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6054 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6055 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006056 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006057 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006058 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006059 vi_ci.pVertexAttributeDescriptions = nullptr;
6060
6061 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6062 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6063 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6064
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006065 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006066 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06006067 rs_ci.pNext = nullptr;
6068
Mark Youngc89c6312016-03-31 16:03:20 -06006069 VkPipelineColorBlendAttachmentState att = {};
6070 att.blendEnable = VK_FALSE;
6071 att.colorWriteMask = 0xf;
6072
Cody Northropf6622dc2015-10-06 10:33:21 -06006073 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6074 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6075 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006076 cb_ci.attachmentCount = 1;
6077 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06006078
Tobin Ehlise68360f2015-10-01 11:15:13 -06006079 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006080 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6081 gp_ci.stageCount = 2;
6082 gp_ci.pStages = shaderStages;
6083 gp_ci.pVertexInputState = &vi_ci;
6084 gp_ci.pInputAssemblyState = &ia_ci;
6085 gp_ci.pViewportState = &vp_state_ci;
6086 gp_ci.pRasterizationState = &rs_ci;
6087 gp_ci.pColorBlendState = &cb_ci;
6088 gp_ci.pDynamicState = &dyn_state_ci;
6089 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6090 gp_ci.layout = pipeline_layout;
6091 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006092
6093 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006094 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006095
6096 VkPipeline pipeline;
6097 VkPipelineCache pipelineCache;
6098
Karl Schultz6addd812016-02-02 17:17:23 -07006099 err =
6100 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006101 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006102 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6103 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006104
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006105 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006106
Tobin Ehlisd332f282015-10-02 11:00:56 -06006107 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07006108 // First need to successfully create the PSO from above by setting
6109 // pViewports
6110 m_errorMonitor->SetDesiredFailureMsg(
6111 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6112 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO "
6113 "scissorCount is 1. These counts must match.");
6114
6115 VkViewport vp = {}; // Just need dummy vp to point to
6116 vp_state_ci.pViewports = &vp;
6117 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6118 &gp_ci, NULL, &pipeline);
6119 ASSERT_VK_SUCCESS(err);
6120 BeginCommandBuffer();
6121 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6122 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
6123 VkRect2D scissors[2] = {}; // don't care about data
6124 // Count of 2 doesn't match PSO count of 1
6125 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
6126 Draw(1, 0, 0, 0);
6127
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006128 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006129
6130 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6131 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6132 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6133 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6134}
6135// Create PSO w/o non-zero scissorCount but no scissor data
6136// Then run second test where dynamic viewportCount doesn't match PSO
6137// viewportCount
6138TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
6139 VkResult err;
6140
6141 m_errorMonitor->SetDesiredFailureMsg(
6142 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6143 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
6144
6145 ASSERT_NO_FATAL_FAILURE(InitState());
6146 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6147
6148 VkDescriptorPoolSize ds_type_count = {};
6149 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6150 ds_type_count.descriptorCount = 1;
6151
6152 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6153 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6154 ds_pool_ci.maxSets = 1;
6155 ds_pool_ci.poolSizeCount = 1;
6156 ds_pool_ci.pPoolSizes = &ds_type_count;
6157
6158 VkDescriptorPool ds_pool;
6159 err =
6160 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6161 ASSERT_VK_SUCCESS(err);
6162
6163 VkDescriptorSetLayoutBinding dsl_binding = {};
6164 dsl_binding.binding = 0;
6165 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6166 dsl_binding.descriptorCount = 1;
6167 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6168
6169 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6170 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6171 ds_layout_ci.bindingCount = 1;
6172 ds_layout_ci.pBindings = &dsl_binding;
6173
6174 VkDescriptorSetLayout ds_layout;
6175 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6176 &ds_layout);
6177 ASSERT_VK_SUCCESS(err);
6178
6179 VkDescriptorSet descriptorSet;
6180 VkDescriptorSetAllocateInfo alloc_info = {};
6181 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6182 alloc_info.descriptorSetCount = 1;
6183 alloc_info.descriptorPool = ds_pool;
6184 alloc_info.pSetLayouts = &ds_layout;
6185 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6186 &descriptorSet);
6187 ASSERT_VK_SUCCESS(err);
6188
6189 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6190 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6191 pipeline_layout_ci.setLayoutCount = 1;
6192 pipeline_layout_ci.pSetLayouts = &ds_layout;
6193
6194 VkPipelineLayout pipeline_layout;
6195 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6196 &pipeline_layout);
6197 ASSERT_VK_SUCCESS(err);
6198
6199 VkPipelineViewportStateCreateInfo vp_state_ci = {};
6200 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6201 vp_state_ci.scissorCount = 1;
6202 vp_state_ci.pScissors =
6203 NULL; // Null scissor w/ count of 1 should cause error
6204 vp_state_ci.viewportCount = 1;
6205 vp_state_ci.pViewports =
6206 NULL; // vp is dynamic (below) so this won't cause error
6207
6208 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
6209 // Set scissor as dynamic to avoid that error
6210 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
6211 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6212 dyn_state_ci.dynamicStateCount = 1;
6213 dyn_state_ci.pDynamicStates = &vp_state;
6214
6215 VkPipelineShaderStageCreateInfo shaderStages[2];
6216 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6217
6218 VkShaderObj vs(m_device, bindStateVertShaderText,
6219 VK_SHADER_STAGE_VERTEX_BIT, this);
6220 VkShaderObj fs(m_device, bindStateFragShaderText,
6221 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006222 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006223 // but add it to be able to run on more devices
6224 shaderStages[0] = vs.GetStageCreateInfo();
6225 shaderStages[1] = fs.GetStageCreateInfo();
6226
6227 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6228 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6229 vi_ci.pNext = nullptr;
6230 vi_ci.vertexBindingDescriptionCount = 0;
6231 vi_ci.pVertexBindingDescriptions = nullptr;
6232 vi_ci.vertexAttributeDescriptionCount = 0;
6233 vi_ci.pVertexAttributeDescriptions = nullptr;
6234
6235 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6236 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6237 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6238
6239 VkPipelineRasterizationStateCreateInfo rs_ci = {};
6240 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6241 rs_ci.pNext = nullptr;
6242
Mark Youngc89c6312016-03-31 16:03:20 -06006243 VkPipelineColorBlendAttachmentState att = {};
6244 att.blendEnable = VK_FALSE;
6245 att.colorWriteMask = 0xf;
6246
Karl Schultz6addd812016-02-02 17:17:23 -07006247 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6248 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6249 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006250 cb_ci.attachmentCount = 1;
6251 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07006252
6253 VkGraphicsPipelineCreateInfo gp_ci = {};
6254 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6255 gp_ci.stageCount = 2;
6256 gp_ci.pStages = shaderStages;
6257 gp_ci.pVertexInputState = &vi_ci;
6258 gp_ci.pInputAssemblyState = &ia_ci;
6259 gp_ci.pViewportState = &vp_state_ci;
6260 gp_ci.pRasterizationState = &rs_ci;
6261 gp_ci.pColorBlendState = &cb_ci;
6262 gp_ci.pDynamicState = &dyn_state_ci;
6263 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6264 gp_ci.layout = pipeline_layout;
6265 gp_ci.renderPass = renderPass();
6266
6267 VkPipelineCacheCreateInfo pc_ci = {};
6268 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6269
6270 VkPipeline pipeline;
6271 VkPipelineCache pipelineCache;
6272
6273 err =
6274 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6275 ASSERT_VK_SUCCESS(err);
6276 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6277 &gp_ci, NULL, &pipeline);
6278
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006279 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006280
6281 // Now hit second fail case where we set scissor w/ different count than PSO
6282 // First need to successfully create the PSO from above by setting
6283 // pViewports
6284 m_errorMonitor->SetDesiredFailureMsg(
6285 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6286 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO "
6287 "viewportCount is 1. These counts must match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006288
Tobin Ehlisd332f282015-10-02 11:00:56 -06006289 VkRect2D sc = {}; // Just need dummy vp to point to
6290 vp_state_ci.pScissors = &sc;
Karl Schultz6addd812016-02-02 17:17:23 -07006291 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6292 &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006293 ASSERT_VK_SUCCESS(err);
6294 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006295 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6296 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006297 VkViewport viewports[2] = {}; // don't care about data
6298 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07006299 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006300 Draw(1, 0, 0, 0);
6301
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006302 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006303
Chia-I Wuf7458c52015-10-26 21:10:41 +08006304 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6305 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6306 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6307 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006308}
6309
Mark Young7394fdd2016-03-31 14:56:43 -06006310TEST_F(VkLayerTest, PSOLineWidthInvalid) {
6311 VkResult err;
6312
6313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06006314 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06006315
6316 ASSERT_NO_FATAL_FAILURE(InitState());
6317 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6318
6319 VkDescriptorPoolSize ds_type_count = {};
6320 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6321 ds_type_count.descriptorCount = 1;
6322
6323 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6324 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6325 ds_pool_ci.maxSets = 1;
6326 ds_pool_ci.poolSizeCount = 1;
6327 ds_pool_ci.pPoolSizes = &ds_type_count;
6328
6329 VkDescriptorPool ds_pool;
6330 err =
6331 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6332 ASSERT_VK_SUCCESS(err);
6333
6334 VkDescriptorSetLayoutBinding dsl_binding = {};
6335 dsl_binding.binding = 0;
6336 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6337 dsl_binding.descriptorCount = 1;
6338 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6339
6340 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6341 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6342 ds_layout_ci.bindingCount = 1;
6343 ds_layout_ci.pBindings = &dsl_binding;
6344
6345 VkDescriptorSetLayout ds_layout;
6346 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6347 &ds_layout);
6348 ASSERT_VK_SUCCESS(err);
6349
6350 VkDescriptorSet descriptorSet;
6351 VkDescriptorSetAllocateInfo alloc_info = {};
6352 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6353 alloc_info.descriptorSetCount = 1;
6354 alloc_info.descriptorPool = ds_pool;
6355 alloc_info.pSetLayouts = &ds_layout;
6356 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6357 &descriptorSet);
6358 ASSERT_VK_SUCCESS(err);
6359
6360 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6361 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6362 pipeline_layout_ci.setLayoutCount = 1;
6363 pipeline_layout_ci.pSetLayouts = &ds_layout;
6364
6365 VkPipelineLayout pipeline_layout;
6366 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6367 &pipeline_layout);
6368 ASSERT_VK_SUCCESS(err);
6369
6370 VkPipelineViewportStateCreateInfo vp_state_ci = {};
6371 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6372 vp_state_ci.scissorCount = 1;
6373 vp_state_ci.pScissors = NULL;
6374 vp_state_ci.viewportCount = 1;
6375 vp_state_ci.pViewports = NULL;
6376
6377 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT,
6378 VK_DYNAMIC_STATE_SCISSOR,
6379 VK_DYNAMIC_STATE_LINE_WIDTH};
6380 // Set scissor as dynamic to avoid that error
6381 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
6382 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6383 dyn_state_ci.dynamicStateCount = 2;
6384 dyn_state_ci.pDynamicStates = dynamic_states;
6385
6386 VkPipelineShaderStageCreateInfo shaderStages[2];
6387 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6388
6389 VkShaderObj vs(m_device, bindStateVertShaderText,
6390 VK_SHADER_STAGE_VERTEX_BIT, this);
6391 VkShaderObj fs(m_device, bindStateFragShaderText,
6392 VK_SHADER_STAGE_FRAGMENT_BIT,
6393 this); // TODO - We shouldn't need a fragment shader
6394 // but add it to be able to run on more devices
6395 shaderStages[0] = vs.GetStageCreateInfo();
6396 shaderStages[1] = fs.GetStageCreateInfo();
6397
6398 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6399 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6400 vi_ci.pNext = nullptr;
6401 vi_ci.vertexBindingDescriptionCount = 0;
6402 vi_ci.pVertexBindingDescriptions = nullptr;
6403 vi_ci.vertexAttributeDescriptionCount = 0;
6404 vi_ci.pVertexAttributeDescriptions = nullptr;
6405
6406 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6407 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6408 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6409
6410 VkPipelineRasterizationStateCreateInfo rs_ci = {};
6411 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6412 rs_ci.pNext = nullptr;
6413
Mark Young47107952016-05-02 15:59:55 -06006414 // Check too low (line width of -1.0f).
6415 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06006416
6417 VkPipelineColorBlendAttachmentState att = {};
6418 att.blendEnable = VK_FALSE;
6419 att.colorWriteMask = 0xf;
6420
6421 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6422 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6423 cb_ci.pNext = nullptr;
6424 cb_ci.attachmentCount = 1;
6425 cb_ci.pAttachments = &att;
6426
6427 VkGraphicsPipelineCreateInfo gp_ci = {};
6428 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6429 gp_ci.stageCount = 2;
6430 gp_ci.pStages = shaderStages;
6431 gp_ci.pVertexInputState = &vi_ci;
6432 gp_ci.pInputAssemblyState = &ia_ci;
6433 gp_ci.pViewportState = &vp_state_ci;
6434 gp_ci.pRasterizationState = &rs_ci;
6435 gp_ci.pColorBlendState = &cb_ci;
6436 gp_ci.pDynamicState = &dyn_state_ci;
6437 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6438 gp_ci.layout = pipeline_layout;
6439 gp_ci.renderPass = renderPass();
6440
6441 VkPipelineCacheCreateInfo pc_ci = {};
6442 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6443
6444 VkPipeline pipeline;
6445 VkPipelineCache pipelineCache;
6446
6447 err =
6448 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6449 ASSERT_VK_SUCCESS(err);
6450 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6451 &gp_ci, NULL, &pipeline);
6452
6453 m_errorMonitor->VerifyFound();
6454
6455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6456 "Attempt to set lineWidth to 65536");
6457
6458 // Check too high (line width of 65536.0f).
6459 rs_ci.lineWidth = 65536.0f;
6460
6461 err =
6462 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6463 ASSERT_VK_SUCCESS(err);
6464 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6465 &gp_ci, NULL, &pipeline);
6466
6467 m_errorMonitor->VerifyFound();
6468
6469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06006470 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06006471
6472 dyn_state_ci.dynamicStateCount = 3;
6473
6474 rs_ci.lineWidth = 1.0f;
6475
6476 err =
6477 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6478 ASSERT_VK_SUCCESS(err);
6479 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6480 &gp_ci, NULL, &pipeline);
6481 BeginCommandBuffer();
6482 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6483 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
6484
6485 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06006486 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06006487 m_errorMonitor->VerifyFound();
6488
6489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6490 "Attempt to set lineWidth to 65536");
6491
6492 // Check too high with dynamic setting.
6493 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
6494 m_errorMonitor->VerifyFound();
6495 EndCommandBuffer();
6496
6497 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6498 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6499 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6500 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6501}
6502
Karl Schultz6addd812016-02-02 17:17:23 -07006503TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006504 // Bind a NULL RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006505 m_errorMonitor->SetDesiredFailureMsg(
6506 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006507 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006508
6509 ASSERT_NO_FATAL_FAILURE(InitState());
6510 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006511
Tony Barbourfe3351b2015-07-28 10:17:20 -06006512 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006513 // Don't care about RenderPass handle b/c error should be flagged before
6514 // that
6515 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL,
6516 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006517
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006518 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006519}
6520
Karl Schultz6addd812016-02-02 17:17:23 -07006521TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006522 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006523 m_errorMonitor->SetDesiredFailureMsg(
6524 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006525 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006526
6527 ASSERT_NO_FATAL_FAILURE(InitState());
6528 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006529
Tony Barbourfe3351b2015-07-28 10:17:20 -06006530 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006531 // Just create a dummy Renderpass that's non-NULL so we can get to the
6532 // proper error
Tony Barboureb254902015-07-15 12:50:33 -06006533 VkRenderPassBeginInfo rp_begin = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006534 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
6535 rp_begin.pNext = NULL;
6536 rp_begin.renderPass = renderPass();
6537 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006538
Karl Schultz6addd812016-02-02 17:17:23 -07006539 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
6540 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006541
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006542 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006543}
6544
Cody Northrop3bb4d962016-05-09 16:15:57 -06006545TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
6546
6547 TEST_DESCRIPTION("End a command buffer with an active render pass");
6548
6549 m_errorMonitor->SetDesiredFailureMsg(
6550 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6551 "It is invalid to issue this call inside an active render pass");
6552
6553 ASSERT_NO_FATAL_FAILURE(InitState());
6554 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6555
6556 // The framework's BeginCommandBuffer calls CreateRenderPass
6557 BeginCommandBuffer();
6558
6559 // Call directly into vkEndCommandBuffer instead of the
6560 // the framework's EndCommandBuffer, which inserts a
6561 // vkEndRenderPass
6562 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
6563
6564 m_errorMonitor->VerifyFound();
6565
6566 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
6567 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
6568}
6569
Karl Schultz6addd812016-02-02 17:17:23 -07006570TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006571 // Call CmdFillBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07006572 m_errorMonitor->SetDesiredFailureMsg(
6573 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006574 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006575
6576 ASSERT_NO_FATAL_FAILURE(InitState());
6577 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006578
6579 // Renderpass is started here
6580 BeginCommandBuffer();
6581
6582 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006583 vk_testing::Buffer dstBuffer;
6584 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006585
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006586 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006587
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006588 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006589}
6590
Karl Schultz6addd812016-02-02 17:17:23 -07006591TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006592 // Call CmdUpdateBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07006593 m_errorMonitor->SetDesiredFailureMsg(
6594 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006595 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006596
6597 ASSERT_NO_FATAL_FAILURE(InitState());
6598 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006599
6600 // Renderpass is started here
6601 BeginCommandBuffer();
6602
6603 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006604 vk_testing::Buffer dstBuffer;
6605 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006606
Karl Schultz6addd812016-02-02 17:17:23 -07006607 VkDeviceSize dstOffset = 0;
6608 VkDeviceSize dataSize = 1024;
6609 const uint32_t *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006610
Karl Schultz6addd812016-02-02 17:17:23 -07006611 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
6612 dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006613
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006614 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006615}
6616
Karl Schultz6addd812016-02-02 17:17:23 -07006617TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006618 // Call CmdClearColorImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006619 m_errorMonitor->SetDesiredFailureMsg(
6620 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006621 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006622
6623 ASSERT_NO_FATAL_FAILURE(InitState());
6624 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006625
6626 // Renderpass is started here
6627 BeginCommandBuffer();
6628
Michael Lentine0a369f62016-02-03 16:51:46 -06006629 VkClearColorValue clear_color;
6630 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07006631 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
6632 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6633 const int32_t tex_width = 32;
6634 const int32_t tex_height = 32;
6635 VkImageCreateInfo image_create_info = {};
6636 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6637 image_create_info.pNext = NULL;
6638 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6639 image_create_info.format = tex_format;
6640 image_create_info.extent.width = tex_width;
6641 image_create_info.extent.height = tex_height;
6642 image_create_info.extent.depth = 1;
6643 image_create_info.mipLevels = 1;
6644 image_create_info.arrayLayers = 1;
6645 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6646 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
6647 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006648
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006649 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07006650 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
6651 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006652
Karl Schultz6addd812016-02-02 17:17:23 -07006653 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
6654 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006655
Karl Schultz6addd812016-02-02 17:17:23 -07006656 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
6657 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006658
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006659 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006660}
6661
Karl Schultz6addd812016-02-02 17:17:23 -07006662TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006663 // Call CmdClearDepthStencilImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006664 m_errorMonitor->SetDesiredFailureMsg(
6665 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006666 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006667
6668 ASSERT_NO_FATAL_FAILURE(InitState());
6669 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006670
6671 // Renderpass is started here
6672 BeginCommandBuffer();
6673
6674 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07006675 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07006676 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
6677 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6678 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
6679 image_create_info.extent.width = 64;
6680 image_create_info.extent.height = 64;
6681 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6682 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006683
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006684 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07006685 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
6686 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006687
Karl Schultz6addd812016-02-02 17:17:23 -07006688 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
6689 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006690
Karl Schultz6addd812016-02-02 17:17:23 -07006691 vkCmdClearDepthStencilImage(
6692 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
6693 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
6694 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006695
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006696 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006697}
6698
Karl Schultz6addd812016-02-02 17:17:23 -07006699TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006700 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006701 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006702
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006704 "vkCmdClearAttachments: This call "
6705 "must be issued inside an active "
6706 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006707
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006708 ASSERT_NO_FATAL_FAILURE(InitState());
6709 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006710
6711 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006712 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006713 ASSERT_VK_SUCCESS(err);
6714
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006715 VkClearAttachment color_attachment;
6716 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6717 color_attachment.clearValue.color.float32[0] = 0;
6718 color_attachment.clearValue.color.float32[1] = 0;
6719 color_attachment.clearValue.color.float32[2] = 0;
6720 color_attachment.clearValue.color.float32[3] = 0;
6721 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07006722 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
6723 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
6724 &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006725
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006726 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006727}
6728
Karl Schultz9e66a292016-04-21 15:57:51 -06006729TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
6730 // Try to add a buffer memory barrier with no buffer.
6731 m_errorMonitor->SetDesiredFailureMsg(
6732 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6733 "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE");
6734
6735 ASSERT_NO_FATAL_FAILURE(InitState());
6736 BeginCommandBuffer();
6737
6738 VkBufferMemoryBarrier buf_barrier = {};
6739 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
6740 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6741 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6742 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6743 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6744 buf_barrier.buffer = VK_NULL_HANDLE;
6745 buf_barrier.offset = 0;
6746 buf_barrier.size = VK_WHOLE_SIZE;
6747 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6748 VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
6749 0, 0, nullptr, 1, &buf_barrier, 0, nullptr);
6750
6751 m_errorMonitor->VerifyFound();
6752}
6753
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06006754TEST_F(VkLayerTest, InvalidBarriers) {
6755 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
6756
6757 m_errorMonitor->SetDesiredFailureMsg(
6758 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
6759
6760 ASSERT_NO_FATAL_FAILURE(InitState());
6761 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6762
6763 VkMemoryBarrier mem_barrier = {};
6764 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
6765 mem_barrier.pNext = NULL;
6766 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6767 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6768 BeginCommandBuffer();
6769 // BeginCommandBuffer() starts a render pass
6770 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6771 VK_PIPELINE_STAGE_HOST_BIT,
6772 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
6773 &mem_barrier, 0, nullptr, 0, nullptr);
6774 m_errorMonitor->VerifyFound();
6775
6776 m_errorMonitor->SetDesiredFailureMsg(
6777 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6778 "Image Layout cannot be transitioned to UNDEFINED");
6779 VkImageObj image(m_device);
6780 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
6781 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6782 ASSERT_TRUE(image.initialized());
6783 VkImageMemoryBarrier img_barrier = {};
6784 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
6785 img_barrier.pNext = NULL;
6786 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6787 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6788 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
6789 // New layout can't be UNDEFINED
6790 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6791 img_barrier.image = image.handle();
6792 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6793 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6794 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6795 img_barrier.subresourceRange.baseArrayLayer = 0;
6796 img_barrier.subresourceRange.baseMipLevel = 0;
6797 img_barrier.subresourceRange.layerCount = 1;
6798 img_barrier.subresourceRange.levelCount = 1;
6799 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6800 VK_PIPELINE_STAGE_HOST_BIT,
6801 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6802 nullptr, 1, &img_barrier);
6803 m_errorMonitor->VerifyFound();
6804 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
6805
6806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6807 "Subresource must have the sum of the "
6808 "baseArrayLayer");
6809 // baseArrayLayer + layerCount must be <= image's arrayLayers
6810 img_barrier.subresourceRange.baseArrayLayer = 1;
6811 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6812 VK_PIPELINE_STAGE_HOST_BIT,
6813 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6814 nullptr, 1, &img_barrier);
6815 m_errorMonitor->VerifyFound();
6816 img_barrier.subresourceRange.baseArrayLayer = 0;
6817
6818 m_errorMonitor->SetDesiredFailureMsg(
6819 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6820 "Subresource must have the sum of the baseMipLevel");
6821 // baseMipLevel + levelCount must be <= image's mipLevels
6822 img_barrier.subresourceRange.baseMipLevel = 1;
6823 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6824 VK_PIPELINE_STAGE_HOST_BIT,
6825 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6826 nullptr, 1, &img_barrier);
6827 m_errorMonitor->VerifyFound();
6828 img_barrier.subresourceRange.baseMipLevel = 0;
6829
6830 m_errorMonitor->SetDesiredFailureMsg(
6831 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6832 "Buffer Barriers cannot be used during a render pass");
6833 vk_testing::Buffer buffer;
6834 buffer.init(*m_device, 256);
6835 VkBufferMemoryBarrier buf_barrier = {};
6836 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
6837 buf_barrier.pNext = NULL;
6838 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6839 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6840 buf_barrier.buffer = buffer.handle();
6841 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6842 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6843 buf_barrier.offset = 0;
6844 buf_barrier.size = VK_WHOLE_SIZE;
6845 // Can't send buffer barrier during a render pass
6846 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6847 VK_PIPELINE_STAGE_HOST_BIT,
6848 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
6849 &buf_barrier, 0, nullptr);
6850 m_errorMonitor->VerifyFound();
6851 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
6852
6853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6854 "which is not less than total size");
6855 buf_barrier.offset = 257;
6856 // Offset greater than total size
6857 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6858 VK_PIPELINE_STAGE_HOST_BIT,
6859 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
6860 &buf_barrier, 0, nullptr);
6861 m_errorMonitor->VerifyFound();
6862 buf_barrier.offset = 0;
6863
6864 m_errorMonitor->SetDesiredFailureMsg(
6865 VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
6866 buf_barrier.size = 257;
6867 // Size greater than total size
6868 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6869 VK_PIPELINE_STAGE_HOST_BIT,
6870 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
6871 &buf_barrier, 0, nullptr);
6872 m_errorMonitor->VerifyFound();
6873 buf_barrier.size = VK_WHOLE_SIZE;
6874
6875 m_errorMonitor->SetDesiredFailureMsg(
6876 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6877 "Image is a depth and stencil format and thus must "
6878 "have both VK_IMAGE_ASPECT_DEPTH_BIT and "
6879 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
6880 VkDepthStencilObj ds_image(m_device);
6881 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
6882 ASSERT_TRUE(ds_image.initialized());
6883 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
6884 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
6885 img_barrier.image = ds_image.handle();
6886 // Leave aspectMask at COLOR on purpose
6887 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6888 VK_PIPELINE_STAGE_HOST_BIT,
6889 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6890 nullptr, 1, &img_barrier);
6891 m_errorMonitor->VerifyFound();
6892}
6893
Karl Schultz6addd812016-02-02 17:17:23 -07006894TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006895 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006896 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006897
Karl Schultz6addd812016-02-02 17:17:23 -07006898 m_errorMonitor->SetDesiredFailureMsg(
6899 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006900 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
6901
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006902 ASSERT_NO_FATAL_FAILURE(InitState());
6903 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006904 uint32_t qfi = 0;
6905 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006906 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6907 buffCI.size = 1024;
6908 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
6909 buffCI.queueFamilyIndexCount = 1;
6910 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006911
6912 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006913 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006914 ASSERT_VK_SUCCESS(err);
6915
6916 BeginCommandBuffer();
6917 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006918 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6919 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006920 // Should error before calling to driver so don't care about actual data
Karl Schultz6addd812016-02-02 17:17:23 -07006921 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
6922 VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006923
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006924 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006925
Chia-I Wuf7458c52015-10-26 21:10:41 +08006926 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006927}
6928
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07006929TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
6930 // Create an out-of-range queueFamilyIndex
6931 m_errorMonitor->SetDesiredFailureMsg(
6932 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesde628532016-04-21 16:30:17 -06006933 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
6934 "of the indices specified when the device was created, via the "
6935 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07006936
6937 ASSERT_NO_FATAL_FAILURE(InitState());
6938 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6939 VkBufferCreateInfo buffCI = {};
6940 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6941 buffCI.size = 1024;
6942 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
6943 buffCI.queueFamilyIndexCount = 1;
6944 // Introduce failure by specifying invalid queue_family_index
6945 uint32_t qfi = 777;
6946 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06006947 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07006948
6949 VkBuffer ib;
6950 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
6951
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006952 m_errorMonitor->VerifyFound();
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07006953}
6954
Karl Schultz6addd812016-02-02 17:17:23 -07006955TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
6956 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
6957 // secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006958
Karl Schultz6addd812016-02-02 17:17:23 -07006959 m_errorMonitor->SetDesiredFailureMsg(
6960 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006961 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006962
6963 ASSERT_NO_FATAL_FAILURE(InitState());
6964 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006965
6966 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006967 // ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006968 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
6969 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006970
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006971 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006972}
6973
Karl Schultz6addd812016-02-02 17:17:23 -07006974TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006975 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07006976 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06006977
Karl Schultz6addd812016-02-02 17:17:23 -07006978 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006979 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6980 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
6981 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006982
Tobin Ehlis3b780662015-05-28 12:11:26 -06006983 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07006984 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006985 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006986 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6987 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006988
6989 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006990 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6991 ds_pool_ci.pNext = NULL;
6992 ds_pool_ci.maxSets = 1;
6993 ds_pool_ci.poolSizeCount = 1;
6994 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06006995
Tobin Ehlis3b780662015-05-28 12:11:26 -06006996 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006997 err =
6998 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06006999 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06007000 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007001 dsl_binding.binding = 0;
7002 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7003 dsl_binding.descriptorCount = 1;
7004 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7005 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007006
Tony Barboureb254902015-07-15 12:50:33 -06007007 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007008 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7009 ds_layout_ci.pNext = NULL;
7010 ds_layout_ci.bindingCount = 1;
7011 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007012
Tobin Ehlis3b780662015-05-28 12:11:26 -06007013 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007014 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7015 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007016 ASSERT_VK_SUCCESS(err);
7017
7018 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007019 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007020 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007021 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007022 alloc_info.descriptorPool = ds_pool;
7023 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007024 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7025 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007026 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007027
Tobin Ehlis30db8f82016-05-05 08:19:48 -06007028 VkSamplerCreateInfo sampler_ci = {};
7029 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7030 sampler_ci.pNext = NULL;
7031 sampler_ci.magFilter = VK_FILTER_NEAREST;
7032 sampler_ci.minFilter = VK_FILTER_NEAREST;
7033 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7034 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7035 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7036 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7037 sampler_ci.mipLodBias = 1.0;
7038 sampler_ci.anisotropyEnable = VK_FALSE;
7039 sampler_ci.maxAnisotropy = 1;
7040 sampler_ci.compareEnable = VK_FALSE;
7041 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7042 sampler_ci.minLod = 1.0;
7043 sampler_ci.maxLod = 1.0;
7044 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7045 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7046 VkSampler sampler;
7047 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7048 ASSERT_VK_SUCCESS(err);
7049
7050 VkDescriptorImageInfo info = {};
7051 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007052
7053 VkWriteDescriptorSet descriptor_write;
7054 memset(&descriptor_write, 0, sizeof(descriptor_write));
7055 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007056 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007057 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007058 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007059 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007060 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007061
7062 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7063
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007064 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007065
Chia-I Wuf7458c52015-10-26 21:10:41 +08007066 vkDestroySampler(m_device->device(), sampler, NULL);
7067 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7068 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007069}
7070
Karl Schultz6addd812016-02-02 17:17:23 -07007071TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007072 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07007073 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007074
Karl Schultz6addd812016-02-02 17:17:23 -07007075 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007076 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7077 " binding #0 with 1 total descriptors but update of 1 descriptors "
7078 "starting at binding offset of 0 combined with update array element "
7079 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007080
Tobin Ehlis3b780662015-05-28 12:11:26 -06007081 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007082 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007083 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007084 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7085 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007086
7087 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007088 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7089 ds_pool_ci.pNext = NULL;
7090 ds_pool_ci.maxSets = 1;
7091 ds_pool_ci.poolSizeCount = 1;
7092 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06007093
Tobin Ehlis3b780662015-05-28 12:11:26 -06007094 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007095 err =
7096 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007097 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007098
Tony Barboureb254902015-07-15 12:50:33 -06007099 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007100 dsl_binding.binding = 0;
7101 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7102 dsl_binding.descriptorCount = 1;
7103 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7104 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06007105
7106 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007107 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7108 ds_layout_ci.pNext = NULL;
7109 ds_layout_ci.bindingCount = 1;
7110 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007111
Tobin Ehlis3b780662015-05-28 12:11:26 -06007112 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007113 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7114 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007115 ASSERT_VK_SUCCESS(err);
7116
7117 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007118 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007119 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007120 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007121 alloc_info.descriptorPool = ds_pool;
7122 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007123 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7124 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007125 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007126
Tobin Ehlis30db8f82016-05-05 08:19:48 -06007127 // Correctly update descriptor to avoid "NOT_UPDATED" error
7128 VkDescriptorBufferInfo buff_info = {};
7129 buff_info.buffer =
7130 VkBuffer(0); // Don't care about buffer handle for this test
7131 buff_info.offset = 0;
7132 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007133
7134 VkWriteDescriptorSet descriptor_write;
7135 memset(&descriptor_write, 0, sizeof(descriptor_write));
7136 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007137 descriptor_write.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007138 descriptor_write.dstArrayElement =
7139 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08007140 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007141 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7142 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007143
7144 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7145
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007146 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007147
Chia-I Wuf7458c52015-10-26 21:10:41 +08007148 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7149 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007150}
7151
Karl Schultz6addd812016-02-02 17:17:23 -07007152TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
7153 // Create layout w/ count of 1 and attempt update to that layout w/ binding
7154 // index 2
7155 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007156
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7158 " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007159
Tobin Ehlis3b780662015-05-28 12:11:26 -06007160 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007161 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007162 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007163 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7164 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007165
7166 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007167 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7168 ds_pool_ci.pNext = NULL;
7169 ds_pool_ci.maxSets = 1;
7170 ds_pool_ci.poolSizeCount = 1;
7171 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06007172
Tobin Ehlis3b780662015-05-28 12:11:26 -06007173 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007174 err =
7175 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007176 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007177
Tony Barboureb254902015-07-15 12:50:33 -06007178 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007179 dsl_binding.binding = 0;
7180 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7181 dsl_binding.descriptorCount = 1;
7182 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7183 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06007184
7185 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007186 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7187 ds_layout_ci.pNext = NULL;
7188 ds_layout_ci.bindingCount = 1;
7189 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007190 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007191 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7192 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007193 ASSERT_VK_SUCCESS(err);
7194
7195 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007196 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007197 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007198 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007199 alloc_info.descriptorPool = ds_pool;
7200 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007201 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7202 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007203 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007204
Tony Barboureb254902015-07-15 12:50:33 -06007205 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007206 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7207 sampler_ci.pNext = NULL;
7208 sampler_ci.magFilter = VK_FILTER_NEAREST;
7209 sampler_ci.minFilter = VK_FILTER_NEAREST;
7210 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7211 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7212 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7213 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7214 sampler_ci.mipLodBias = 1.0;
7215 sampler_ci.anisotropyEnable = VK_FALSE;
7216 sampler_ci.maxAnisotropy = 1;
7217 sampler_ci.compareEnable = VK_FALSE;
7218 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7219 sampler_ci.minLod = 1.0;
7220 sampler_ci.maxLod = 1.0;
7221 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7222 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06007223
Tobin Ehlis3b780662015-05-28 12:11:26 -06007224 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007225 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007226 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007227
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007228 VkDescriptorImageInfo info = {};
7229 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007230
7231 VkWriteDescriptorSet descriptor_write;
7232 memset(&descriptor_write, 0, sizeof(descriptor_write));
7233 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007234 descriptor_write.dstSet = descriptorSet;
7235 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007236 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007237 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007238 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007239 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007240
7241 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7242
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007243 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007244
Chia-I Wuf7458c52015-10-26 21:10:41 +08007245 vkDestroySampler(m_device->device(), sampler, NULL);
7246 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7247 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007248}
7249
Karl Schultz6addd812016-02-02 17:17:23 -07007250TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
7251 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
7252 // types
7253 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007254
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis660bcdc2016-05-17 10:39:46 -06007256 ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007257
Tobin Ehlis3b780662015-05-28 12:11:26 -06007258 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007259
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007260 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007261 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7262 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007263
7264 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007265 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7266 ds_pool_ci.pNext = NULL;
7267 ds_pool_ci.maxSets = 1;
7268 ds_pool_ci.poolSizeCount = 1;
7269 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06007270
Tobin Ehlis3b780662015-05-28 12:11:26 -06007271 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007272 err =
7273 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007274 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06007275 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007276 dsl_binding.binding = 0;
7277 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7278 dsl_binding.descriptorCount = 1;
7279 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7280 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007281
Tony Barboureb254902015-07-15 12:50:33 -06007282 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007283 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7284 ds_layout_ci.pNext = NULL;
7285 ds_layout_ci.bindingCount = 1;
7286 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007287
Tobin Ehlis3b780662015-05-28 12:11:26 -06007288 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007289 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7290 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007291 ASSERT_VK_SUCCESS(err);
7292
7293 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007294 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007295 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007296 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007297 alloc_info.descriptorPool = ds_pool;
7298 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007299 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7300 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007301 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007302
Tony Barboureb254902015-07-15 12:50:33 -06007303 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007304 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7305 sampler_ci.pNext = NULL;
7306 sampler_ci.magFilter = VK_FILTER_NEAREST;
7307 sampler_ci.minFilter = VK_FILTER_NEAREST;
7308 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7309 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7310 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7311 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7312 sampler_ci.mipLodBias = 1.0;
7313 sampler_ci.anisotropyEnable = VK_FALSE;
7314 sampler_ci.maxAnisotropy = 1;
7315 sampler_ci.compareEnable = VK_FALSE;
7316 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7317 sampler_ci.minLod = 1.0;
7318 sampler_ci.maxLod = 1.0;
7319 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7320 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007321 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007322 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007323 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007324
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007325 VkDescriptorImageInfo info = {};
7326 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007327
7328 VkWriteDescriptorSet descriptor_write;
7329 memset(&descriptor_write, 0, sizeof(descriptor_write));
Karl Schultz6addd812016-02-02 17:17:23 -07007330 descriptor_write.sType =
7331 (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007332 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007333 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007334 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007335 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007336 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007337
7338 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7339
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007340 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007341
Chia-I Wuf7458c52015-10-26 21:10:41 +08007342 vkDestroySampler(m_device->device(), sampler, NULL);
7343 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7344 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007345}
7346
Karl Schultz6addd812016-02-02 17:17:23 -07007347TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007348 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07007349 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007350
Karl Schultz6addd812016-02-02 17:17:23 -07007351 m_errorMonitor->SetDesiredFailureMsg(
7352 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007353 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007354
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007355 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007356 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
7357 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007358 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007359 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
7360 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007361
7362 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007363 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7364 ds_pool_ci.pNext = NULL;
7365 ds_pool_ci.maxSets = 1;
7366 ds_pool_ci.poolSizeCount = 1;
7367 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007368
7369 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007370 err =
7371 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007372 ASSERT_VK_SUCCESS(err);
7373
7374 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007375 dsl_binding.binding = 0;
7376 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7377 dsl_binding.descriptorCount = 1;
7378 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7379 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007380
7381 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007382 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7383 ds_layout_ci.pNext = NULL;
7384 ds_layout_ci.bindingCount = 1;
7385 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007386 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007387 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7388 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007389 ASSERT_VK_SUCCESS(err);
7390
7391 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007392 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007393 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007394 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007395 alloc_info.descriptorPool = ds_pool;
7396 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007397 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7398 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007399 ASSERT_VK_SUCCESS(err);
7400
Karl Schultz6addd812016-02-02 17:17:23 -07007401 VkSampler sampler =
7402 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007403
7404 VkDescriptorImageInfo descriptor_info;
7405 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
7406 descriptor_info.sampler = sampler;
7407
7408 VkWriteDescriptorSet descriptor_write;
7409 memset(&descriptor_write, 0, sizeof(descriptor_write));
7410 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007411 descriptor_write.dstSet = descriptorSet;
7412 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007413 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007414 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7415 descriptor_write.pImageInfo = &descriptor_info;
7416
7417 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7418
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007419 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007420
Chia-I Wuf7458c52015-10-26 21:10:41 +08007421 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7422 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007423}
7424
Karl Schultz6addd812016-02-02 17:17:23 -07007425TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
7426 // Create a single combined Image/Sampler descriptor and send it an invalid
7427 // imageView
7428 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007429
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7431 "Attempted write update to combined "
7432 "image sampler descriptor failed due "
Tobin Ehlis63c4b8a2016-05-09 10:29:34 -06007433 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007434
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007435 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007436 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007437 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7438 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007439
7440 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007441 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7442 ds_pool_ci.pNext = NULL;
7443 ds_pool_ci.maxSets = 1;
7444 ds_pool_ci.poolSizeCount = 1;
7445 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007446
7447 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007448 err =
7449 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007450 ASSERT_VK_SUCCESS(err);
7451
7452 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007453 dsl_binding.binding = 0;
7454 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7455 dsl_binding.descriptorCount = 1;
7456 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7457 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007458
7459 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007460 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7461 ds_layout_ci.pNext = NULL;
7462 ds_layout_ci.bindingCount = 1;
7463 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007464 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007465 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7466 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007467 ASSERT_VK_SUCCESS(err);
7468
7469 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007470 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007471 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007472 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007473 alloc_info.descriptorPool = ds_pool;
7474 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007475 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7476 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007477 ASSERT_VK_SUCCESS(err);
7478
7479 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007480 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7481 sampler_ci.pNext = NULL;
7482 sampler_ci.magFilter = VK_FILTER_NEAREST;
7483 sampler_ci.minFilter = VK_FILTER_NEAREST;
7484 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7485 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7486 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7487 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7488 sampler_ci.mipLodBias = 1.0;
7489 sampler_ci.anisotropyEnable = VK_FALSE;
7490 sampler_ci.maxAnisotropy = 1;
7491 sampler_ci.compareEnable = VK_FALSE;
7492 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7493 sampler_ci.minLod = 1.0;
7494 sampler_ci.maxLod = 1.0;
7495 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7496 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007497
7498 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007499 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007500 ASSERT_VK_SUCCESS(err);
7501
Karl Schultz6addd812016-02-02 17:17:23 -07007502 VkImageView view =
7503 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007504
7505 VkDescriptorImageInfo descriptor_info;
7506 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
7507 descriptor_info.sampler = sampler;
7508 descriptor_info.imageView = view;
7509
7510 VkWriteDescriptorSet descriptor_write;
7511 memset(&descriptor_write, 0, sizeof(descriptor_write));
7512 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007513 descriptor_write.dstSet = descriptorSet;
7514 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007515 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007516 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7517 descriptor_write.pImageInfo = &descriptor_info;
7518
7519 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7520
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007521 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007522
Chia-I Wuf7458c52015-10-26 21:10:41 +08007523 vkDestroySampler(m_device->device(), sampler, NULL);
7524 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7525 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007526}
7527
Karl Schultz6addd812016-02-02 17:17:23 -07007528TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
7529 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
7530 // into the other
7531 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007532
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7534 " binding #1 with type "
7535 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
7536 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007537
Tobin Ehlis04356f92015-10-27 16:35:27 -06007538 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007539 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007540 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007541 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7542 ds_type_count[0].descriptorCount = 1;
7543 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7544 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007545
7546 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007547 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7548 ds_pool_ci.pNext = NULL;
7549 ds_pool_ci.maxSets = 1;
7550 ds_pool_ci.poolSizeCount = 2;
7551 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007552
7553 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007554 err =
7555 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007556 ASSERT_VK_SUCCESS(err);
7557 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007558 dsl_binding[0].binding = 0;
7559 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7560 dsl_binding[0].descriptorCount = 1;
7561 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7562 dsl_binding[0].pImmutableSamplers = NULL;
7563 dsl_binding[1].binding = 1;
7564 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7565 dsl_binding[1].descriptorCount = 1;
7566 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7567 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007568
7569 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007570 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7571 ds_layout_ci.pNext = NULL;
7572 ds_layout_ci.bindingCount = 2;
7573 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007574
7575 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007576 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7577 &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007578 ASSERT_VK_SUCCESS(err);
7579
7580 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007581 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007582 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007583 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007584 alloc_info.descriptorPool = ds_pool;
7585 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007586 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7587 &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007588 ASSERT_VK_SUCCESS(err);
7589
7590 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007591 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7592 sampler_ci.pNext = NULL;
7593 sampler_ci.magFilter = VK_FILTER_NEAREST;
7594 sampler_ci.minFilter = VK_FILTER_NEAREST;
7595 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7596 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7597 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7598 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7599 sampler_ci.mipLodBias = 1.0;
7600 sampler_ci.anisotropyEnable = VK_FALSE;
7601 sampler_ci.maxAnisotropy = 1;
7602 sampler_ci.compareEnable = VK_FALSE;
7603 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7604 sampler_ci.minLod = 1.0;
7605 sampler_ci.maxLod = 1.0;
7606 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7607 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007608
7609 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007610 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007611 ASSERT_VK_SUCCESS(err);
7612
7613 VkDescriptorImageInfo info = {};
7614 info.sampler = sampler;
7615
7616 VkWriteDescriptorSet descriptor_write;
7617 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
7618 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007619 descriptor_write.dstSet = descriptorSet;
7620 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08007621 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007622 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7623 descriptor_write.pImageInfo = &info;
7624 // This write update should succeed
7625 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7626 // Now perform a copy update that fails due to type mismatch
7627 VkCopyDescriptorSet copy_ds_update;
7628 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
7629 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
7630 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06007631 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007632 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007633 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08007634 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06007635 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
7636
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007637 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06007638 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07007639 m_errorMonitor->SetDesiredFailureMsg(
7640 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007641 " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -06007642 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
7643 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
7644 copy_ds_update.srcSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007645 copy_ds_update.srcBinding =
7646 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007647 copy_ds_update.dstSet = descriptorSet;
7648 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06007649 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06007650 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
7651
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007652 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007653
Tobin Ehlis04356f92015-10-27 16:35:27 -06007654 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07007655 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007656 VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
7657 "update array offset of 0 and update of "
7658 "5 descriptors oversteps total number "
7659 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007660
Tobin Ehlis04356f92015-10-27 16:35:27 -06007661 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
7662 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
7663 copy_ds_update.srcSet = descriptorSet;
7664 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007665 copy_ds_update.dstSet = descriptorSet;
7666 copy_ds_update.dstBinding = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007667 copy_ds_update.descriptorCount =
7668 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06007669 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
7670
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007671 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06007672
Chia-I Wuf7458c52015-10-26 21:10:41 +08007673 vkDestroySampler(m_device->device(), sampler, NULL);
7674 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7675 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007676}
7677
Karl Schultz6addd812016-02-02 17:17:23 -07007678TEST_F(VkLayerTest, NumSamplesMismatch) {
7679 // Create CommandBuffer where MSAA samples doesn't match RenderPass
7680 // sampleCount
7681 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007682
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007684 "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007685
Tobin Ehlis3b780662015-05-28 12:11:26 -06007686 ASSERT_NO_FATAL_FAILURE(InitState());
7687 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007688 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06007689 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007690 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007691
7692 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007693 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7694 ds_pool_ci.pNext = NULL;
7695 ds_pool_ci.maxSets = 1;
7696 ds_pool_ci.poolSizeCount = 1;
7697 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06007698
Tobin Ehlis3b780662015-05-28 12:11:26 -06007699 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007700 err =
7701 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007702 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007703
Tony Barboureb254902015-07-15 12:50:33 -06007704 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007705 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06007706 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007707 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007708 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7709 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007710
Tony Barboureb254902015-07-15 12:50:33 -06007711 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7712 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7713 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007714 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007715 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007716
Tobin Ehlis3b780662015-05-28 12:11:26 -06007717 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007718 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7719 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007720 ASSERT_VK_SUCCESS(err);
7721
7722 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007723 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007724 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007725 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007726 alloc_info.descriptorPool = ds_pool;
7727 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007728 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7729 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007730 ASSERT_VK_SUCCESS(err);
7731
Tony Barboureb254902015-07-15 12:50:33 -06007732 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007733 pipe_ms_state_ci.sType =
7734 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7735 pipe_ms_state_ci.pNext = NULL;
7736 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7737 pipe_ms_state_ci.sampleShadingEnable = 0;
7738 pipe_ms_state_ci.minSampleShading = 1.0;
7739 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007740
Tony Barboureb254902015-07-15 12:50:33 -06007741 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007742 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7743 pipeline_layout_ci.pNext = NULL;
7744 pipeline_layout_ci.setLayoutCount = 1;
7745 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007746
7747 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007748 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7749 &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007750 ASSERT_VK_SUCCESS(err);
7751
Karl Schultz6addd812016-02-02 17:17:23 -07007752 VkShaderObj vs(m_device, bindStateVertShaderText,
7753 VK_SHADER_STAGE_VERTEX_BIT, this);
7754 VkShaderObj fs(m_device, bindStateFragShaderText,
7755 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06007756 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07007757 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06007758 VkPipelineObj pipe(m_device);
7759 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007760 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06007761 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06007762 pipe.SetMSAA(&pipe_ms_state_ci);
7763 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06007764
Tony Barbourfe3351b2015-07-28 10:17:20 -06007765 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007766 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7767 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06007768
Mark Young29927482016-05-04 14:38:51 -06007769 // Render triangle (the error should trigger on the attempt to draw).
7770 Draw(3, 1, 0, 0);
7771
7772 // Finalize recording of the command buffer
7773 EndCommandBuffer();
7774
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007775 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007776
Chia-I Wuf7458c52015-10-26 21:10:41 +08007777 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7778 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7779 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007780}
Mark Young29927482016-05-04 14:38:51 -06007781
Mark Youngc89c6312016-03-31 16:03:20 -06007782TEST_F(VkLayerTest, NumBlendAttachMismatch) {
7783 // Create Pipeline where the number of blend attachments doesn't match the
7784 // number of color attachments. In this case, we don't add any color
7785 // blend attachments even though we have a color attachment.
7786 VkResult err;
7787
7788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young29927482016-05-04 14:38:51 -06007789 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06007790
7791 ASSERT_NO_FATAL_FAILURE(InitState());
7792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7793 VkDescriptorPoolSize ds_type_count = {};
7794 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7795 ds_type_count.descriptorCount = 1;
7796
7797 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7798 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7799 ds_pool_ci.pNext = NULL;
7800 ds_pool_ci.maxSets = 1;
7801 ds_pool_ci.poolSizeCount = 1;
7802 ds_pool_ci.pPoolSizes = &ds_type_count;
7803
7804 VkDescriptorPool ds_pool;
7805 err =
7806 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7807 ASSERT_VK_SUCCESS(err);
7808
7809 VkDescriptorSetLayoutBinding dsl_binding = {};
7810 dsl_binding.binding = 0;
7811 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7812 dsl_binding.descriptorCount = 1;
7813 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7814 dsl_binding.pImmutableSamplers = NULL;
7815
7816 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7817 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7818 ds_layout_ci.pNext = NULL;
7819 ds_layout_ci.bindingCount = 1;
7820 ds_layout_ci.pBindings = &dsl_binding;
7821
7822 VkDescriptorSetLayout ds_layout;
7823 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7824 &ds_layout);
7825 ASSERT_VK_SUCCESS(err);
7826
7827 VkDescriptorSet descriptorSet;
7828 VkDescriptorSetAllocateInfo alloc_info = {};
7829 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7830 alloc_info.descriptorSetCount = 1;
7831 alloc_info.descriptorPool = ds_pool;
7832 alloc_info.pSetLayouts = &ds_layout;
7833 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7834 &descriptorSet);
7835 ASSERT_VK_SUCCESS(err);
7836
7837 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7838 pipe_ms_state_ci.sType =
7839 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7840 pipe_ms_state_ci.pNext = NULL;
7841 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7842 pipe_ms_state_ci.sampleShadingEnable = 0;
7843 pipe_ms_state_ci.minSampleShading = 1.0;
7844 pipe_ms_state_ci.pSampleMask = NULL;
7845
7846 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7847 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7848 pipeline_layout_ci.pNext = NULL;
7849 pipeline_layout_ci.setLayoutCount = 1;
7850 pipeline_layout_ci.pSetLayouts = &ds_layout;
7851
7852 VkPipelineLayout pipeline_layout;
7853 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7854 &pipeline_layout);
7855 ASSERT_VK_SUCCESS(err);
7856
7857 VkShaderObj vs(m_device, bindStateVertShaderText,
7858 VK_SHADER_STAGE_VERTEX_BIT, this);
7859 VkShaderObj fs(m_device, bindStateFragShaderText,
7860 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06007861 this); // We shouldn't need a fragment shader
Mark Youngc89c6312016-03-31 16:03:20 -06007862 // but add it to be able to run on more devices
7863 VkPipelineObj pipe(m_device);
7864 pipe.AddShader(&vs);
7865 pipe.AddShader(&fs);
7866 pipe.SetMSAA(&pipe_ms_state_ci);
7867 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7868
7869 BeginCommandBuffer();
7870 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7871 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7872
Mark Young29927482016-05-04 14:38:51 -06007873 // Render triangle (the error should trigger on the attempt to draw).
7874 Draw(3, 1, 0, 0);
7875
7876 // Finalize recording of the command buffer
7877 EndCommandBuffer();
7878
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007879 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06007880
7881 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7882 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7883 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7884}
Mark Young29927482016-05-04 14:38:51 -06007885
Karl Schultz6addd812016-02-02 17:17:23 -07007886TEST_F(VkLayerTest, ClearCmdNoDraw) {
7887 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
7888 // to issuing a Draw
7889 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007890
Karl Schultz6addd812016-02-02 17:17:23 -07007891 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbour7e56d302016-03-02 15:12:01 -07007892 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007893 "vkCmdClearAttachments() issued on CB object ");
7894
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007895 ASSERT_NO_FATAL_FAILURE(InitState());
7896 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06007897
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007898 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007899 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7900 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007901
7902 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007903 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7904 ds_pool_ci.pNext = NULL;
7905 ds_pool_ci.maxSets = 1;
7906 ds_pool_ci.poolSizeCount = 1;
7907 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06007908
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007909 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007910 err =
7911 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007912 ASSERT_VK_SUCCESS(err);
7913
Tony Barboureb254902015-07-15 12:50:33 -06007914 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007915 dsl_binding.binding = 0;
7916 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7917 dsl_binding.descriptorCount = 1;
7918 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7919 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007920
Tony Barboureb254902015-07-15 12:50:33 -06007921 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007922 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7923 ds_layout_ci.pNext = NULL;
7924 ds_layout_ci.bindingCount = 1;
7925 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007926
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007927 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007928 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7929 &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007930 ASSERT_VK_SUCCESS(err);
7931
7932 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007933 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007934 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007935 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007936 alloc_info.descriptorPool = ds_pool;
7937 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007938 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7939 &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007940 ASSERT_VK_SUCCESS(err);
7941
Tony Barboureb254902015-07-15 12:50:33 -06007942 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007943 pipe_ms_state_ci.sType =
7944 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7945 pipe_ms_state_ci.pNext = NULL;
7946 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7947 pipe_ms_state_ci.sampleShadingEnable = 0;
7948 pipe_ms_state_ci.minSampleShading = 1.0;
7949 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007950
Tony Barboureb254902015-07-15 12:50:33 -06007951 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007952 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7953 pipeline_layout_ci.pNext = NULL;
7954 pipeline_layout_ci.setLayoutCount = 1;
7955 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007956
7957 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007958 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7959 &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007960 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007961
Karl Schultz6addd812016-02-02 17:17:23 -07007962 VkShaderObj vs(m_device, bindStateVertShaderText,
7963 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06007964 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07007965 // on more devices
7966 VkShaderObj fs(m_device, bindStateFragShaderText,
7967 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007968
Tony Barbour62e1a5b2015-08-06 10:16:07 -06007969 VkPipelineObj pipe(m_device);
7970 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007971 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06007972 pipe.SetMSAA(&pipe_ms_state_ci);
7973 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06007974
7975 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007976
Karl Schultz6addd812016-02-02 17:17:23 -07007977 // Main thing we care about for this test is that the VkImage obj we're
7978 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007979 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007980 VkClearAttachment color_attachment;
7981 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7982 color_attachment.clearValue.color.float32[0] = 1.0;
7983 color_attachment.clearValue.color.float32[1] = 1.0;
7984 color_attachment.clearValue.color.float32[2] = 1.0;
7985 color_attachment.clearValue.color.float32[3] = 1.0;
7986 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007987 VkClearRect clear_rect = {
7988 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007989
Karl Schultz6addd812016-02-02 17:17:23 -07007990 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
7991 &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007992
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007993 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007994
Chia-I Wuf7458c52015-10-26 21:10:41 +08007995 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7996 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7997 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007998}
7999
Karl Schultz6addd812016-02-02 17:17:23 -07008000TEST_F(VkLayerTest, VtxBufferBadIndex) {
8001 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008002
Karl Schultz6addd812016-02-02 17:17:23 -07008003 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008004 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07008005 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008006
Tobin Ehlis502480b2015-06-24 15:53:07 -06008007 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06008008 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06008009 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06008010
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008011 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008012 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8013 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008014
8015 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008016 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8017 ds_pool_ci.pNext = NULL;
8018 ds_pool_ci.maxSets = 1;
8019 ds_pool_ci.poolSizeCount = 1;
8020 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008021
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008022 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008023 err =
8024 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008025 ASSERT_VK_SUCCESS(err);
8026
Tony Barboureb254902015-07-15 12:50:33 -06008027 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008028 dsl_binding.binding = 0;
8029 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8030 dsl_binding.descriptorCount = 1;
8031 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8032 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008033
Tony Barboureb254902015-07-15 12:50:33 -06008034 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008035 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8036 ds_layout_ci.pNext = NULL;
8037 ds_layout_ci.bindingCount = 1;
8038 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008039
Tobin Ehlis502480b2015-06-24 15:53:07 -06008040 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008041 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8042 &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008043 ASSERT_VK_SUCCESS(err);
8044
8045 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008046 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008047 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008048 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008049 alloc_info.descriptorPool = ds_pool;
8050 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008051 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8052 &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008053 ASSERT_VK_SUCCESS(err);
8054
Tony Barboureb254902015-07-15 12:50:33 -06008055 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008056 pipe_ms_state_ci.sType =
8057 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8058 pipe_ms_state_ci.pNext = NULL;
8059 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8060 pipe_ms_state_ci.sampleShadingEnable = 0;
8061 pipe_ms_state_ci.minSampleShading = 1.0;
8062 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008063
Tony Barboureb254902015-07-15 12:50:33 -06008064 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008065 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8066 pipeline_layout_ci.pNext = NULL;
8067 pipeline_layout_ci.setLayoutCount = 1;
8068 pipeline_layout_ci.pSetLayouts = &ds_layout;
8069 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008070
Karl Schultz6addd812016-02-02 17:17:23 -07008071 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8072 &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008073 ASSERT_VK_SUCCESS(err);
8074
Karl Schultz6addd812016-02-02 17:17:23 -07008075 VkShaderObj vs(m_device, bindStateVertShaderText,
8076 VK_SHADER_STAGE_VERTEX_BIT, this);
8077 VkShaderObj fs(m_device, bindStateFragShaderText,
8078 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06008079 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07008080 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008081 VkPipelineObj pipe(m_device);
8082 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008083 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06008084 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008085 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008086 pipe.SetViewport(m_viewports);
8087 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008088 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06008089
8090 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008091 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8092 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06008093 // Don't care about actual data, just need to get to draw to flag error
8094 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz6addd812016-02-02 17:17:23 -07008095 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
8096 (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06008097 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06008098 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008099
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008100 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008101
Chia-I Wuf7458c52015-10-26 21:10:41 +08008102 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8103 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8104 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008105}
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06008106// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
8107TEST_F(VkLayerTest, InvalidImageLayout) {
8108 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
8109 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
8110 "images in the wrong layout when they're copied or transitioned.");
8111 // 3 in ValidateCmdBufImageLayouts
8112 // * -1 Attempt to submit cmd buf w/ deleted image
8113 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
8114 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
8115 m_errorMonitor->SetDesiredFailureMsg(
8116 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8117 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
8118
8119 ASSERT_NO_FATAL_FAILURE(InitState());
8120 // Create src & dst images to use for copy operations
8121 VkImage src_image;
8122 VkImage dst_image;
8123
8124 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8125 const int32_t tex_width = 32;
8126 const int32_t tex_height = 32;
8127
8128 VkImageCreateInfo image_create_info = {};
8129 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8130 image_create_info.pNext = NULL;
8131 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8132 image_create_info.format = tex_format;
8133 image_create_info.extent.width = tex_width;
8134 image_create_info.extent.height = tex_height;
8135 image_create_info.extent.depth = 1;
8136 image_create_info.mipLevels = 1;
8137 image_create_info.arrayLayers = 4;
8138 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8139 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8140 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8141 image_create_info.flags = 0;
8142
8143 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
8144 ASSERT_VK_SUCCESS(err);
8145 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
8146 ASSERT_VK_SUCCESS(err);
8147
8148 BeginCommandBuffer();
8149 VkImageCopy copyRegion;
8150 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8151 copyRegion.srcSubresource.mipLevel = 0;
8152 copyRegion.srcSubresource.baseArrayLayer = 0;
8153 copyRegion.srcSubresource.layerCount = 1;
8154 copyRegion.srcOffset.x = 0;
8155 copyRegion.srcOffset.y = 0;
8156 copyRegion.srcOffset.z = 0;
8157 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8158 copyRegion.dstSubresource.mipLevel = 0;
8159 copyRegion.dstSubresource.baseArrayLayer = 0;
8160 copyRegion.dstSubresource.layerCount = 1;
8161 copyRegion.dstOffset.x = 0;
8162 copyRegion.dstOffset.y = 0;
8163 copyRegion.dstOffset.z = 0;
8164 copyRegion.extent.width = 1;
8165 copyRegion.extent.height = 1;
8166 copyRegion.extent.depth = 1;
8167 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8168 m_errorMonitor->VerifyFound();
8169 // Now cause error due to src image layout changing
8170 m_errorMonitor->SetDesiredFailureMsg(
8171 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8172 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
8173 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8174 m_errorMonitor->VerifyFound();
8175 // Final src error is due to bad layout type
8176 m_errorMonitor->SetDesiredFailureMsg(
8177 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8178 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
8179 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8180 m_errorMonitor->VerifyFound();
8181 // Now verify same checks for dst
8182 m_errorMonitor->SetDesiredFailureMsg(
8183 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8184 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
8185 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8186 m_errorMonitor->VerifyFound();
8187 // Now cause error due to src image layout changing
8188 m_errorMonitor->SetDesiredFailureMsg(
8189 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8190 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
8191 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
8192 m_errorMonitor->VerifyFound();
8193 m_errorMonitor->SetDesiredFailureMsg(
8194 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8195 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
8196 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
8197 m_errorMonitor->VerifyFound();
8198 // Now cause error due to bad image layout transition in PipelineBarrier
8199 VkImageMemoryBarrier image_barrier[1] = {};
8200 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
8201 image_barrier[0].image = src_image;
8202 image_barrier[0].subresourceRange.layerCount = 2;
8203 image_barrier[0].subresourceRange.levelCount = 2;
8204 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8205 m_errorMonitor->SetDesiredFailureMsg(
8206 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8207 "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL.");
8208 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier);
8209 m_errorMonitor->VerifyFound();
8210
8211 // Finally some layout errors at RenderPass create time
8212 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
8213 VkAttachmentReference attach = {};
8214 // perf warning for GENERAL layout w/ non-DS input attachment
8215 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8216 VkSubpassDescription subpass = {};
8217 subpass.inputAttachmentCount = 1;
8218 subpass.pInputAttachments = &attach;
8219 VkRenderPassCreateInfo rpci = {};
8220 rpci.subpassCount = 1;
8221 rpci.pSubpasses = &subpass;
8222 rpci.attachmentCount = 1;
8223 VkAttachmentDescription attach_desc = {};
8224 attach_desc.format = VK_FORMAT_UNDEFINED;
8225 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -06008226 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06008227 VkRenderPass rp;
8228 m_errorMonitor->SetDesiredFailureMsg(
8229 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8230 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
8231 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8232 m_errorMonitor->VerifyFound();
8233 // error w/ non-general layout
8234 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
8235
8236 m_errorMonitor->SetDesiredFailureMsg(
8237 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8238 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
8239 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8240 m_errorMonitor->VerifyFound();
8241 subpass.inputAttachmentCount = 0;
8242 subpass.colorAttachmentCount = 1;
8243 subpass.pColorAttachments = &attach;
8244 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8245 // perf warning for GENERAL layout on color attachment
8246 m_errorMonitor->SetDesiredFailureMsg(
8247 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8248 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
8249 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8250 m_errorMonitor->VerifyFound();
8251 // error w/ non-color opt or GENERAL layout for color attachment
8252 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
8253 m_errorMonitor->SetDesiredFailureMsg(
8254 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8255 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
8256 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8257 m_errorMonitor->VerifyFound();
8258 subpass.colorAttachmentCount = 0;
8259 subpass.pDepthStencilAttachment = &attach;
8260 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8261 // perf warning for GENERAL layout on DS attachment
8262 m_errorMonitor->SetDesiredFailureMsg(
8263 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8264 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
8265 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8266 m_errorMonitor->VerifyFound();
8267 // error w/ non-ds opt or GENERAL layout for color attachment
8268 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
8269 m_errorMonitor->SetDesiredFailureMsg(
8270 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8271 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.");
8272 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8273 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -06008274 // For this error we need a valid renderpass so create default one
8275 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
8276 attach.attachment = 0;
8277 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
8278 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
8279 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
8280 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
8281 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
8282 // Can't do a CLEAR load on READ_ONLY initialLayout
8283 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8284 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
8285 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8287 " with invalid first layout "
8288 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
8289 "ONLY_OPTIMAL");
8290 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8291 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06008292
8293 vkDestroyImage(m_device->device(), src_image, NULL);
8294 vkDestroyImage(m_device->device(), dst_image, NULL);
8295}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008296#endif // DRAW_STATE_TESTS
8297
Tobin Ehlis0788f522015-05-26 16:11:58 -06008298#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06008299#if GTEST_IS_THREADSAFE
8300struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008301 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008302 VkEvent event;
8303 bool bailout;
8304};
8305
Karl Schultz6addd812016-02-02 17:17:23 -07008306extern "C" void *AddToCommandBuffer(void *arg) {
8307 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008308
Karl Schultz6addd812016-02-02 17:17:23 -07008309 for (int i = 0; i < 10000; i++) {
8310 vkCmdSetEvent(data->commandBuffer, data->event,
8311 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008312 if (data->bailout) {
8313 break;
8314 }
8315 }
8316 return NULL;
8317}
8318
Karl Schultz6addd812016-02-02 17:17:23 -07008319TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -06008320 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008321
Karl Schultz6addd812016-02-02 17:17:23 -07008322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8323 "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008324
Mike Stroyanaccf7692015-05-12 16:00:45 -06008325 ASSERT_NO_FATAL_FAILURE(InitState());
8326 ASSERT_NO_FATAL_FAILURE(InitViewport());
8327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8328
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008329 // Calls AllocateCommandBuffers
8330 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06008331
8332 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008333 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008334
8335 VkEventCreateInfo event_info;
8336 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008337 VkResult err;
8338
8339 memset(&event_info, 0, sizeof(event_info));
8340 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8341
Chia-I Wuf7458c52015-10-26 21:10:41 +08008342 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008343 ASSERT_VK_SUCCESS(err);
8344
Mike Stroyanaccf7692015-05-12 16:00:45 -06008345 err = vkResetEvent(device(), event);
8346 ASSERT_VK_SUCCESS(err);
8347
8348 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008349 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008350 data.event = event;
8351 data.bailout = false;
8352 m_errorMonitor->SetBailout(&data.bailout);
8353 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06008354 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008355 // Add many entries to command buffer from this thread at the same time.
8356 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06008357
Mike Stroyan4268d1f2015-07-13 14:45:35 -06008358 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008359 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008360
Mike Stroyan10b8cb72016-01-22 15:22:03 -07008361 m_errorMonitor->SetBailout(NULL);
8362
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008363 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008364
Chia-I Wuf7458c52015-10-26 21:10:41 +08008365 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008366}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008367#endif // GTEST_IS_THREADSAFE
8368#endif // THREADING_TESTS
8369
Chris Forbes9f7ff632015-05-25 11:13:08 +12008370#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07008371TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008373 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008374
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008375 ASSERT_NO_FATAL_FAILURE(InitState());
8376 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8377
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008378 VkShaderModule module;
8379 VkShaderModuleCreateInfo moduleCreateInfo;
8380 struct icd_spv_header spv;
8381
8382 spv.magic = ICD_SPV_MAGIC;
8383 spv.version = ICD_SPV_VERSION;
8384 spv.gen_magic = 0;
8385
8386 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
8387 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07008388 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008389 moduleCreateInfo.codeSize = 4;
8390 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008391 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008392
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008393 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008394}
8395
Karl Schultz6addd812016-02-02 17:17:23 -07008396TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008398 "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008399
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008400 ASSERT_NO_FATAL_FAILURE(InitState());
8401 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8402
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008403 VkShaderModule module;
8404 VkShaderModuleCreateInfo moduleCreateInfo;
8405 struct icd_spv_header spv;
8406
8407 spv.magic = ~ICD_SPV_MAGIC;
8408 spv.version = ICD_SPV_VERSION;
8409 spv.gen_magic = 0;
8410
8411 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
8412 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07008413 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008414 moduleCreateInfo.codeSize = sizeof(spv) + 10;
8415 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008416 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008417
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008418 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008419}
8420
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008421#if 0
8422// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -07008423TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008425 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008426
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008427 ASSERT_NO_FATAL_FAILURE(InitState());
8428 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8429
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008430 VkShaderModule module;
8431 VkShaderModuleCreateInfo moduleCreateInfo;
8432 struct icd_spv_header spv;
8433
8434 spv.magic = ICD_SPV_MAGIC;
8435 spv.version = ~ICD_SPV_VERSION;
8436 spv.gen_magic = 0;
8437
8438 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
8439 moduleCreateInfo.pNext = NULL;
8440
Karl Schultz6addd812016-02-02 17:17:23 -07008441 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008442 moduleCreateInfo.codeSize = sizeof(spv) + 10;
8443 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008444 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008445
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008446 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008447}
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008448#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008449
Karl Schultz6addd812016-02-02 17:17:23 -07008450TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008452 "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008453
Chris Forbes9f7ff632015-05-25 11:13:08 +12008454 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008455 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12008456
8457 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008458 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12008459 "\n"
8460 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07008461 "out gl_PerVertex {\n"
8462 " vec4 gl_Position;\n"
8463 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12008464 "void main(){\n"
8465 " gl_Position = vec4(1);\n"
8466 " x = 0;\n"
8467 "}\n";
8468 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008469 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12008470 "\n"
8471 "layout(location=0) out vec4 color;\n"
8472 "void main(){\n"
8473 " color = vec4(1);\n"
8474 "}\n";
8475
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008476 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8477 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12008478
8479 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008480 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12008481 pipe.AddShader(&vs);
8482 pipe.AddShader(&fs);
8483
Chris Forbes9f7ff632015-05-25 11:13:08 +12008484 VkDescriptorSetObj descriptorSet(m_device);
8485 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008486 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12008487
Tony Barbour5781e8f2015-08-04 16:23:11 -06008488 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12008489
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008490 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +12008491}
Chris Forbes9f7ff632015-05-25 11:13:08 +12008492
Karl Schultz6addd812016-02-02 17:17:23 -07008493TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008495 "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008496
Chris Forbes59cb88d2015-05-25 11:13:13 +12008497 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008498 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12008499
8500 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008501 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12008502 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07008503 "out gl_PerVertex {\n"
8504 " vec4 gl_Position;\n"
8505 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12008506 "void main(){\n"
8507 " gl_Position = vec4(1);\n"
8508 "}\n";
8509 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008510 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12008511 "\n"
8512 "layout(location=0) in float x;\n"
8513 "layout(location=0) out vec4 color;\n"
8514 "void main(){\n"
8515 " color = vec4(x);\n"
8516 "}\n";
8517
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008518 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8519 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12008520
8521 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008522 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12008523 pipe.AddShader(&vs);
8524 pipe.AddShader(&fs);
8525
Chris Forbes59cb88d2015-05-25 11:13:13 +12008526 VkDescriptorSetObj descriptorSet(m_device);
8527 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008528 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12008529
Tony Barbour5781e8f2015-08-04 16:23:11 -06008530 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12008531
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008532 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +12008533}
8534
Karl Schultz6addd812016-02-02 17:17:23 -07008535TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13008536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008537 "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +13008538
8539 ASSERT_NO_FATAL_FAILURE(InitState());
8540 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8541
8542 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008543 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008544 "\n"
8545 "out gl_PerVertex {\n"
8546 " vec4 gl_Position;\n"
8547 "};\n"
8548 "void main(){\n"
8549 " gl_Position = vec4(1);\n"
8550 "}\n";
8551 char const *fsSource =
8552 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008553 "\n"
8554 "in block { layout(location=0) float x; } ins;\n"
8555 "layout(location=0) out vec4 color;\n"
8556 "void main(){\n"
8557 " color = vec4(ins.x);\n"
8558 "}\n";
8559
8560 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8561 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8562
8563 VkPipelineObj pipe(m_device);
8564 pipe.AddColorAttachment();
8565 pipe.AddShader(&vs);
8566 pipe.AddShader(&fs);
8567
8568 VkDescriptorSetObj descriptorSet(m_device);
8569 descriptorSet.AppendDummy();
8570 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8571
8572 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8573
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008574 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13008575}
8576
Karl Schultz6addd812016-02-02 17:17:23 -07008577TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes0036fd12016-01-26 14:19:49 +13008578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbese9928822016-02-17 14:44:52 +13008579 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz6addd812016-02-02 17:17:23 -07008580 "output arr[2] of float32' vs 'ptr to "
8581 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +13008582
8583 ASSERT_NO_FATAL_FAILURE(InitState());
8584 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8585
8586 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008587 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13008588 "\n"
8589 "layout(location=0) out float x[2];\n"
8590 "out gl_PerVertex {\n"
8591 " vec4 gl_Position;\n"
8592 "};\n"
8593 "void main(){\n"
8594 " x[0] = 0; x[1] = 0;\n"
8595 " gl_Position = vec4(1);\n"
8596 "}\n";
8597 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008598 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13008599 "\n"
8600 "layout(location=0) in float x[3];\n"
8601 "layout(location=0) out vec4 color;\n"
8602 "void main(){\n"
8603 " color = vec4(x[0] + x[1] + x[2]);\n"
8604 "}\n";
8605
8606 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8607 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8608
8609 VkPipelineObj pipe(m_device);
8610 pipe.AddColorAttachment();
8611 pipe.AddShader(&vs);
8612 pipe.AddShader(&fs);
8613
8614 VkDescriptorSetObj descriptorSet(m_device);
8615 descriptorSet.AppendDummy();
8616 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8617
8618 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8619
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008620 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +13008621}
8622
Karl Schultz6addd812016-02-02 17:17:23 -07008623TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008625 "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008626
Chris Forbesb56af562015-05-25 11:13:17 +12008627 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008628 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12008629
8630 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008631 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12008632 "\n"
8633 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07008634 "out gl_PerVertex {\n"
8635 " vec4 gl_Position;\n"
8636 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12008637 "void main(){\n"
8638 " x = 0;\n"
8639 " gl_Position = vec4(1);\n"
8640 "}\n";
8641 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008642 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12008643 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008644 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbesb56af562015-05-25 11:13:17 +12008645 "layout(location=0) out vec4 color;\n"
8646 "void main(){\n"
8647 " color = vec4(x);\n"
8648 "}\n";
8649
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008650 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8651 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12008652
8653 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008654 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12008655 pipe.AddShader(&vs);
8656 pipe.AddShader(&fs);
8657
Chris Forbesb56af562015-05-25 11:13:17 +12008658 VkDescriptorSetObj descriptorSet(m_device);
8659 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008660 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12008661
Tony Barbour5781e8f2015-08-04 16:23:11 -06008662 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12008663
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008664 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +12008665}
8666
Karl Schultz6addd812016-02-02 17:17:23 -07008667TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13008668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008669 "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +13008670
8671 ASSERT_NO_FATAL_FAILURE(InitState());
8672 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8673
8674 char const *vsSource =
8675 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008676 "\n"
8677 "out block { layout(location=0) int x; } outs;\n"
8678 "out gl_PerVertex {\n"
8679 " vec4 gl_Position;\n"
8680 "};\n"
8681 "void main(){\n"
8682 " outs.x = 0;\n"
8683 " gl_Position = vec4(1);\n"
8684 "}\n";
8685 char const *fsSource =
8686 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008687 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008688 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbesa3e85f62016-01-15 14:53:11 +13008689 "layout(location=0) out vec4 color;\n"
8690 "void main(){\n"
8691 " color = vec4(ins.x);\n"
8692 "}\n";
8693
8694 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8695 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8696
8697 VkPipelineObj pipe(m_device);
8698 pipe.AddColorAttachment();
8699 pipe.AddShader(&vs);
8700 pipe.AddShader(&fs);
8701
8702 VkDescriptorSetObj descriptorSet(m_device);
8703 descriptorSet.AppendDummy();
8704 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8705
8706 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8707
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008708 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13008709}
8710
8711TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
8712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8713 "location 0.0 which is not written by vertex shader");
8714
8715 ASSERT_NO_FATAL_FAILURE(InitState());
8716 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8717
8718 char const *vsSource =
8719 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008720 "\n"
8721 "out block { layout(location=1) float x; } outs;\n"
8722 "out gl_PerVertex {\n"
8723 " vec4 gl_Position;\n"
8724 "};\n"
8725 "void main(){\n"
8726 " outs.x = 0;\n"
8727 " gl_Position = vec4(1);\n"
8728 "}\n";
8729 char const *fsSource =
8730 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008731 "\n"
8732 "in block { layout(location=0) float x; } ins;\n"
8733 "layout(location=0) out vec4 color;\n"
8734 "void main(){\n"
8735 " color = vec4(ins.x);\n"
8736 "}\n";
8737
8738 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8739 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8740
8741 VkPipelineObj pipe(m_device);
8742 pipe.AddColorAttachment();
8743 pipe.AddShader(&vs);
8744 pipe.AddShader(&fs);
8745
8746 VkDescriptorSetObj descriptorSet(m_device);
8747 descriptorSet.AppendDummy();
8748 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8749
8750 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8751
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008752 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13008753}
8754
8755TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
8756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8757 "location 0.1 which is not written by vertex shader");
8758
8759 ASSERT_NO_FATAL_FAILURE(InitState());
8760 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8761
8762 char const *vsSource =
8763 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008764 "\n"
8765 "out block { layout(location=0, component=0) float x; } outs;\n"
8766 "out gl_PerVertex {\n"
8767 " vec4 gl_Position;\n"
8768 "};\n"
8769 "void main(){\n"
8770 " outs.x = 0;\n"
8771 " gl_Position = vec4(1);\n"
8772 "}\n";
8773 char const *fsSource =
8774 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008775 "\n"
8776 "in block { layout(location=0, component=1) float x; } ins;\n"
8777 "layout(location=0) out vec4 color;\n"
8778 "void main(){\n"
8779 " color = vec4(ins.x);\n"
8780 "}\n";
8781
8782 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8783 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8784
8785 VkPipelineObj pipe(m_device);
8786 pipe.AddColorAttachment();
8787 pipe.AddShader(&vs);
8788 pipe.AddShader(&fs);
8789
8790 VkDescriptorSetObj descriptorSet(m_device);
8791 descriptorSet.AppendDummy();
8792 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8793
8794 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8795
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008796 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13008797}
8798
Karl Schultz6addd812016-02-02 17:17:23 -07008799TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008801 "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008802
Chris Forbesde136e02015-05-25 11:13:28 +12008803 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12008805
8806 VkVertexInputBindingDescription input_binding;
8807 memset(&input_binding, 0, sizeof(input_binding));
8808
8809 VkVertexInputAttributeDescription input_attrib;
8810 memset(&input_attrib, 0, sizeof(input_attrib));
8811 input_attrib.format = VK_FORMAT_R32_SFLOAT;
8812
8813 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008814 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12008815 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07008816 "out gl_PerVertex {\n"
8817 " vec4 gl_Position;\n"
8818 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +12008819 "void main(){\n"
8820 " gl_Position = vec4(1);\n"
8821 "}\n";
8822 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008823 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12008824 "\n"
8825 "layout(location=0) out vec4 color;\n"
8826 "void main(){\n"
8827 " color = vec4(1);\n"
8828 "}\n";
8829
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008830 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8831 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12008832
8833 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008834 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12008835 pipe.AddShader(&vs);
8836 pipe.AddShader(&fs);
8837
8838 pipe.AddVertexInputBindings(&input_binding, 1);
8839 pipe.AddVertexInputAttribs(&input_attrib, 1);
8840
Chris Forbesde136e02015-05-25 11:13:28 +12008841 VkDescriptorSetObj descriptorSet(m_device);
8842 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008843 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12008844
Tony Barbour5781e8f2015-08-04 16:23:11 -06008845 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12008846
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008847 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +12008848}
8849
Karl Schultz6addd812016-02-02 17:17:23 -07008850TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008852 "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +13008853
8854 ASSERT_NO_FATAL_FAILURE(InitState());
8855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8856
8857 VkVertexInputBindingDescription input_binding;
8858 memset(&input_binding, 0, sizeof(input_binding));
8859
8860 VkVertexInputAttributeDescription input_attrib;
8861 memset(&input_attrib, 0, sizeof(input_attrib));
8862 input_attrib.format = VK_FORMAT_R32_SFLOAT;
8863
8864 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008865 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13008866 "\n"
8867 "layout(location=1) in float x;\n"
8868 "out gl_PerVertex {\n"
8869 " vec4 gl_Position;\n"
8870 "};\n"
8871 "void main(){\n"
8872 " gl_Position = vec4(x);\n"
8873 "}\n";
8874 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008875 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13008876 "\n"
8877 "layout(location=0) out vec4 color;\n"
8878 "void main(){\n"
8879 " color = vec4(1);\n"
8880 "}\n";
8881
8882 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8883 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8884
8885 VkPipelineObj pipe(m_device);
8886 pipe.AddColorAttachment();
8887 pipe.AddShader(&vs);
8888 pipe.AddShader(&fs);
8889
8890 pipe.AddVertexInputBindings(&input_binding, 1);
8891 pipe.AddVertexInputAttribs(&input_attrib, 1);
8892
8893 VkDescriptorSetObj descriptorSet(m_device);
8894 descriptorSet.AppendDummy();
8895 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8896
8897 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8898
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008899 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +13008900}
8901
Karl Schultz6addd812016-02-02 17:17:23 -07008902TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
8903 m_errorMonitor->SetDesiredFailureMsg(
8904 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008905 "VS consumes input at location 0 but not provided");
8906
Chris Forbes62e8e502015-05-25 11:13:29 +12008907 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008908 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12008909
8910 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008911 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12008912 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008913 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -07008914 "out gl_PerVertex {\n"
8915 " vec4 gl_Position;\n"
8916 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12008917 "void main(){\n"
8918 " gl_Position = x;\n"
8919 "}\n";
8920 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008921 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12008922 "\n"
8923 "layout(location=0) out vec4 color;\n"
8924 "void main(){\n"
8925 " color = vec4(1);\n"
8926 "}\n";
8927
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008928 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8929 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12008930
8931 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008932 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12008933 pipe.AddShader(&vs);
8934 pipe.AddShader(&fs);
8935
Chris Forbes62e8e502015-05-25 11:13:29 +12008936 VkDescriptorSetObj descriptorSet(m_device);
8937 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008938 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12008939
Tony Barbour5781e8f2015-08-04 16:23:11 -06008940 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12008941
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008942 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +12008943}
8944
Karl Schultz6addd812016-02-02 17:17:23 -07008945TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
8946 m_errorMonitor->SetDesiredFailureMsg(
8947 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008948 "location 0 does not match VS input type");
8949
Chris Forbesc97d98e2015-05-25 11:13:31 +12008950 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12008952
8953 VkVertexInputBindingDescription input_binding;
8954 memset(&input_binding, 0, sizeof(input_binding));
8955
8956 VkVertexInputAttributeDescription input_attrib;
8957 memset(&input_attrib, 0, sizeof(input_attrib));
8958 input_attrib.format = VK_FORMAT_R32_SFLOAT;
8959
8960 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008961 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12008962 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008963 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07008964 "out gl_PerVertex {\n"
8965 " vec4 gl_Position;\n"
8966 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12008967 "void main(){\n"
8968 " gl_Position = vec4(x);\n"
8969 "}\n";
8970 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008971 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12008972 "\n"
8973 "layout(location=0) out vec4 color;\n"
8974 "void main(){\n"
8975 " color = vec4(1);\n"
8976 "}\n";
8977
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008978 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8979 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12008980
8981 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008982 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12008983 pipe.AddShader(&vs);
8984 pipe.AddShader(&fs);
8985
8986 pipe.AddVertexInputBindings(&input_binding, 1);
8987 pipe.AddVertexInputAttribs(&input_attrib, 1);
8988
Chris Forbesc97d98e2015-05-25 11:13:31 +12008989 VkDescriptorSetObj descriptorSet(m_device);
8990 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008991 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12008992
Tony Barbour5781e8f2015-08-04 16:23:11 -06008993 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12008994
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008995 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +12008996}
8997
Chris Forbesc68b43c2016-04-06 11:18:47 +12008998TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
8999 m_errorMonitor->SetDesiredFailureMsg(
9000 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9001 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
9002
9003 ASSERT_NO_FATAL_FAILURE(InitState());
9004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9005
9006 char const *vsSource =
9007 "#version 450\n"
9008 "\n"
9009 "out gl_PerVertex {\n"
9010 " vec4 gl_Position;\n"
9011 "};\n"
9012 "void main(){\n"
9013 " gl_Position = vec4(1);\n"
9014 "}\n";
9015 char const *fsSource =
9016 "#version 450\n"
9017 "\n"
9018 "layout(location=0) out vec4 color;\n"
9019 "void main(){\n"
9020 " color = vec4(1);\n"
9021 "}\n";
9022
9023 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9024 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9025
9026 VkPipelineObj pipe(m_device);
9027 pipe.AddColorAttachment();
9028 pipe.AddShader(&vs);
9029 pipe.AddShader(&vs);
9030 pipe.AddShader(&fs);
9031
9032 VkDescriptorSetObj descriptorSet(m_device);
9033 descriptorSet.AppendDummy();
9034 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9035
9036 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9037
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009038 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +12009039}
9040
Karl Schultz6addd812016-02-02 17:17:23 -07009041TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009042 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13009043
9044 ASSERT_NO_FATAL_FAILURE(InitState());
9045 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9046
9047 VkVertexInputBindingDescription input_binding;
9048 memset(&input_binding, 0, sizeof(input_binding));
9049
9050 VkVertexInputAttributeDescription input_attribs[2];
9051 memset(input_attribs, 0, sizeof(input_attribs));
9052
9053 for (int i = 0; i < 2; i++) {
9054 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
9055 input_attribs[i].location = i;
9056 }
9057
9058 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009059 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009060 "\n"
9061 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009062 "out gl_PerVertex {\n"
9063 " vec4 gl_Position;\n"
9064 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009065 "void main(){\n"
9066 " gl_Position = x[0] + x[1];\n"
9067 "}\n";
9068 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009069 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009070 "\n"
9071 "layout(location=0) out vec4 color;\n"
9072 "void main(){\n"
9073 " color = vec4(1);\n"
9074 "}\n";
9075
9076 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9077 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9078
9079 VkPipelineObj pipe(m_device);
9080 pipe.AddColorAttachment();
9081 pipe.AddShader(&vs);
9082 pipe.AddShader(&fs);
9083
9084 pipe.AddVertexInputBindings(&input_binding, 1);
9085 pipe.AddVertexInputAttribs(input_attribs, 2);
9086
9087 VkDescriptorSetObj descriptorSet(m_device);
9088 descriptorSet.AppendDummy();
9089 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9090
9091 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9092
9093 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009094 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +13009095}
9096
Chris Forbes2682b242015-11-24 11:13:14 +13009097TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
9098{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009099 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13009100
9101 ASSERT_NO_FATAL_FAILURE(InitState());
9102 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9103
9104 VkVertexInputBindingDescription input_binding;
9105 memset(&input_binding, 0, sizeof(input_binding));
9106
9107 VkVertexInputAttributeDescription input_attribs[2];
9108 memset(input_attribs, 0, sizeof(input_attribs));
9109
9110 for (int i = 0; i < 2; i++) {
9111 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
9112 input_attribs[i].location = i;
9113 }
9114
9115 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009116 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009117 "\n"
9118 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -07009119 "out gl_PerVertex {\n"
9120 " vec4 gl_Position;\n"
9121 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009122 "void main(){\n"
9123 " gl_Position = x[0] + x[1];\n"
9124 "}\n";
9125 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009126 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009127 "\n"
9128 "layout(location=0) out vec4 color;\n"
9129 "void main(){\n"
9130 " color = vec4(1);\n"
9131 "}\n";
9132
9133 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9134 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9135
9136 VkPipelineObj pipe(m_device);
9137 pipe.AddColorAttachment();
9138 pipe.AddShader(&vs);
9139 pipe.AddShader(&fs);
9140
9141 pipe.AddVertexInputBindings(&input_binding, 1);
9142 pipe.AddVertexInputAttribs(input_attribs, 2);
9143
9144 VkDescriptorSetObj descriptorSet(m_device);
9145 descriptorSet.AppendDummy();
9146 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9147
9148 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9149
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009150 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +13009151}
Chris Forbes2682b242015-11-24 11:13:14 +13009152
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009153TEST_F(VkLayerTest, CreatePipelineSimplePositive)
9154{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009155 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009156
9157 ASSERT_NO_FATAL_FAILURE(InitState());
9158 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9159
9160 char const *vsSource =
9161 "#version 450\n"
9162 "out gl_PerVertex {\n"
9163 " vec4 gl_Position;\n"
9164 "};\n"
9165 "void main(){\n"
9166 " gl_Position = vec4(0);\n"
9167 "}\n";
9168 char const *fsSource =
9169 "#version 450\n"
9170 "\n"
9171 "layout(location=0) out vec4 color;\n"
9172 "void main(){\n"
9173 " color = vec4(1);\n"
9174 "}\n";
9175
9176 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9177 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9178
9179 VkPipelineObj pipe(m_device);
9180 pipe.AddColorAttachment();
9181 pipe.AddShader(&vs);
9182 pipe.AddShader(&fs);
9183
9184 VkDescriptorSetObj descriptorSet(m_device);
9185 descriptorSet.AppendDummy();
9186 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9187
9188 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9189
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009190 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009191}
9192
Chris Forbes912c9192016-04-05 17:50:35 +12009193TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch)
9194{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009195 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +12009196
9197 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
9198
9199 ASSERT_NO_FATAL_FAILURE(InitState());
9200 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9201
9202 char const *vsSource =
9203 "#version 450\n"
9204 "out gl_PerVertex {\n"
9205 " vec4 gl_Position;\n"
9206 "};\n"
9207 "layout(location=0) out vec3 x;\n"
9208 "layout(location=1) out ivec3 y;\n"
9209 "layout(location=2) out vec3 z;\n"
9210 "void main(){\n"
9211 " gl_Position = vec4(0);\n"
9212 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
9213 "}\n";
9214 char const *fsSource =
9215 "#version 450\n"
9216 "\n"
9217 "layout(location=0) out vec4 color;\n"
9218 "layout(location=0) in float x;\n"
9219 "layout(location=1) flat in int y;\n"
9220 "layout(location=2) in vec2 z;\n"
9221 "void main(){\n"
9222 " color = vec4(1 + x + y + z.x);\n"
9223 "}\n";
9224
9225 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9226 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9227
9228 VkPipelineObj pipe(m_device);
9229 pipe.AddColorAttachment();
9230 pipe.AddShader(&vs);
9231 pipe.AddShader(&fs);
9232
9233 VkDescriptorSetObj descriptorSet(m_device);
9234 descriptorSet.AppendDummy();
9235 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9236
9237 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9238
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009239 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +12009240}
9241
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009242TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
9243{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009244 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009245
9246 ASSERT_NO_FATAL_FAILURE(InitState());
9247 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9248
Chris Forbesc1e852d2016-04-04 19:26:42 +12009249 if (!m_device->phy().features().tessellationShader) {
9250 printf("Device does not support tessellation shaders; skipped.\n");
9251 return;
9252 }
9253
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009254 char const *vsSource =
9255 "#version 450\n"
9256 "void main(){}\n";
9257 char const *tcsSource =
9258 "#version 450\n"
9259 "layout(location=0) out int x[];\n"
9260 "layout(vertices=3) out;\n"
9261 "void main(){\n"
9262 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
9263 " gl_TessLevelInner[0] = 1;\n"
9264 " x[gl_InvocationID] = gl_InvocationID;\n"
9265 "}\n";
9266 char const *tesSource =
9267 "#version 450\n"
9268 "layout(triangles, equal_spacing, cw) in;\n"
9269 "layout(location=0) in int x[];\n"
9270 "out gl_PerVertex { vec4 gl_Position; };\n"
9271 "void main(){\n"
9272 " gl_Position.xyz = gl_TessCoord;\n"
9273 " gl_Position.w = x[0] + x[1] + x[2];\n"
9274 "}\n";
9275 char const *fsSource =
9276 "#version 450\n"
9277 "layout(location=0) out vec4 color;\n"
9278 "void main(){\n"
9279 " color = vec4(1);\n"
9280 "}\n";
9281
9282 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9283 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
9284 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
9285 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9286
9287 VkPipelineInputAssemblyStateCreateInfo iasci{
9288 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
9289 nullptr,
9290 0,
9291 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
9292 VK_FALSE};
9293
Chris Forbesb4cacb62016-04-04 19:15:00 +12009294 VkPipelineTessellationStateCreateInfo tsci{
9295 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
9296 nullptr,
9297 0,
9298 3};
9299
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009300 VkPipelineObj pipe(m_device);
9301 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +12009302 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009303 pipe.AddColorAttachment();
9304 pipe.AddShader(&vs);
9305 pipe.AddShader(&tcs);
9306 pipe.AddShader(&tes);
9307 pipe.AddShader(&fs);
9308
9309 VkDescriptorSetObj descriptorSet(m_device);
9310 descriptorSet.AppendDummy();
9311 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9312
9313 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9314
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009315 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009316}
9317
Chris Forbesa0ab8152016-04-20 13:34:27 +12009318TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive)
9319{
9320 m_errorMonitor->ExpectSuccess();
9321
9322 ASSERT_NO_FATAL_FAILURE(InitState());
9323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9324
9325 if (!m_device->phy().features().geometryShader) {
9326 printf("Device does not support geometry shaders; skipped.\n");
9327 return;
9328 }
9329
9330 char const *vsSource =
9331 "#version 450\n"
9332 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
9333 "void main(){\n"
9334 " vs_out.x = vec4(1);\n"
9335 "}\n";
9336 char const *gsSource =
9337 "#version 450\n"
9338 "layout(triangles) in;\n"
9339 "layout(triangle_strip, max_vertices=3) out;\n"
9340 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
9341 "out gl_PerVertex { vec4 gl_Position; };\n"
9342 "void main() {\n"
9343 " gl_Position = gs_in[0].x;\n"
9344 " EmitVertex();\n"
9345 "}\n";
9346 char const *fsSource =
9347 "#version 450\n"
9348 "layout(location=0) out vec4 color;\n"
9349 "void main(){\n"
9350 " color = vec4(1);\n"
9351 "}\n";
9352
9353 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9354 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
9355 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9356
9357 VkPipelineObj pipe(m_device);
9358 pipe.AddColorAttachment();
9359 pipe.AddShader(&vs);
9360 pipe.AddShader(&gs);
9361 pipe.AddShader(&fs);
9362
9363 VkDescriptorSetObj descriptorSet(m_device);
9364 descriptorSet.AppendDummy();
9365 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9366
9367 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9368
9369 m_errorMonitor->VerifyNotFound();
9370}
9371
Chris Forbesa0193bc2016-04-04 19:19:47 +12009372TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
9373{
9374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9375 "is per-vertex in tessellation control shader stage "
9376 "but per-patch in tessellation evaluation shader stage");
9377
9378 ASSERT_NO_FATAL_FAILURE(InitState());
9379 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9380
Chris Forbesc1e852d2016-04-04 19:26:42 +12009381 if (!m_device->phy().features().tessellationShader) {
9382 printf("Device does not support tessellation shaders; skipped.\n");
9383 return;
9384 }
9385
Chris Forbesa0193bc2016-04-04 19:19:47 +12009386 char const *vsSource =
9387 "#version 450\n"
9388 "void main(){}\n";
9389 char const *tcsSource =
9390 "#version 450\n"
9391 "layout(location=0) out int x[];\n"
9392 "layout(vertices=3) out;\n"
9393 "void main(){\n"
9394 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
9395 " gl_TessLevelInner[0] = 1;\n"
9396 " x[gl_InvocationID] = gl_InvocationID;\n"
9397 "}\n";
9398 char const *tesSource =
9399 "#version 450\n"
9400 "layout(triangles, equal_spacing, cw) in;\n"
9401 "layout(location=0) patch in int x;\n"
9402 "out gl_PerVertex { vec4 gl_Position; };\n"
9403 "void main(){\n"
9404 " gl_Position.xyz = gl_TessCoord;\n"
9405 " gl_Position.w = x;\n"
9406 "}\n";
9407 char const *fsSource =
9408 "#version 450\n"
9409 "layout(location=0) out vec4 color;\n"
9410 "void main(){\n"
9411 " color = vec4(1);\n"
9412 "}\n";
9413
9414 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9415 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
9416 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
9417 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9418
9419 VkPipelineInputAssemblyStateCreateInfo iasci{
9420 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
9421 nullptr,
9422 0,
9423 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
9424 VK_FALSE};
9425
9426 VkPipelineTessellationStateCreateInfo tsci{
9427 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
9428 nullptr,
9429 0,
9430 3};
9431
9432 VkPipelineObj pipe(m_device);
9433 pipe.SetInputAssembly(&iasci);
9434 pipe.SetTessellation(&tsci);
9435 pipe.AddColorAttachment();
9436 pipe.AddShader(&vs);
9437 pipe.AddShader(&tcs);
9438 pipe.AddShader(&tes);
9439 pipe.AddShader(&fs);
9440
9441 VkDescriptorSetObj descriptorSet(m_device);
9442 descriptorSet.AppendDummy();
9443 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9444
9445 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9446
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009447 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +12009448}
9449
Karl Schultz6addd812016-02-02 17:17:23 -07009450TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
9451 m_errorMonitor->SetDesiredFailureMsg(
9452 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009453 "Duplicate vertex input binding descriptions for binding 0");
9454
Chris Forbes280ba2c2015-06-12 11:16:41 +12009455 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009456 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12009457
9458 /* Two binding descriptions for binding 0 */
9459 VkVertexInputBindingDescription input_bindings[2];
9460 memset(input_bindings, 0, sizeof(input_bindings));
9461
9462 VkVertexInputAttributeDescription input_attrib;
9463 memset(&input_attrib, 0, sizeof(input_attrib));
9464 input_attrib.format = VK_FORMAT_R32_SFLOAT;
9465
9466 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009467 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12009468 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009469 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07009470 "out gl_PerVertex {\n"
9471 " vec4 gl_Position;\n"
9472 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12009473 "void main(){\n"
9474 " gl_Position = vec4(x);\n"
9475 "}\n";
9476 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009477 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12009478 "\n"
9479 "layout(location=0) out vec4 color;\n"
9480 "void main(){\n"
9481 " color = vec4(1);\n"
9482 "}\n";
9483
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009484 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9485 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +12009486
9487 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009488 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12009489 pipe.AddShader(&vs);
9490 pipe.AddShader(&fs);
9491
9492 pipe.AddVertexInputBindings(input_bindings, 2);
9493 pipe.AddVertexInputAttribs(&input_attrib, 1);
9494
Chris Forbes280ba2c2015-06-12 11:16:41 +12009495 VkDescriptorSetObj descriptorSet(m_device);
9496 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009497 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12009498
Tony Barbour5781e8f2015-08-04 16:23:11 -06009499 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12009500
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009501 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +12009502}
Chris Forbes8f68b562015-05-25 11:13:32 +12009503
Chris Forbes35efec72016-04-21 14:32:08 +12009504TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
9505 m_errorMonitor->ExpectSuccess();
9506
9507 ASSERT_NO_FATAL_FAILURE(InitState());
9508 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9509
9510 if (!m_device->phy().features().tessellationShader) {
9511 printf("Device does not support 64bit vertex attributes; skipped.\n");
9512 return;
9513 }
9514
9515 VkVertexInputBindingDescription input_bindings[1];
9516 memset(input_bindings, 0, sizeof(input_bindings));
9517
9518 VkVertexInputAttributeDescription input_attribs[4];
9519 memset(input_attribs, 0, sizeof(input_attribs));
9520 input_attribs[0].location = 0;
9521 input_attribs[0].offset = 0;
9522 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9523 input_attribs[1].location = 2;
9524 input_attribs[1].offset = 32;
9525 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9526 input_attribs[2].location = 4;
9527 input_attribs[2].offset = 64;
9528 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9529 input_attribs[3].location = 6;
9530 input_attribs[3].offset = 96;
9531 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9532
9533 char const *vsSource =
9534 "#version 450\n"
9535 "\n"
9536 "layout(location=0) in dmat4 x;\n"
9537 "out gl_PerVertex {\n"
9538 " vec4 gl_Position;\n"
9539 "};\n"
9540 "void main(){\n"
9541 " gl_Position = vec4(x[0][0]);\n"
9542 "}\n";
9543 char const *fsSource =
9544 "#version 450\n"
9545 "\n"
9546 "layout(location=0) out vec4 color;\n"
9547 "void main(){\n"
9548 " color = vec4(1);\n"
9549 "}\n";
9550
9551 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9552 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9553
9554 VkPipelineObj pipe(m_device);
9555 pipe.AddColorAttachment();
9556 pipe.AddShader(&vs);
9557 pipe.AddShader(&fs);
9558
9559 pipe.AddVertexInputBindings(input_bindings, 1);
9560 pipe.AddVertexInputAttribs(input_attribs, 4);
9561
9562 VkDescriptorSetObj descriptorSet(m_device);
9563 descriptorSet.AppendDummy();
9564 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9565
9566 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9567
9568 m_errorMonitor->VerifyNotFound();
9569}
9570
Karl Schultz6addd812016-02-02 17:17:23 -07009571TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009573 "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009574
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009575 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009576
9577 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009578 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009579 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009580 "out gl_PerVertex {\n"
9581 " vec4 gl_Position;\n"
9582 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009583 "void main(){\n"
9584 " gl_Position = vec4(1);\n"
9585 "}\n";
9586 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009587 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009588 "\n"
9589 "void main(){\n"
9590 "}\n";
9591
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009592 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9593 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009594
9595 VkPipelineObj pipe(m_device);
9596 pipe.AddShader(&vs);
9597 pipe.AddShader(&fs);
9598
Chia-I Wu08accc62015-07-07 11:50:03 +08009599 /* set up CB 0, not written */
9600 pipe.AddColorAttachment();
9601 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009602
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009603 VkDescriptorSetObj descriptorSet(m_device);
9604 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009605 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009606
Tony Barbour5781e8f2015-08-04 16:23:11 -06009607 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009608
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009609 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009610}
9611
Karl Schultz6addd812016-02-02 17:17:23 -07009612TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Karl Schultz6addd812016-02-02 17:17:23 -07009613 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009614 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009615 "FS writes to output location 1 with no matching attachment");
9616
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009617 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009618
9619 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009620 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009621 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009622 "out gl_PerVertex {\n"
9623 " vec4 gl_Position;\n"
9624 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009625 "void main(){\n"
9626 " gl_Position = vec4(1);\n"
9627 "}\n";
9628 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009629 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009630 "\n"
9631 "layout(location=0) out vec4 x;\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009632 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009633 "void main(){\n"
9634 " x = vec4(1);\n"
9635 " y = vec4(1);\n"
9636 "}\n";
9637
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009638 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9639 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009640
9641 VkPipelineObj pipe(m_device);
9642 pipe.AddShader(&vs);
9643 pipe.AddShader(&fs);
9644
Chia-I Wu08accc62015-07-07 11:50:03 +08009645 /* set up CB 0, not written */
9646 pipe.AddColorAttachment();
9647 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009648 /* FS writes CB 1, but we don't configure it */
9649
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009650 VkDescriptorSetObj descriptorSet(m_device);
9651 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009652 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009653
Tony Barbour5781e8f2015-08-04 16:23:11 -06009654 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009655
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009656 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009657}
9658
Karl Schultz6addd812016-02-02 17:17:23 -07009659TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009661 "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009662
Chris Forbesa36d69e2015-05-25 11:13:44 +12009663 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12009664
9665 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009666 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12009667 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009668 "out gl_PerVertex {\n"
9669 " vec4 gl_Position;\n"
9670 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12009671 "void main(){\n"
9672 " gl_Position = vec4(1);\n"
9673 "}\n";
9674 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009675 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12009676 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009677 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbesa36d69e2015-05-25 11:13:44 +12009678 "void main(){\n"
9679 " x = ivec4(1);\n"
9680 "}\n";
9681
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009682 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9683 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +12009684
9685 VkPipelineObj pipe(m_device);
9686 pipe.AddShader(&vs);
9687 pipe.AddShader(&fs);
9688
Chia-I Wu08accc62015-07-07 11:50:03 +08009689 /* set up CB 0; type is UNORM by default */
9690 pipe.AddColorAttachment();
9691 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12009692
Chris Forbesa36d69e2015-05-25 11:13:44 +12009693 VkDescriptorSetObj descriptorSet(m_device);
9694 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009695 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12009696
Tony Barbour5781e8f2015-08-04 16:23:11 -06009697 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12009698
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009699 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +12009700}
Chris Forbes7b1b8932015-06-05 14:43:36 +12009701
Karl Schultz6addd812016-02-02 17:17:23 -07009702TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009704 "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009705
Chris Forbes556c76c2015-08-14 12:04:59 +12009706 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12009707
9708 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009709 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12009710 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009711 "out gl_PerVertex {\n"
9712 " vec4 gl_Position;\n"
9713 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12009714 "void main(){\n"
9715 " gl_Position = vec4(1);\n"
9716 "}\n";
9717 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009718 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12009719 "\n"
9720 "layout(location=0) out vec4 x;\n"
9721 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
9722 "void main(){\n"
9723 " x = vec4(bar.y);\n"
9724 "}\n";
9725
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009726 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9727 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +12009728
Chris Forbes556c76c2015-08-14 12:04:59 +12009729 VkPipelineObj pipe(m_device);
9730 pipe.AddShader(&vs);
9731 pipe.AddShader(&fs);
9732
9733 /* set up CB 0; type is UNORM by default */
9734 pipe.AddColorAttachment();
9735 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9736
9737 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009738 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +12009739
9740 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9741
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009742 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +12009743}
9744
Chris Forbes5c59e902016-02-26 16:56:09 +13009745TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
9746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9747 "not declared in layout");
9748
9749 ASSERT_NO_FATAL_FAILURE(InitState());
9750
9751 char const *vsSource =
9752 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +13009753 "\n"
9754 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
9755 "out gl_PerVertex {\n"
9756 " vec4 gl_Position;\n"
9757 "};\n"
9758 "void main(){\n"
9759 " gl_Position = vec4(consts.x);\n"
9760 "}\n";
9761 char const *fsSource =
9762 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +13009763 "\n"
9764 "layout(location=0) out vec4 x;\n"
9765 "void main(){\n"
9766 " x = vec4(1);\n"
9767 "}\n";
9768
9769 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9770 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9771
9772 VkPipelineObj pipe(m_device);
9773 pipe.AddShader(&vs);
9774 pipe.AddShader(&fs);
9775
9776 /* set up CB 0; type is UNORM by default */
9777 pipe.AddColorAttachment();
9778 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9779
9780 VkDescriptorSetObj descriptorSet(m_device);
9781 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9782
9783 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9784
9785 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009786 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +13009787}
9788
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009789#endif // SHADER_CHECKER_TESTS
9790
9791#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -06009792TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Karl Schultz6addd812016-02-02 17:17:23 -07009793 m_errorMonitor->SetDesiredFailureMsg(
9794 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009795 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009796
9797 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009798
9799 // Create an image
9800 VkImage image;
9801
Karl Schultz6addd812016-02-02 17:17:23 -07009802 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9803 const int32_t tex_width = 32;
9804 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009805
9806 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009807 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9808 image_create_info.pNext = NULL;
9809 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9810 image_create_info.format = tex_format;
9811 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009812 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -07009813 image_create_info.extent.depth = 1;
9814 image_create_info.mipLevels = 1;
9815 image_create_info.arrayLayers = 1;
9816 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9817 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9818 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9819 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009820
9821 // Introduce error by sending down a bogus width extent
9822 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009823 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009824
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009825 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009826}
9827
Mark Youngc48c4c12016-04-11 14:26:49 -06009828TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
9829 m_errorMonitor->SetDesiredFailureMsg(
9830 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9831 "CreateImage extents is 0 for at least one required dimension");
9832
9833 ASSERT_NO_FATAL_FAILURE(InitState());
9834
9835 // Create an image
9836 VkImage image;
9837
9838 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9839 const int32_t tex_width = 32;
9840 const int32_t tex_height = 32;
9841
9842 VkImageCreateInfo image_create_info = {};
9843 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9844 image_create_info.pNext = NULL;
9845 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9846 image_create_info.format = tex_format;
9847 image_create_info.extent.width = tex_width;
9848 image_create_info.extent.height = tex_height;
9849 image_create_info.extent.depth = 1;
9850 image_create_info.mipLevels = 1;
9851 image_create_info.arrayLayers = 1;
9852 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9853 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9854 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9855 image_create_info.flags = 0;
9856
9857 // Introduce error by sending down a bogus width extent
9858 image_create_info.extent.width = 0;
9859 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
9860
9861 m_errorMonitor->VerifyFound();
9862}
9863
Karl Schultz6addd812016-02-02 17:17:23 -07009864TEST_F(VkLayerTest, UpdateBufferAlignment) {
9865 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mike Stroyana3082432015-09-25 13:39:21 -06009866
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009868 "dstOffset, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009869
Mike Stroyana3082432015-09-25 13:39:21 -06009870 ASSERT_NO_FATAL_FAILURE(InitState());
9871
9872 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9873 vk_testing::Buffer buffer;
9874 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
9875
9876 BeginCommandBuffer();
9877 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009878 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009879 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009880
Mike Stroyana3082432015-09-25 13:39:21 -06009881 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009883 "dataSize, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009884
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009885 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009886 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06009887 EndCommandBuffer();
9888}
9889
Karl Schultz6addd812016-02-02 17:17:23 -07009890TEST_F(VkLayerTest, FillBufferAlignment) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009892 "dstOffset, is not a multiple of 4");
Mike Stroyana3082432015-09-25 13:39:21 -06009893
9894 ASSERT_NO_FATAL_FAILURE(InitState());
9895
9896 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9897 vk_testing::Buffer buffer;
9898 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
9899
9900 BeginCommandBuffer();
9901 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009902 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009903 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009904
Mike Stroyana3082432015-09-25 13:39:21 -06009905 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009907 "size, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009908
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009909 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009910
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009911 m_errorMonitor->VerifyFound();
9912
Mike Stroyana3082432015-09-25 13:39:21 -06009913 EndCommandBuffer();
9914}
9915
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009916#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +12009917
Tobin Ehliscde08892015-09-22 10:11:37 -06009918#if IMAGE_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07009919TEST_F(VkLayerTest, InvalidImageView) {
9920 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -06009921
Karl Schultz6addd812016-02-02 17:17:23 -07009922 m_errorMonitor->SetDesiredFailureMsg(
9923 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009924 "vkCreateImageView called with baseMipLevel 10 ");
9925
Tobin Ehliscde08892015-09-22 10:11:37 -06009926 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -06009927
Mike Stroyana3082432015-09-25 13:39:21 -06009928 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -07009929 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -06009930
Karl Schultz6addd812016-02-02 17:17:23 -07009931 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9932 const int32_t tex_width = 32;
9933 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -06009934
9935 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009936 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9937 image_create_info.pNext = NULL;
9938 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9939 image_create_info.format = tex_format;
9940 image_create_info.extent.width = tex_width;
9941 image_create_info.extent.height = tex_height;
9942 image_create_info.extent.depth = 1;
9943 image_create_info.mipLevels = 1;
9944 image_create_info.arrayLayers = 1;
9945 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9946 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9947 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9948 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -06009949
Chia-I Wuf7458c52015-10-26 21:10:41 +08009950 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -06009951 ASSERT_VK_SUCCESS(err);
9952
9953 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009954 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9955 image_view_create_info.image = image;
9956 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
9957 image_view_create_info.format = tex_format;
9958 image_view_create_info.subresourceRange.layerCount = 1;
9959 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
9960 image_view_create_info.subresourceRange.levelCount = 1;
9961 image_view_create_info.subresourceRange.aspectMask =
9962 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06009963
9964 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07009965 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
9966 &view);
Tobin Ehliscde08892015-09-22 10:11:37 -06009967
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009968 m_errorMonitor->VerifyFound();
Tobin Ehliscde08892015-09-22 10:11:37 -06009969}
Mike Stroyana3082432015-09-25 13:39:21 -06009970
Karl Schultz6addd812016-02-02 17:17:23 -07009971TEST_F(VkLayerTest, InvalidImageViewAspect) {
9972 VkResult err;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009973
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009975 "vkCreateImageView: Color image "
9976 "formats must have ONLY the "
9977 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009978
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009979 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009980
9981 // Create an image and try to create a view with an invalid aspectMask
Karl Schultz6addd812016-02-02 17:17:23 -07009982 VkImage image;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009983
Karl Schultz6addd812016-02-02 17:17:23 -07009984 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9985 const int32_t tex_width = 32;
9986 const int32_t tex_height = 32;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009987
9988 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009989 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9990 image_create_info.pNext = NULL;
9991 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9992 image_create_info.format = tex_format;
9993 image_create_info.extent.width = tex_width;
9994 image_create_info.extent.height = tex_height;
9995 image_create_info.extent.depth = 1;
9996 image_create_info.mipLevels = 1;
9997 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9998 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9999 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10000 image_create_info.flags = 0;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010001
Chia-I Wuf7458c52015-10-26 21:10:41 +080010002 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010003 ASSERT_VK_SUCCESS(err);
10004
10005 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010006 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10007 image_view_create_info.image = image;
10008 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
10009 image_view_create_info.format = tex_format;
10010 image_view_create_info.subresourceRange.baseMipLevel = 0;
10011 image_view_create_info.subresourceRange.levelCount = 1;
10012 // Cause an error by setting an invalid image aspect
10013 image_view_create_info.subresourceRange.aspectMask =
10014 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010015
10016 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070010017 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
10018 &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010019
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010020 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010021}
10022
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010023TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070010024 VkResult err;
10025 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010026
Karl Schultz6addd812016-02-02 17:17:23 -070010027 m_errorMonitor->SetDesiredFailureMsg(
10028 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010029 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010030
Mike Stroyana3082432015-09-25 13:39:21 -060010031 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010032
10033 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010034 VkImage srcImage;
10035 VkImage dstImage;
10036 VkDeviceMemory srcMem;
10037 VkDeviceMemory destMem;
10038 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010039
10040 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010041 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10042 image_create_info.pNext = NULL;
10043 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10044 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10045 image_create_info.extent.width = 32;
10046 image_create_info.extent.height = 32;
10047 image_create_info.extent.depth = 1;
10048 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010049 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070010050 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10051 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10052 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10053 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010054
Karl Schultz6addd812016-02-02 17:17:23 -070010055 err =
10056 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010057 ASSERT_VK_SUCCESS(err);
10058
Karl Schultz6addd812016-02-02 17:17:23 -070010059 err =
10060 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010061 ASSERT_VK_SUCCESS(err);
10062
10063 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010064 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010065 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10066 memAlloc.pNext = NULL;
10067 memAlloc.allocationSize = 0;
10068 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010069
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010070 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010071 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010072 pass =
10073 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010074 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010075 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010076 ASSERT_VK_SUCCESS(err);
10077
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010078 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010079 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010080 pass =
10081 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010082 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010083 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010084 ASSERT_VK_SUCCESS(err);
10085
10086 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10087 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010088 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010089 ASSERT_VK_SUCCESS(err);
10090
10091 BeginCommandBuffer();
10092 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010093 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010094 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010095 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010096 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060010097 copyRegion.srcOffset.x = 0;
10098 copyRegion.srcOffset.y = 0;
10099 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010100 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010101 copyRegion.dstSubresource.mipLevel = 0;
10102 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010103 // Introduce failure by forcing the dst layerCount to differ from src
10104 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010105 copyRegion.dstOffset.x = 0;
10106 copyRegion.dstOffset.y = 0;
10107 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010108 copyRegion.extent.width = 1;
10109 copyRegion.extent.height = 1;
10110 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010111 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10112 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010113 EndCommandBuffer();
10114
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010115 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010116
Chia-I Wuf7458c52015-10-26 21:10:41 +080010117 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010118 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010119 vkFreeMemory(m_device->device(), srcMem, NULL);
10120 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010121}
10122
Tony Barbourd6673642016-05-05 14:46:39 -060010123TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
10124
10125 TEST_DESCRIPTION("Creating images with unsuported formats ");
10126
10127 ASSERT_NO_FATAL_FAILURE(InitState());
10128 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10129 VkImageObj image(m_device);
10130 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
10131 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
10132 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
10133 VK_IMAGE_TILING_OPTIMAL, 0);
10134 ASSERT_TRUE(image.initialized());
10135
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010136 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
10137 VkImageCreateInfo image_create_info;
10138 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10139 image_create_info.pNext = NULL;
10140 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10141 image_create_info.format = VK_FORMAT_UNDEFINED;
10142 image_create_info.extent.width = 32;
10143 image_create_info.extent.height = 32;
10144 image_create_info.extent.depth = 1;
10145 image_create_info.mipLevels = 1;
10146 image_create_info.arrayLayers = 1;
10147 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10148 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10149 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10150 image_create_info.flags = 0;
10151
10152 m_errorMonitor->SetDesiredFailureMsg(
10153 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10154 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
10155
10156 VkImage localImage;
10157 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
10158 m_errorMonitor->VerifyFound();
10159
Tony Barbourd6673642016-05-05 14:46:39 -060010160 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010161 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060010162 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
10163 VkFormat format = static_cast<VkFormat>(f);
10164 VkFormatProperties fProps = m_device->format_properties(format);
10165 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
10166 fProps.optimalTilingFeatures == 0) {
10167 unsupported = format;
10168 break;
10169 }
10170 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010171
Tony Barbourd6673642016-05-05 14:46:39 -060010172 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060010173 image_create_info.format = unsupported;
Tony Barbourd6673642016-05-05 14:46:39 -060010174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010175 "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060010176
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010177 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060010178 m_errorMonitor->VerifyFound();
10179 }
10180}
10181
10182TEST_F(VkLayerTest, ImageLayerViewTests) {
10183 VkResult ret;
10184 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
10185
10186 ASSERT_NO_FATAL_FAILURE(InitState());
10187
10188 VkImageObj image(m_device);
10189 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
10190 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
10191 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
10192 VK_IMAGE_TILING_OPTIMAL, 0);
10193 ASSERT_TRUE(image.initialized());
10194
10195 VkImageView imgView;
10196 VkImageViewCreateInfo imgViewInfo = {};
10197 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10198 imgViewInfo.image = image.handle();
10199 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
10200 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
10201 imgViewInfo.subresourceRange.layerCount = 1;
10202 imgViewInfo.subresourceRange.baseMipLevel = 0;
10203 imgViewInfo.subresourceRange.levelCount = 1;
10204 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10205
10206 m_errorMonitor->SetDesiredFailureMsg(
10207 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10208 "vkCreateImageView called with baseMipLevel");
10209 // View can't have baseMipLevel >= image's mipLevels - Expect
10210 // VIEW_CREATE_ERROR
10211 imgViewInfo.subresourceRange.baseMipLevel = 1;
10212 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10213 m_errorMonitor->VerifyFound();
10214 imgViewInfo.subresourceRange.baseMipLevel = 0;
10215
10216 m_errorMonitor->SetDesiredFailureMsg(
10217 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10218 "vkCreateImageView called with baseArrayLayer");
10219 // View can't have baseArrayLayer >= image's arraySize - Expect
10220 // VIEW_CREATE_ERROR
10221 imgViewInfo.subresourceRange.baseArrayLayer = 1;
10222 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10223 m_errorMonitor->VerifyFound();
10224 imgViewInfo.subresourceRange.baseArrayLayer = 0;
10225
10226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10227 "vkCreateImageView called with 0 in "
10228 "pCreateInfo->subresourceRange."
10229 "levelCount");
10230 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
10231 imgViewInfo.subresourceRange.levelCount = 0;
10232 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10233 m_errorMonitor->VerifyFound();
10234 imgViewInfo.subresourceRange.levelCount = 1;
10235
10236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10237 "vkCreateImageView called with 0 in "
10238 "pCreateInfo->subresourceRange."
10239 "layerCount");
10240 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
10241 imgViewInfo.subresourceRange.layerCount = 0;
10242 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10243 m_errorMonitor->VerifyFound();
10244 imgViewInfo.subresourceRange.layerCount = 1;
10245
10246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10247 "but both must be color formats");
10248 // Can't use depth format for view into color image - Expect INVALID_FORMAT
10249 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
10250 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10251 m_errorMonitor->VerifyFound();
10252 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
10253
10254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10255 "Formats MUST be IDENTICAL unless "
10256 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
10257 "was set on image creation.");
10258 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
10259 // VIEW_CREATE_ERROR
10260 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
10261 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10262 m_errorMonitor->VerifyFound();
10263 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
10264
10265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10266 "can support ImageViews with "
10267 "differing formats but they must be "
10268 "in the same compatibility class.");
10269 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
10270 // VIEW_CREATE_ERROR
10271 VkImageCreateInfo mutImgInfo = image.create_info();
10272 VkImage mutImage;
10273 mutImgInfo.format = VK_FORMAT_R8_UINT;
10274 assert(
10275 m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures &
10276 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
10277 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
10278 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10279 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
10280 ASSERT_VK_SUCCESS(ret);
10281 imgViewInfo.image = mutImage;
10282 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10283 m_errorMonitor->VerifyFound();
10284 imgViewInfo.image = image.handle();
10285 vkDestroyImage(m_device->handle(), mutImage, NULL);
10286}
10287
10288TEST_F(VkLayerTest, MiscImageLayerTests) {
10289
10290 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
10291
10292 ASSERT_NO_FATAL_FAILURE(InitState());
10293
10294 VkImageObj image(m_device);
10295 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
10296 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
10297 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
10298 VK_IMAGE_TILING_OPTIMAL, 0);
10299 ASSERT_TRUE(image.initialized());
10300
10301 m_errorMonitor->SetDesiredFailureMsg(
10302 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10303 "number of layers in image subresource is zero");
10304 vk_testing::Buffer buffer;
10305 VkMemoryPropertyFlags reqs = 0;
10306 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
10307 VkBufferImageCopy region = {};
10308 region.bufferRowLength = 128;
10309 region.bufferImageHeight = 128;
10310 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10311 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
10312 region.imageSubresource.layerCount = 0;
10313 region.imageExtent.height = 4;
10314 region.imageExtent.width = 4;
10315 region.imageExtent.depth = 1;
10316 m_commandBuffer->BeginCommandBuffer();
10317 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
10318 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
10319 1, &region);
10320 m_errorMonitor->VerifyFound();
10321 region.imageSubresource.layerCount = 1;
10322
10323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10324 "aspectMasks for each region must "
10325 "specify only COLOR or DEPTH or "
10326 "STENCIL");
10327 // Expect MISMATCHED_IMAGE_ASPECT
10328 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
10329 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
10330 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
10331 1, &region);
10332 m_errorMonitor->VerifyFound();
10333 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10334
10335 m_errorMonitor->SetDesiredFailureMsg(
10336 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10337 "If the format of srcImage is a depth, stencil, depth stencil or "
10338 "integer-based format then filter must be VK_FILTER_NEAREST");
10339 // Expect INVALID_FILTER
10340 VkImageObj intImage1(m_device);
10341 intImage1.init(128, 128, VK_FORMAT_R8_UINT,
10342 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
10343 0);
10344 VkImageObj intImage2(m_device);
10345 intImage2.init(128, 128, VK_FORMAT_R8_UINT,
10346 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
10347 0);
10348 VkImageBlit blitRegion = {};
10349 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10350 blitRegion.srcSubresource.baseArrayLayer = 0;
10351 blitRegion.srcSubresource.layerCount = 1;
10352 blitRegion.srcSubresource.mipLevel = 0;
10353 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10354 blitRegion.dstSubresource.baseArrayLayer = 0;
10355 blitRegion.dstSubresource.layerCount = 1;
10356 blitRegion.dstSubresource.mipLevel = 0;
10357
10358 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(),
10359 intImage1.layout(), intImage2.handle(), intImage2.layout(),
10360 16, &blitRegion, VK_FILTER_LINEAR);
10361 m_errorMonitor->VerifyFound();
10362
10363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10364 "called with 0 in ppMemoryBarriers");
10365 VkImageMemoryBarrier img_barrier;
10366 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10367 img_barrier.pNext = NULL;
10368 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10369 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10370 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10371 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10372 img_barrier.image = image.handle();
10373 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10374 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10375 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10376 img_barrier.subresourceRange.baseArrayLayer = 0;
10377 img_barrier.subresourceRange.baseMipLevel = 0;
10378 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
10379 img_barrier.subresourceRange.layerCount = 0;
10380 img_barrier.subresourceRange.levelCount = 1;
10381 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
10382 VK_PIPELINE_STAGE_HOST_BIT,
10383 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
10384 nullptr, 1, &img_barrier);
10385 m_errorMonitor->VerifyFound();
10386 img_barrier.subresourceRange.layerCount = 1;
10387}
10388
10389TEST_F(VkLayerTest, ImageFormatLimits) {
10390
10391 TEST_DESCRIPTION("Exceed the limits of image format ");
10392
10393 m_errorMonitor->SetDesiredFailureMsg(
10394 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10395 "CreateImage extents exceed allowable limits for format");
10396 VkImageCreateInfo image_create_info = {};
10397 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10398 image_create_info.pNext = NULL;
10399 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10400 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10401 image_create_info.extent.width = 32;
10402 image_create_info.extent.height = 32;
10403 image_create_info.extent.depth = 1;
10404 image_create_info.mipLevels = 1;
10405 image_create_info.arrayLayers = 1;
10406 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10407 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10408 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10409 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10410 image_create_info.flags = 0;
10411
10412 VkImage nullImg;
10413 VkImageFormatProperties imgFmtProps;
10414 vkGetPhysicalDeviceImageFormatProperties(
10415 gpu(), image_create_info.format, image_create_info.imageType,
10416 image_create_info.tiling, image_create_info.usage,
10417 image_create_info.flags, &imgFmtProps);
10418 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
10419 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10420 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10421 m_errorMonitor->VerifyFound();
10422 image_create_info.extent.depth = 1;
10423
10424 m_errorMonitor->SetDesiredFailureMsg(
10425 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10426 "exceeds allowable maximum supported by format of");
10427 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
10428 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10429 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10430 m_errorMonitor->VerifyFound();
10431 image_create_info.mipLevels = 1;
10432
10433 m_errorMonitor->SetDesiredFailureMsg(
10434 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10435 "exceeds allowable maximum supported by format of");
10436 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
10437 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10438 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10439 m_errorMonitor->VerifyFound();
10440 image_create_info.arrayLayers = 1;
10441
10442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10443 "is not supported by format");
10444 int samples = imgFmtProps.sampleCounts >> 1;
10445 image_create_info.samples = (VkSampleCountFlagBits)samples;
10446 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10447 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10448 m_errorMonitor->VerifyFound();
10449 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10450
10451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10452 "pCreateInfo->initialLayout, must be "
10453 "VK_IMAGE_LAYOUT_UNDEFINED or "
10454 "VK_IMAGE_LAYOUT_PREINITIALIZED");
10455 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10456 // Expect INVALID_LAYOUT
10457 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10458 m_errorMonitor->VerifyFound();
10459 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10460}
10461
Karl Schultz6addd812016-02-02 17:17:23 -070010462TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060010463 VkResult err;
10464 bool pass;
10465
10466 // Create color images with different format sizes and try to copy between them
10467 m_errorMonitor->SetDesiredFailureMsg(
10468 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10469 "vkCmdCopyImage called with unmatched source and dest image format sizes");
10470
10471 ASSERT_NO_FATAL_FAILURE(InitState());
10472
10473 // Create two images of different types and try to copy between them
10474 VkImage srcImage;
10475 VkImage dstImage;
10476 VkDeviceMemory srcMem;
10477 VkDeviceMemory destMem;
10478 VkMemoryRequirements memReqs;
10479
10480 VkImageCreateInfo image_create_info = {};
10481 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10482 image_create_info.pNext = NULL;
10483 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10484 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10485 image_create_info.extent.width = 32;
10486 image_create_info.extent.height = 32;
10487 image_create_info.extent.depth = 1;
10488 image_create_info.mipLevels = 1;
10489 image_create_info.arrayLayers = 1;
10490 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10491 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10492 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10493 image_create_info.flags = 0;
10494
10495 err =
10496 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
10497 ASSERT_VK_SUCCESS(err);
10498
10499 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
10500 // Introduce failure by creating second image with a different-sized format.
10501 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
10502
10503 err =
10504 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
10505 ASSERT_VK_SUCCESS(err);
10506
10507 // Allocate memory
10508 VkMemoryAllocateInfo memAlloc = {};
10509 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10510 memAlloc.pNext = NULL;
10511 memAlloc.allocationSize = 0;
10512 memAlloc.memoryTypeIndex = 0;
10513
10514 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
10515 memAlloc.allocationSize = memReqs.size;
10516 pass =
10517 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
10518 ASSERT_TRUE(pass);
10519 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
10520 ASSERT_VK_SUCCESS(err);
10521
10522 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
10523 memAlloc.allocationSize = memReqs.size;
10524 pass =
10525 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
10526 ASSERT_TRUE(pass);
10527 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
10528 ASSERT_VK_SUCCESS(err);
10529
10530 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10531 ASSERT_VK_SUCCESS(err);
10532 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
10533 ASSERT_VK_SUCCESS(err);
10534
10535 BeginCommandBuffer();
10536 VkImageCopy copyRegion;
10537 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10538 copyRegion.srcSubresource.mipLevel = 0;
10539 copyRegion.srcSubresource.baseArrayLayer = 0;
10540 copyRegion.srcSubresource.layerCount = 0;
10541 copyRegion.srcOffset.x = 0;
10542 copyRegion.srcOffset.y = 0;
10543 copyRegion.srcOffset.z = 0;
10544 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10545 copyRegion.dstSubresource.mipLevel = 0;
10546 copyRegion.dstSubresource.baseArrayLayer = 0;
10547 copyRegion.dstSubresource.layerCount = 0;
10548 copyRegion.dstOffset.x = 0;
10549 copyRegion.dstOffset.y = 0;
10550 copyRegion.dstOffset.z = 0;
10551 copyRegion.extent.width = 1;
10552 copyRegion.extent.height = 1;
10553 copyRegion.extent.depth = 1;
10554 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10555 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10556 EndCommandBuffer();
10557
10558 m_errorMonitor->VerifyFound();
10559
10560 vkDestroyImage(m_device->device(), srcImage, NULL);
10561 vkDestroyImage(m_device->device(), dstImage, NULL);
10562 vkFreeMemory(m_device->device(), srcMem, NULL);
10563 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010564}
10565
Karl Schultz6addd812016-02-02 17:17:23 -070010566TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
10567 VkResult err;
10568 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010569
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010570 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010571 m_errorMonitor->SetDesiredFailureMsg(
10572 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010573 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010574
Mike Stroyana3082432015-09-25 13:39:21 -060010575 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010576
10577 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010578 VkImage srcImage;
10579 VkImage dstImage;
10580 VkDeviceMemory srcMem;
10581 VkDeviceMemory destMem;
10582 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010583
10584 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010585 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10586 image_create_info.pNext = NULL;
10587 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10588 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10589 image_create_info.extent.width = 32;
10590 image_create_info.extent.height = 32;
10591 image_create_info.extent.depth = 1;
10592 image_create_info.mipLevels = 1;
10593 image_create_info.arrayLayers = 1;
10594 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10595 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10596 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10597 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010598
Karl Schultz6addd812016-02-02 17:17:23 -070010599 err =
10600 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010601 ASSERT_VK_SUCCESS(err);
10602
Karl Schultzbdb75952016-04-19 11:36:49 -060010603 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
10604
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010605 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070010606 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010607 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
10608 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010609
Karl Schultz6addd812016-02-02 17:17:23 -070010610 err =
10611 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010612 ASSERT_VK_SUCCESS(err);
10613
10614 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010615 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010616 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10617 memAlloc.pNext = NULL;
10618 memAlloc.allocationSize = 0;
10619 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010620
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010621 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010622 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010623 pass =
10624 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010625 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010626 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010627 ASSERT_VK_SUCCESS(err);
10628
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010629 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010630 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010631 pass =
10632 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010633 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010634 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010635 ASSERT_VK_SUCCESS(err);
10636
10637 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10638 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010639 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010640 ASSERT_VK_SUCCESS(err);
10641
10642 BeginCommandBuffer();
10643 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010644 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010645 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010646 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010647 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010648 copyRegion.srcOffset.x = 0;
10649 copyRegion.srcOffset.y = 0;
10650 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010651 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010652 copyRegion.dstSubresource.mipLevel = 0;
10653 copyRegion.dstSubresource.baseArrayLayer = 0;
10654 copyRegion.dstSubresource.layerCount = 0;
10655 copyRegion.dstOffset.x = 0;
10656 copyRegion.dstOffset.y = 0;
10657 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010658 copyRegion.extent.width = 1;
10659 copyRegion.extent.height = 1;
10660 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010661 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10662 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010663 EndCommandBuffer();
10664
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010665 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010666
Chia-I Wuf7458c52015-10-26 21:10:41 +080010667 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010668 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010669 vkFreeMemory(m_device->device(), srcMem, NULL);
10670 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010671}
10672
Karl Schultz6addd812016-02-02 17:17:23 -070010673TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
10674 VkResult err;
10675 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010676
Karl Schultz6addd812016-02-02 17:17:23 -070010677 m_errorMonitor->SetDesiredFailureMsg(
10678 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010679 "vkCmdResolveImage called with source sample count less than 2.");
10680
Mike Stroyana3082432015-09-25 13:39:21 -060010681 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010682
10683 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070010684 VkImage srcImage;
10685 VkImage dstImage;
10686 VkDeviceMemory srcMem;
10687 VkDeviceMemory destMem;
10688 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010689
10690 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010691 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10692 image_create_info.pNext = NULL;
10693 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10694 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10695 image_create_info.extent.width = 32;
10696 image_create_info.extent.height = 1;
10697 image_create_info.extent.depth = 1;
10698 image_create_info.mipLevels = 1;
10699 image_create_info.arrayLayers = 1;
10700 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10701 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10702 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10703 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010704
Karl Schultz6addd812016-02-02 17:17:23 -070010705 err =
10706 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010707 ASSERT_VK_SUCCESS(err);
10708
Karl Schultz6addd812016-02-02 17:17:23 -070010709 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010710
Karl Schultz6addd812016-02-02 17:17:23 -070010711 err =
10712 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010713 ASSERT_VK_SUCCESS(err);
10714
10715 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010716 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010717 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10718 memAlloc.pNext = NULL;
10719 memAlloc.allocationSize = 0;
10720 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010721
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010722 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010723 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010724 pass =
10725 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010726 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010727 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010728 ASSERT_VK_SUCCESS(err);
10729
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010730 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010731 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010732 pass =
10733 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010734 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010735 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010736 ASSERT_VK_SUCCESS(err);
10737
10738 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10739 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010740 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010741 ASSERT_VK_SUCCESS(err);
10742
10743 BeginCommandBuffer();
10744 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070010745 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
10746 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060010747 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010748 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010749 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010750 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010751 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010752 resolveRegion.srcOffset.x = 0;
10753 resolveRegion.srcOffset.y = 0;
10754 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010755 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010756 resolveRegion.dstSubresource.mipLevel = 0;
10757 resolveRegion.dstSubresource.baseArrayLayer = 0;
10758 resolveRegion.dstSubresource.layerCount = 0;
10759 resolveRegion.dstOffset.x = 0;
10760 resolveRegion.dstOffset.y = 0;
10761 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010762 resolveRegion.extent.width = 1;
10763 resolveRegion.extent.height = 1;
10764 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010765 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10766 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010767 EndCommandBuffer();
10768
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010769 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010770
Chia-I Wuf7458c52015-10-26 21:10:41 +080010771 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010772 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010773 vkFreeMemory(m_device->device(), srcMem, NULL);
10774 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010775}
10776
Karl Schultz6addd812016-02-02 17:17:23 -070010777TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
10778 VkResult err;
10779 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010780
Karl Schultz6addd812016-02-02 17:17:23 -070010781 m_errorMonitor->SetDesiredFailureMsg(
10782 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010783 "vkCmdResolveImage called with dest sample count greater than 1.");
10784
Mike Stroyana3082432015-09-25 13:39:21 -060010785 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010786
Chris Forbesa7530692016-05-08 12:35:39 +120010787 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070010788 VkImage srcImage;
10789 VkImage dstImage;
10790 VkDeviceMemory srcMem;
10791 VkDeviceMemory destMem;
10792 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010793
10794 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010795 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10796 image_create_info.pNext = NULL;
10797 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10798 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10799 image_create_info.extent.width = 32;
10800 image_create_info.extent.height = 1;
10801 image_create_info.extent.depth = 1;
10802 image_create_info.mipLevels = 1;
10803 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120010804 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070010805 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10806 // Note: Some implementations expect color attachment usage for any
10807 // multisample surface
10808 image_create_info.usage =
10809 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10810 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010811
Karl Schultz6addd812016-02-02 17:17:23 -070010812 err =
10813 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010814 ASSERT_VK_SUCCESS(err);
10815
Karl Schultz6addd812016-02-02 17:17:23 -070010816 // Note: Some implementations expect color attachment usage for any
10817 // multisample surface
10818 image_create_info.usage =
10819 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010820
Karl Schultz6addd812016-02-02 17:17:23 -070010821 err =
10822 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010823 ASSERT_VK_SUCCESS(err);
10824
10825 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010826 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010827 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10828 memAlloc.pNext = NULL;
10829 memAlloc.allocationSize = 0;
10830 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010831
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010832 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010833 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010834 pass =
10835 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010836 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010837 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010838 ASSERT_VK_SUCCESS(err);
10839
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010840 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010841 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010842 pass =
10843 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010844 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010845 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010846 ASSERT_VK_SUCCESS(err);
10847
10848 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10849 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010850 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010851 ASSERT_VK_SUCCESS(err);
10852
10853 BeginCommandBuffer();
10854 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070010855 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
10856 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060010857 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010858 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010859 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010860 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010861 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010862 resolveRegion.srcOffset.x = 0;
10863 resolveRegion.srcOffset.y = 0;
10864 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010865 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010866 resolveRegion.dstSubresource.mipLevel = 0;
10867 resolveRegion.dstSubresource.baseArrayLayer = 0;
10868 resolveRegion.dstSubresource.layerCount = 0;
10869 resolveRegion.dstOffset.x = 0;
10870 resolveRegion.dstOffset.y = 0;
10871 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010872 resolveRegion.extent.width = 1;
10873 resolveRegion.extent.height = 1;
10874 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010875 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10876 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010877 EndCommandBuffer();
10878
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010879 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010880
Chia-I Wuf7458c52015-10-26 21:10:41 +080010881 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010882 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010883 vkFreeMemory(m_device->device(), srcMem, NULL);
10884 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010885}
10886
Karl Schultz6addd812016-02-02 17:17:23 -070010887TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
10888 VkResult err;
10889 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010890
Karl Schultz6addd812016-02-02 17:17:23 -070010891 m_errorMonitor->SetDesiredFailureMsg(
10892 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010893 "vkCmdResolveImage called with unmatched source and dest formats.");
10894
Mike Stroyana3082432015-09-25 13:39:21 -060010895 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010896
10897 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010898 VkImage srcImage;
10899 VkImage dstImage;
10900 VkDeviceMemory srcMem;
10901 VkDeviceMemory destMem;
10902 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010903
10904 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010905 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10906 image_create_info.pNext = NULL;
10907 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10908 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10909 image_create_info.extent.width = 32;
10910 image_create_info.extent.height = 1;
10911 image_create_info.extent.depth = 1;
10912 image_create_info.mipLevels = 1;
10913 image_create_info.arrayLayers = 1;
10914 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
10915 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10916 // Note: Some implementations expect color attachment usage for any
10917 // multisample surface
10918 image_create_info.usage =
10919 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10920 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010921
Karl Schultz6addd812016-02-02 17:17:23 -070010922 err =
10923 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010924 ASSERT_VK_SUCCESS(err);
10925
Karl Schultz6addd812016-02-02 17:17:23 -070010926 // Set format to something other than source image
10927 image_create_info.format = VK_FORMAT_R32_SFLOAT;
10928 // Note: Some implementations expect color attachment usage for any
10929 // multisample surface
10930 image_create_info.usage =
10931 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10932 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010933
Karl Schultz6addd812016-02-02 17:17:23 -070010934 err =
10935 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010936 ASSERT_VK_SUCCESS(err);
10937
10938 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010939 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010940 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10941 memAlloc.pNext = NULL;
10942 memAlloc.allocationSize = 0;
10943 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010944
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010945 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010946 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010947 pass =
10948 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010949 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010950 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010951 ASSERT_VK_SUCCESS(err);
10952
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010953 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010954 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010955 pass =
10956 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010957 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010958 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010959 ASSERT_VK_SUCCESS(err);
10960
10961 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10962 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010963 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010964 ASSERT_VK_SUCCESS(err);
10965
10966 BeginCommandBuffer();
10967 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070010968 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
10969 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060010970 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010971 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010972 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010973 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010974 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010975 resolveRegion.srcOffset.x = 0;
10976 resolveRegion.srcOffset.y = 0;
10977 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010978 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010979 resolveRegion.dstSubresource.mipLevel = 0;
10980 resolveRegion.dstSubresource.baseArrayLayer = 0;
10981 resolveRegion.dstSubresource.layerCount = 0;
10982 resolveRegion.dstOffset.x = 0;
10983 resolveRegion.dstOffset.y = 0;
10984 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010985 resolveRegion.extent.width = 1;
10986 resolveRegion.extent.height = 1;
10987 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010988 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10989 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010990 EndCommandBuffer();
10991
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010992 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010993
Chia-I Wuf7458c52015-10-26 21:10:41 +080010994 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010995 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010996 vkFreeMemory(m_device->device(), srcMem, NULL);
10997 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010998}
10999
Karl Schultz6addd812016-02-02 17:17:23 -070011000TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
11001 VkResult err;
11002 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011003
Karl Schultz6addd812016-02-02 17:17:23 -070011004 m_errorMonitor->SetDesiredFailureMsg(
11005 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011006 "vkCmdResolveImage called with unmatched source and dest image types.");
11007
Mike Stroyana3082432015-09-25 13:39:21 -060011008 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011009
11010 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011011 VkImage srcImage;
11012 VkImage dstImage;
11013 VkDeviceMemory srcMem;
11014 VkDeviceMemory destMem;
11015 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011016
11017 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011018 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11019 image_create_info.pNext = NULL;
11020 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11021 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11022 image_create_info.extent.width = 32;
11023 image_create_info.extent.height = 1;
11024 image_create_info.extent.depth = 1;
11025 image_create_info.mipLevels = 1;
11026 image_create_info.arrayLayers = 1;
11027 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
11028 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11029 // Note: Some implementations expect color attachment usage for any
11030 // multisample surface
11031 image_create_info.usage =
11032 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11033 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011034
Karl Schultz6addd812016-02-02 17:17:23 -070011035 err =
11036 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011037 ASSERT_VK_SUCCESS(err);
11038
Karl Schultz6addd812016-02-02 17:17:23 -070011039 image_create_info.imageType = VK_IMAGE_TYPE_1D;
11040 // Note: Some implementations expect color attachment usage for any
11041 // multisample surface
11042 image_create_info.usage =
11043 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11044 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011045
Karl Schultz6addd812016-02-02 17:17:23 -070011046 err =
11047 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011048 ASSERT_VK_SUCCESS(err);
11049
11050 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011051 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011052 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11053 memAlloc.pNext = NULL;
11054 memAlloc.allocationSize = 0;
11055 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011056
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011057 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011058 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011059 pass =
11060 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011061 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011062 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011063 ASSERT_VK_SUCCESS(err);
11064
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011065 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011066 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011067 pass =
11068 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011069 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011070 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011071 ASSERT_VK_SUCCESS(err);
11072
11073 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11074 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011075 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011076 ASSERT_VK_SUCCESS(err);
11077
11078 BeginCommandBuffer();
11079 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011080 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11081 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011082 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011083 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011084 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011085 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011086 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011087 resolveRegion.srcOffset.x = 0;
11088 resolveRegion.srcOffset.y = 0;
11089 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011090 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011091 resolveRegion.dstSubresource.mipLevel = 0;
11092 resolveRegion.dstSubresource.baseArrayLayer = 0;
11093 resolveRegion.dstSubresource.layerCount = 0;
11094 resolveRegion.dstOffset.x = 0;
11095 resolveRegion.dstOffset.y = 0;
11096 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011097 resolveRegion.extent.width = 1;
11098 resolveRegion.extent.height = 1;
11099 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011100 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11101 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011102 EndCommandBuffer();
11103
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011104 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011105
Chia-I Wuf7458c52015-10-26 21:10:41 +080011106 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011107 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011108 vkFreeMemory(m_device->device(), srcMem, NULL);
11109 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011110}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011111
Karl Schultz6addd812016-02-02 17:17:23 -070011112TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011113 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070011114 // to using a DS format, then cause it to hit error due to COLOR_BIT not
11115 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011116 // The image format check comes 2nd in validation so we trigger it first,
11117 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070011118 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011119
Karl Schultz6addd812016-02-02 17:17:23 -070011120 m_errorMonitor->SetDesiredFailureMsg(
11121 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011122 "Combination depth/stencil image formats can have only the ");
11123
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011124 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011125
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011126 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011127 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
11128 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011129
11130 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011131 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11132 ds_pool_ci.pNext = NULL;
11133 ds_pool_ci.maxSets = 1;
11134 ds_pool_ci.poolSizeCount = 1;
11135 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011136
11137 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -070011138 err =
11139 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011140 ASSERT_VK_SUCCESS(err);
11141
11142 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011143 dsl_binding.binding = 0;
11144 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
11145 dsl_binding.descriptorCount = 1;
11146 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11147 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011148
11149 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011150 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11151 ds_layout_ci.pNext = NULL;
11152 ds_layout_ci.bindingCount = 1;
11153 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011154 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070011155 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
11156 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011157 ASSERT_VK_SUCCESS(err);
11158
11159 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011160 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011161 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011162 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011163 alloc_info.descriptorPool = ds_pool;
11164 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070011165 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
11166 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011167 ASSERT_VK_SUCCESS(err);
11168
Karl Schultz6addd812016-02-02 17:17:23 -070011169 VkImage image_bad;
11170 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011171 // One bad format and one good format for Color attachment
Karl Schultz6addd812016-02-02 17:17:23 -070011172 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011173 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070011174 const int32_t tex_width = 32;
11175 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011176
11177 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011178 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11179 image_create_info.pNext = NULL;
11180 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11181 image_create_info.format = tex_format_bad;
11182 image_create_info.extent.width = tex_width;
11183 image_create_info.extent.height = tex_height;
11184 image_create_info.extent.depth = 1;
11185 image_create_info.mipLevels = 1;
11186 image_create_info.arrayLayers = 1;
11187 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11188 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11189 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
11190 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11191 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011192
Karl Schultz6addd812016-02-02 17:17:23 -070011193 err =
11194 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011195 ASSERT_VK_SUCCESS(err);
11196 image_create_info.format = tex_format_good;
Karl Schultz6addd812016-02-02 17:17:23 -070011197 image_create_info.usage =
11198 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11199 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
11200 &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011201 ASSERT_VK_SUCCESS(err);
11202
11203 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011204 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11205 image_view_create_info.image = image_bad;
11206 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11207 image_view_create_info.format = tex_format_bad;
11208 image_view_create_info.subresourceRange.baseArrayLayer = 0;
11209 image_view_create_info.subresourceRange.baseMipLevel = 0;
11210 image_view_create_info.subresourceRange.layerCount = 1;
11211 image_view_create_info.subresourceRange.levelCount = 1;
11212 image_view_create_info.subresourceRange.aspectMask =
11213 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011214
11215 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070011216 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
11217 &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011218
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011219 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011220
Chia-I Wuf7458c52015-10-26 21:10:41 +080011221 vkDestroyImage(m_device->device(), image_bad, NULL);
11222 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011223 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11224 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011225}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060011226
11227TEST_F(VkLayerTest, ClearImageErrors) {
11228 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
11229 "ClearDepthStencilImage with a color image.");
11230
11231 ASSERT_NO_FATAL_FAILURE(InitState());
11232 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11233
11234 // Renderpass is started here so end it as Clear cmds can't be in renderpass
11235 BeginCommandBuffer();
11236 m_commandBuffer->EndRenderPass();
11237
11238 // Color image
11239 VkClearColorValue clear_color;
11240 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
11241 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
11242 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
11243 const int32_t img_width = 32;
11244 const int32_t img_height = 32;
11245 VkImageCreateInfo image_create_info = {};
11246 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11247 image_create_info.pNext = NULL;
11248 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11249 image_create_info.format = color_format;
11250 image_create_info.extent.width = img_width;
11251 image_create_info.extent.height = img_height;
11252 image_create_info.extent.depth = 1;
11253 image_create_info.mipLevels = 1;
11254 image_create_info.arrayLayers = 1;
11255 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11256 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11257 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11258
11259 vk_testing::Image color_image;
11260 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info,
11261 reqs);
11262
11263 const VkImageSubresourceRange color_range =
11264 vk_testing::Image::subresource_range(image_create_info,
11265 VK_IMAGE_ASPECT_COLOR_BIT);
11266
11267 // Depth/Stencil image
11268 VkClearDepthStencilValue clear_value = {0};
11269 reqs = 0; // don't need HOST_VISIBLE DS image
11270 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
11271 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
11272 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
11273 ds_image_create_info.extent.width = 64;
11274 ds_image_create_info.extent.height = 64;
11275 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11276 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11277
11278 vk_testing::Image ds_image;
11279 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info,
11280 reqs);
11281
11282 const VkImageSubresourceRange ds_range =
11283 vk_testing::Image::subresource_range(ds_image_create_info,
11284 VK_IMAGE_ASPECT_DEPTH_BIT);
11285
11286 m_errorMonitor->SetDesiredFailureMsg(
11287 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11288 "vkCmdClearColorImage called with depth/stencil image.");
11289
11290 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
11291 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
11292 &color_range);
11293
11294 m_errorMonitor->VerifyFound();
11295
11296 // Call CmdClearDepthStencilImage with color image
11297 m_errorMonitor->SetDesiredFailureMsg(
11298 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11299 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
11300
11301 vkCmdClearDepthStencilImage(
11302 m_commandBuffer->GetBufferHandle(), color_image.handle(),
11303 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
11304 &ds_range);
11305
11306 m_errorMonitor->VerifyFound();
11307}
Tobin Ehliscde08892015-09-22 10:11:37 -060011308#endif // IMAGE_TESTS
11309
Tony Barbour300a6082015-04-07 13:44:53 -060011310int main(int argc, char **argv) {
11311 int result;
11312
Cody Northrop8e54a402016-03-08 22:25:52 -070011313#ifdef ANDROID
11314 int vulkanSupport = InitVulkan();
11315 if (vulkanSupport == 0)
11316 return 1;
11317#endif
11318
Tony Barbour300a6082015-04-07 13:44:53 -060011319 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060011320 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060011321
11322 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
11323
11324 result = RUN_ALL_TESTS();
11325
Tony Barbour6918cd52015-04-09 12:58:51 -060011326 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060011327 return result;
11328}