blob: 7fafdbb7ce13b9c40f82f758e306ca089e29c909 [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;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600525 ds_ci.maxDepthBounds = 0.0f;
526 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600527 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600528 ds_ci.stencilTestEnable = VK_TRUE;
529 ds_ci.front = stencil;
530 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600531
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600532 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600533 pipelineobj.SetViewport(m_viewports);
534 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800535 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700536 VkResult err = pipelineobj.CreateVKPipeline(
537 descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600538 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800539 commandBuffer->BindPipeline(pipelineobj);
540 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500541}
542
Ian Elliott2c1daf52016-05-12 09:41:46 -0600543class VkWsiEnabledLayerTest : public VkLayerTest {
544 public:
545protected:
546 VkWsiEnabledLayerTest() {
547 m_enableWSI = true;
548 }
549};
550
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500551// ********************************************************************************************************************
552// ********************************************************************************************************************
553// ********************************************************************************************************************
554// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600555#if PARAMETER_VALIDATION_TESTS
556TEST_F(VkLayerTest, RequiredParameter) {
557 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
558 "pointer, array, and array count parameters");
559
560 ASSERT_NO_FATAL_FAILURE(InitState());
561
562 m_errorMonitor->SetDesiredFailureMsg(
563 VK_DEBUG_REPORT_ERROR_BIT_EXT,
564 "required parameter pFeatures specified as NULL");
565 // Specify NULL for a pointer to a handle
566 // Expected to trigger an error with
567 // parameter_validation::validate_required_pointer
568 vkGetPhysicalDeviceFeatures(gpu(), NULL);
569 m_errorMonitor->VerifyFound();
570
571 m_errorMonitor->SetDesiredFailureMsg(
572 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600573 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600574 // Specify NULL for pointer to array count
575 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600576 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600577 m_errorMonitor->VerifyFound();
578
579 m_errorMonitor->SetDesiredFailureMsg(
580 VK_DEBUG_REPORT_ERROR_BIT_EXT,
581 "parameter viewportCount must be greater than 0");
582 // Specify 0 for a required array count
583 // Expected to trigger an error with parameter_validation::validate_array
584 VkViewport view_port = {};
585 m_commandBuffer->SetViewport(0, 0, &view_port);
586 m_errorMonitor->VerifyFound();
587
588 m_errorMonitor->SetDesiredFailureMsg(
589 VK_DEBUG_REPORT_ERROR_BIT_EXT,
590 "required parameter pViewports specified as NULL");
591 // Specify NULL for a required array
592 // Expected to trigger an error with parameter_validation::validate_array
593 m_commandBuffer->SetViewport(0, 1, NULL);
594 m_errorMonitor->VerifyFound();
595
596 m_errorMonitor->SetDesiredFailureMsg(
597 VK_DEBUG_REPORT_ERROR_BIT_EXT,
598 "required parameter memory specified as VK_NULL_HANDLE");
599 // Specify VK_NULL_HANDLE for a required handle
600 // Expected to trigger an error with
601 // parameter_validation::validate_required_handle
602 vkUnmapMemory(device(), VK_NULL_HANDLE);
603 m_errorMonitor->VerifyFound();
604
605 m_errorMonitor->SetDesiredFailureMsg(
606 VK_DEBUG_REPORT_ERROR_BIT_EXT,
607 "required parameter pFences[0] specified as VK_NULL_HANDLE");
608 // Specify VK_NULL_HANDLE for a required handle array entry
609 // Expected to trigger an error with
610 // parameter_validation::validate_required_handle_array
611 VkFence fence = VK_NULL_HANDLE;
612 vkResetFences(device(), 1, &fence);
613 m_errorMonitor->VerifyFound();
614
615 m_errorMonitor->SetDesiredFailureMsg(
616 VK_DEBUG_REPORT_ERROR_BIT_EXT,
617 "required parameter pAllocateInfo specified as NULL");
618 // Specify NULL for a required struct pointer
619 // Expected to trigger an error with
620 // parameter_validation::validate_struct_type
621 VkDeviceMemory memory = VK_NULL_HANDLE;
622 vkAllocateMemory(device(), NULL, NULL, &memory);
623 m_errorMonitor->VerifyFound();
624
625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
626 "value of faceMask must not be 0");
627 // Specify 0 for a required VkFlags parameter
628 // Expected to trigger an error with parameter_validation::validate_flags
629 m_commandBuffer->SetStencilReference(0, 0);
630 m_errorMonitor->VerifyFound();
631
632 m_errorMonitor->SetDesiredFailureMsg(
633 VK_DEBUG_REPORT_ERROR_BIT_EXT,
634 "value of pSubmits[i].pWaitDstStageMask[0] must not be 0");
635 // Specify 0 for a required VkFlags array entry
636 // Expected to trigger an error with
637 // parameter_validation::validate_flags_array
638 VkSemaphore semaphore = VK_NULL_HANDLE;
639 VkPipelineStageFlags stageFlags = 0;
640 VkSubmitInfo submitInfo = {};
641 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
642 submitInfo.waitSemaphoreCount = 1;
643 submitInfo.pWaitSemaphores = &semaphore;
644 submitInfo.pWaitDstStageMask = &stageFlags;
645 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
646 m_errorMonitor->VerifyFound();
647}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600648
Dustin Gravesfce74c02016-05-10 11:42:58 -0600649TEST_F(VkLayerTest, ReservedParameter) {
650 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
651
652 ASSERT_NO_FATAL_FAILURE(InitState());
653
654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
655 " must be 0");
656 // Specify 0 for a reserved VkFlags parameter
657 // Expected to trigger an error with
658 // parameter_validation::validate_reserved_flags
659 VkEvent event_handle = VK_NULL_HANDLE;
660 VkEventCreateInfo event_info = {};
661 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
662 event_info.flags = 1;
663 vkCreateEvent(device(), &event_info, NULL, &event_handle);
664 m_errorMonitor->VerifyFound();
665}
666
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600667TEST_F(VkLayerTest, InvalidStructSType) {
668 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
669 "structure's sType field");
670
671 ASSERT_NO_FATAL_FAILURE(InitState());
672
673 m_errorMonitor->SetDesiredFailureMsg(
674 VK_DEBUG_REPORT_ERROR_BIT_EXT,
675 "parameter pAllocateInfo->sType must be");
676 // Zero struct memory, effectively setting sType to
677 // VK_STRUCTURE_TYPE_APPLICATION_INFO
678 // Expected to trigger an error with
679 // parameter_validation::validate_struct_type
680 VkMemoryAllocateInfo alloc_info = {};
681 VkDeviceMemory memory = VK_NULL_HANDLE;
682 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
683 m_errorMonitor->VerifyFound();
684
685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
686 "parameter pSubmits[0].sType must be");
687 // Zero struct memory, effectively setting sType to
688 // VK_STRUCTURE_TYPE_APPLICATION_INFO
689 // Expected to trigger an error with
690 // parameter_validation::validate_struct_type_array
691 VkSubmitInfo submit_info = {};
692 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
693 m_errorMonitor->VerifyFound();
694}
695
696TEST_F(VkLayerTest, InvalidStructPNext) {
697 TEST_DESCRIPTION(
698 "Specify an invalid value for a Vulkan structure's pNext field");
699
700 ASSERT_NO_FATAL_FAILURE(InitState());
701
702 m_errorMonitor->SetDesiredFailureMsg(
703 VK_DEBUG_REPORT_ERROR_BIT_EXT,
704 "value of pAllocateInfo->pNext must be NULL");
705 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
706 // NULL
707 // Expected to trigger an error with
708 // parameter_validation::validate_struct_pnext
709 VkDeviceMemory memory = VK_NULL_HANDLE;
710 // Zero-initialization will provide the correct sType
711 VkApplicationInfo app_info = {};
Dustin Graves47b6cba2016-05-10 17:34:38 -0600712 VkMemoryAllocateInfo memory_alloc_info = {};
713 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
714 memory_alloc_info.pNext = &app_info;
715 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600716 m_errorMonitor->VerifyFound();
717
Dustin Graves47b6cba2016-05-10 17:34:38 -0600718 m_errorMonitor->SetDesiredFailureMsg(
719 VK_DEBUG_REPORT_ERROR_BIT_EXT,
720 " chain includes a structure with unexpected VkStructureType ");
721 // Set VkGraphicsPipelineCreateInfo::VkPipelineRasterizationStateCreateInfo::pNext to an invalid structure, when pNext is allowed to be a non-NULL value
722 // Expected to trigger an error with
723 // parameter_validation::validate_struct_pnext
724 VkDescriptorPoolSize ds_type_count = {};
725 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
726 ds_type_count.descriptorCount = 1;
727
728 VkDescriptorPoolCreateInfo ds_pool_ci = {};
729 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
730 ds_pool_ci.pNext = NULL;
731 ds_pool_ci.maxSets = 1;
732 ds_pool_ci.poolSizeCount = 1;
733 ds_pool_ci.pPoolSizes = &ds_type_count;
734
735 VkDescriptorPool ds_pool;
736 VkResult err =
737 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
738 ASSERT_VK_SUCCESS(err);
739
740 VkDescriptorSetLayoutBinding dsl_binding = {};
741 dsl_binding.binding = 0;
742 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
743 dsl_binding.descriptorCount = 1;
744 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
745 dsl_binding.pImmutableSamplers = NULL;
746
747 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
748 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
749 ds_layout_ci.pNext = NULL;
750 ds_layout_ci.bindingCount = 1;
751 ds_layout_ci.pBindings = &dsl_binding;
752
753 VkDescriptorSetLayout ds_layout;
754 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
755 &ds_layout);
756 ASSERT_VK_SUCCESS(err);
757
758 VkDescriptorSet descriptorSet;
759 VkDescriptorSetAllocateInfo ds_alloc_info = {};
760 ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
761 ds_alloc_info.descriptorSetCount = 1;
762 ds_alloc_info.descriptorPool = ds_pool;
763 ds_alloc_info.pSetLayouts = &ds_layout;
764 err = vkAllocateDescriptorSets(m_device->device(), &ds_alloc_info,
765 &descriptorSet);
766 ASSERT_VK_SUCCESS(err);
767
768 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
769 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
770 pipeline_layout_ci.setLayoutCount = 1;
771 pipeline_layout_ci.pSetLayouts = &ds_layout;
772
773 VkPipelineLayout pipeline_layout;
774 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
775 &pipeline_layout);
776 ASSERT_VK_SUCCESS(err);
777
778 VkViewport vp = {}; // Just need dummy vp to point to
779 VkRect2D sc = {}; // dummy scissor to point to
780
781 VkPipelineViewportStateCreateInfo vp_state_ci = {};
782 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
783 vp_state_ci.scissorCount = 1;
784 vp_state_ci.pScissors = &sc;
785 vp_state_ci.viewportCount = 1;
786 vp_state_ci.pViewports = &vp;
787
788 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
789 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
790 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
791 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
792 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
793 rs_state_ci.depthClampEnable = VK_FALSE;
794 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
795 rs_state_ci.depthBiasEnable = VK_FALSE;
796
797 VkGraphicsPipelineCreateInfo gp_ci = {};
798 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
799 gp_ci.pViewportState = &vp_state_ci;
800 gp_ci.pRasterizationState = &rs_state_ci;
801 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
802 gp_ci.layout = pipeline_layout;
803 gp_ci.renderPass = renderPass();
804
805 VkPipelineCacheCreateInfo pc_ci = {};
806 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
807 pc_ci.initialDataSize = 0;
808 pc_ci.pInitialData = 0;
809
810 VkPipeline pipeline;
811 VkPipelineCache pipelineCache;
812
813 err =
814 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
815 ASSERT_VK_SUCCESS(err);
816
817 // Set VkPipelineRasterizationStateCreateInfo::pNext to an invalid value
818 VkApplicationInfo invalid_pnext_struct = {};
819 rs_state_ci.pNext = &invalid_pnext_struct;
820
821 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
822 &gp_ci, NULL, &pipeline);
823 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600824}
Dustin Graves5d33d532016-05-09 16:21:12 -0600825
826TEST_F(VkLayerTest, UnrecognizedValue) {
827 TEST_DESCRIPTION(
828 "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
829
830 ASSERT_NO_FATAL_FAILURE(InitState());
831
832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
833 "does not fall within the begin..end "
834 "range of the core VkFormat "
835 "enumeration tokens");
836 // Specify an invalid VkFormat value
837 // Expected to trigger an error with
838 // parameter_validation::validate_ranged_enum
839 VkFormatProperties format_properties;
840 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000),
841 &format_properties);
842 m_errorMonitor->VerifyFound();
843
844 m_errorMonitor->SetDesiredFailureMsg(
845 VK_DEBUG_REPORT_ERROR_BIT_EXT,
846 "contains flag bits that are not recognized members of");
847 // Specify an invalid VkFlags bitmask value
848 // Expected to trigger an error with parameter_validation::validate_flags
849 VkImageFormatProperties image_format_properties;
850 vkGetPhysicalDeviceImageFormatProperties(
851 gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D,
852 VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0,
853 &image_format_properties);
854 m_errorMonitor->VerifyFound();
855
856 m_errorMonitor->SetDesiredFailureMsg(
857 VK_DEBUG_REPORT_ERROR_BIT_EXT,
858 "contains flag bits that are not recognized members of");
859 // Specify an invalid VkFlags array entry
860 // Expected to trigger an error with
861 // parameter_validation::validate_flags_array
862 VkSemaphore semaphore = VK_NULL_HANDLE;
863 VkPipelineStageFlags stage_flags =
864 static_cast<VkPipelineStageFlags>(1 << 25);
865 VkSubmitInfo submit_info = {};
866 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
867 submit_info.waitSemaphoreCount = 1;
868 submit_info.pWaitSemaphores = &semaphore;
869 submit_info.pWaitDstStageMask = &stage_flags;
870 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
871 m_errorMonitor->VerifyFound();
872
873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
874 "is neither VK_TRUE nor VK_FALSE");
875 // Specify an invalid VkBool32 value
876 // Expected to trigger a warning with
877 // parameter_validation::validate_bool32
878 VkSampler sampler = VK_NULL_HANDLE;
879 VkSamplerCreateInfo sampler_info = {};
880 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
881 sampler_info.pNext = NULL;
882 sampler_info.magFilter = VK_FILTER_NEAREST;
883 sampler_info.minFilter = VK_FILTER_NEAREST;
884 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
885 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
886 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
887 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
888 sampler_info.mipLodBias = 1.0;
889 sampler_info.maxAnisotropy = 1;
890 sampler_info.compareEnable = VK_FALSE;
891 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
892 sampler_info.minLod = 1.0;
893 sampler_info.maxLod = 1.0;
894 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
895 sampler_info.unnormalizedCoordinates = VK_FALSE;
896 // Not VK_TRUE or VK_FALSE
897 sampler_info.anisotropyEnable = 3;
898 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
899 m_errorMonitor->VerifyFound();
900}
Dustin Gravesfce74c02016-05-10 11:42:58 -0600901
902TEST_F(VkLayerTest, FailedReturnValue) {
903 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
904
905 ASSERT_NO_FATAL_FAILURE(InitState());
906
Dustin Graves13c1e2b2016-05-16 15:31:02 -0600907 // Find an unsupported image format
908 VkFormat unsupported = VK_FORMAT_UNDEFINED;
909 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
910 VkFormat format = static_cast<VkFormat>(f);
911 VkFormatProperties fProps = m_device->format_properties(format);
912 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
913 fProps.optimalTilingFeatures == 0) {
914 unsupported = format;
915 break;
916 }
917 }
918
919 if (unsupported != VK_FORMAT_UNDEFINED) {
920 m_errorMonitor->SetDesiredFailureMsg(
921 VK_DEBUG_REPORT_WARNING_BIT_EXT,
922 "the requested format is not supported on this device");
923 // Specify an unsupported VkFormat value to generate a
924 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
925 // Expected to trigger a warning from
926 // parameter_validation::validate_result
927 VkImageFormatProperties image_format_properties;
928 VkResult err = vkGetPhysicalDeviceImageFormatProperties(
929 gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
930 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
931 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
932 m_errorMonitor->VerifyFound();
933 }
Dustin Gravesfce74c02016-05-10 11:42:58 -0600934}
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600935#endif // PARAMETER_VALIDATION_TESTS
936
Tobin Ehlis0788f522015-05-26 16:11:58 -0600937#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -0700938#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800939TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500940{
941 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500942 VkFenceCreateInfo fenceInfo = {};
943 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
944 fenceInfo.pNext = NULL;
945 fenceInfo.flags = 0;
946
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600948
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500949 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -0600950
951 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
952 vk_testing::Buffer buffer;
953 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500954
Tony Barbourfe3351b2015-07-28 10:17:20 -0600955 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800956 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600957 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500958
959 testFence.init(*m_device, fenceInfo);
960
961 // Bypass framework since it does the waits automatically
962 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600963 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800964 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
965 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800966 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600967 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -0700968 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800969 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800970 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800971 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600972 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600973
974 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500975 ASSERT_VK_SUCCESS( err );
976
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500977 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800978 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500979
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200980 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500981}
982
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800983TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500984{
985 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500986 VkFenceCreateInfo fenceInfo = {};
987 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
988 fenceInfo.pNext = NULL;
989 fenceInfo.flags = 0;
990
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600992
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500993 ASSERT_NO_FATAL_FAILURE(InitState());
994 ASSERT_NO_FATAL_FAILURE(InitViewport());
995 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
996
Tony Barbourfe3351b2015-07-28 10:17:20 -0600997 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800998 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600999 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001000
1001 testFence.init(*m_device, fenceInfo);
1002
1003 // Bypass framework since it does the waits automatically
1004 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001005 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001006 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1007 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001008 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001009 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001010 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001011 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001012 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001013 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001014 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001015
1016 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001017 ASSERT_VK_SUCCESS( err );
1018
Jon Ashburnf19916e2016-01-11 13:12:43 -07001019 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001020 VkCommandBufferBeginInfo info = {};
1021 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1022 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001023 info.renderPass = VK_NULL_HANDLE;
1024 info.subpass = 0;
1025 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001026 info.occlusionQueryEnable = VK_FALSE;
1027 info.queryFlags = 0;
1028 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001029
1030 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001031 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001032
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001033 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001034}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001035#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001036
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001037// This is a positive test. No failures are expected.
1038TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1039 VkResult err;
1040 bool pass;
1041
1042 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1043 "the buffer, create an image, and bind the same memory to "
1044 "it");
1045
1046 m_errorMonitor->ExpectSuccess();
1047
1048 ASSERT_NO_FATAL_FAILURE(InitState());
1049
1050 VkBuffer buffer;
1051 VkImage image;
1052 VkDeviceMemory mem;
1053 VkMemoryRequirements mem_reqs;
1054
1055 VkBufferCreateInfo buf_info = {};
1056 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1057 buf_info.pNext = NULL;
1058 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1059 buf_info.size = 256;
1060 buf_info.queueFamilyIndexCount = 0;
1061 buf_info.pQueueFamilyIndices = NULL;
1062 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1063 buf_info.flags = 0;
1064 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1065 ASSERT_VK_SUCCESS(err);
1066
1067 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1068
1069 VkMemoryAllocateInfo alloc_info = {};
1070 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1071 alloc_info.pNext = NULL;
1072 alloc_info.memoryTypeIndex = 0;
1073
1074 // Ensure memory is big enough for both bindings
1075 alloc_info.allocationSize = 0x10000;
1076
1077 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1078 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1079 if (!pass) {
1080 vkDestroyBuffer(m_device->device(), buffer, NULL);
1081 return;
1082 }
1083
1084 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1085 ASSERT_VK_SUCCESS(err);
1086
1087 uint8_t *pData;
1088 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1089 (void **)&pData);
1090 ASSERT_VK_SUCCESS(err);
1091
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001092 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001093
1094 vkUnmapMemory(m_device->device(), mem);
1095
1096 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1097 ASSERT_VK_SUCCESS(err);
1098
1099 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1100 // memory. In fact, it was never used by the GPU.
1101 // Just be be sure, wait for idle.
1102 vkDestroyBuffer(m_device->device(), buffer, NULL);
1103 vkDeviceWaitIdle(m_device->device());
1104
1105 VkImageCreateInfo image_create_info = {};
1106 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1107 image_create_info.pNext = NULL;
1108 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1109 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1110 image_create_info.extent.width = 64;
1111 image_create_info.extent.height = 64;
1112 image_create_info.extent.depth = 1;
1113 image_create_info.mipLevels = 1;
1114 image_create_info.arrayLayers = 1;
1115 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1116 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1117 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1118 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1119 image_create_info.queueFamilyIndexCount = 0;
1120 image_create_info.pQueueFamilyIndices = NULL;
1121 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1122 image_create_info.flags = 0;
1123
1124 VkMemoryAllocateInfo mem_alloc = {};
1125 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1126 mem_alloc.pNext = NULL;
1127 mem_alloc.allocationSize = 0;
1128 mem_alloc.memoryTypeIndex = 0;
1129
1130 /* Create a mappable image. It will be the texture if linear images are ok
1131 * to be textures or it will be the staging image if they are not.
1132 */
1133 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1134 ASSERT_VK_SUCCESS(err);
1135
1136 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1137
1138 mem_alloc.allocationSize = mem_reqs.size;
1139
1140 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc,
1141 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1142 if (!pass) {
1143 vkDestroyImage(m_device->device(), image, NULL);
1144 return;
1145 }
1146
Tobin Ehlis077ded32016-05-12 17:39:13 -06001147 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001148 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1149 ASSERT_VK_SUCCESS(err);
1150
1151 m_errorMonitor->VerifyNotFound();
1152
1153 vkDestroyBuffer(m_device->device(), buffer, NULL);
1154 vkDestroyImage(m_device->device(), image, NULL);
1155}
1156
Tobin Ehlisf11be982016-05-11 13:52:53 -06001157TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1158 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1159 "buffer and image to memory such that they will alias.");
1160 VkResult err;
1161 bool pass;
1162 ASSERT_NO_FATAL_FAILURE(InitState());
1163
Tobin Ehlis077ded32016-05-12 17:39:13 -06001164 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001165 VkImage image;
1166 VkDeviceMemory mem; // buffer will be bound first
1167 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001168 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001169
1170 VkBufferCreateInfo buf_info = {};
1171 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1172 buf_info.pNext = NULL;
1173 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1174 buf_info.size = 256;
1175 buf_info.queueFamilyIndexCount = 0;
1176 buf_info.pQueueFamilyIndices = NULL;
1177 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1178 buf_info.flags = 0;
1179 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1180 ASSERT_VK_SUCCESS(err);
1181
Tobin Ehlis077ded32016-05-12 17:39:13 -06001182 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001183
1184 VkImageCreateInfo image_create_info = {};
1185 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1186 image_create_info.pNext = NULL;
1187 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1188 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1189 image_create_info.extent.width = 64;
1190 image_create_info.extent.height = 64;
1191 image_create_info.extent.depth = 1;
1192 image_create_info.mipLevels = 1;
1193 image_create_info.arrayLayers = 1;
1194 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1195 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1196 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1197 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1198 image_create_info.queueFamilyIndexCount = 0;
1199 image_create_info.pQueueFamilyIndices = NULL;
1200 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1201 image_create_info.flags = 0;
1202
Tobin Ehlisf11be982016-05-11 13:52:53 -06001203 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1204 ASSERT_VK_SUCCESS(err);
1205
Tobin Ehlis077ded32016-05-12 17:39:13 -06001206 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1207
1208 VkMemoryAllocateInfo alloc_info = {};
1209 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1210 alloc_info.pNext = NULL;
1211 alloc_info.memoryTypeIndex = 0;
1212 // Ensure memory is big enough for both bindings
1213 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
1214 pass = m_device->phy().set_memory_type(
1215 buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info,
1216 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001217 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001218 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001219 vkDestroyImage(m_device->device(), image, NULL);
1220 return;
1221 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001222 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1223 ASSERT_VK_SUCCESS(err);
1224 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1225 ASSERT_VK_SUCCESS(err);
1226
Tobin Ehlisf11be982016-05-11 13:52:53 -06001227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1228 " is aliased with buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001229 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001230 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1231 m_errorMonitor->VerifyFound();
1232
1233 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001234 // aliasing buffer2
1235 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1236 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001237 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1238 ASSERT_VK_SUCCESS(err);
1239 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1240 ASSERT_VK_SUCCESS(err);
1241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1242 " is aliased with image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001243 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001244 m_errorMonitor->VerifyFound();
1245
1246 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001247 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001248 vkDestroyImage(m_device->device(), image, NULL);
1249 vkFreeMemory(m_device->device(), mem, NULL);
1250 vkFreeMemory(m_device->device(), mem_img, NULL);
1251}
1252
Tobin Ehlis35372522016-05-12 08:32:31 -06001253TEST_F(VkLayerTest, InvalidMemoryMapping) {
1254 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1255 VkResult err;
1256 bool pass;
1257 ASSERT_NO_FATAL_FAILURE(InitState());
1258
1259 VkBuffer buffer;
1260 VkDeviceMemory mem;
1261 VkMemoryRequirements mem_reqs;
1262
1263 VkBufferCreateInfo buf_info = {};
1264 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1265 buf_info.pNext = NULL;
1266 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1267 buf_info.size = 256;
1268 buf_info.queueFamilyIndexCount = 0;
1269 buf_info.pQueueFamilyIndices = NULL;
1270 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1271 buf_info.flags = 0;
1272 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1273 ASSERT_VK_SUCCESS(err);
1274
1275 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1276 VkMemoryAllocateInfo alloc_info = {};
1277 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1278 alloc_info.pNext = NULL;
1279 alloc_info.memoryTypeIndex = 0;
1280
1281 // Ensure memory is big enough for both bindings
1282 static const VkDeviceSize allocation_size = 0x10000;
1283 alloc_info.allocationSize = allocation_size;
1284 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1285 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1286 if (!pass) {
1287 vkDestroyBuffer(m_device->device(), buffer, NULL);
1288 return;
1289 }
1290 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1291 ASSERT_VK_SUCCESS(err);
1292
1293 uint8_t *pData;
1294 // Attempt to map memory size 0 is invalid
1295 m_errorMonitor->SetDesiredFailureMsg(
1296 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1297 "VkMapMemory: Attempting to map memory range of size zero");
1298 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1299 m_errorMonitor->VerifyFound();
1300 // Map memory twice
1301 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1302 (void **)&pData);
1303 ASSERT_VK_SUCCESS(err);
1304 m_errorMonitor->SetDesiredFailureMsg(
1305 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1306 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1307 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1308 (void **)&pData);
1309 m_errorMonitor->VerifyFound();
1310
1311 // Unmap the memory to avoid re-map error
1312 vkUnmapMemory(m_device->device(), mem);
1313 // overstep allocation with VK_WHOLE_SIZE
1314 m_errorMonitor->SetDesiredFailureMsg(
1315 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1316 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1317 err = vkMapMemory(m_device->device(), mem, allocation_size + 1,
1318 VK_WHOLE_SIZE, 0, (void **)&pData);
1319 m_errorMonitor->VerifyFound();
1320 // overstep allocation w/o VK_WHOLE_SIZE
1321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1322 " oversteps total array size 0x");
1323 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0,
1324 (void **)&pData);
1325 m_errorMonitor->VerifyFound();
1326 // Now error due to unmapping memory that's not mapped
1327 m_errorMonitor->SetDesiredFailureMsg(
1328 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1329 "Unmapping Memory without memory being mapped: ");
1330 vkUnmapMemory(m_device->device(), mem);
1331 m_errorMonitor->VerifyFound();
1332 // Now map memory and cause errors due to flushing invalid ranges
1333 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0,
1334 (void **)&pData);
1335 ASSERT_VK_SUCCESS(err);
1336 VkMappedMemoryRange mmr = {};
1337 mmr.memory = mem;
1338 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
1339 m_errorMonitor->SetDesiredFailureMsg(
1340 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1341 ") is less than Memory Object's offset (");
1342 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1343 m_errorMonitor->VerifyFound();
1344 // Now flush range that oversteps mapped range
1345 vkUnmapMemory(m_device->device(), mem);
1346 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1347 ASSERT_VK_SUCCESS(err);
1348 mmr.offset = 16;
1349 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
1350 m_errorMonitor->SetDesiredFailureMsg(
1351 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1352 ") exceeds the Memory Object's upper-bound (");
1353 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1354 m_errorMonitor->VerifyFound();
1355
1356 pass =
1357 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1358 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1359 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
1360 if (!pass) {
1361 vkFreeMemory(m_device->device(), mem, NULL);
1362 vkDestroyBuffer(m_device->device(), buffer, NULL);
1363 return;
1364 }
1365 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1366 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1367
1368 vkDestroyBuffer(m_device->device(), buffer, NULL);
1369 vkFreeMemory(m_device->device(), mem, NULL);
1370}
1371
Ian Elliott1c32c772016-04-28 14:47:13 -06001372TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1373 VkResult err;
1374 bool pass;
1375
Ian Elliott489eec02016-05-05 14:12:44 -06001376// FIXME: After we turn on this code for non-Linux platforms, uncomment the
1377// following declaration (which is temporarily being moved below):
1378// VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001379 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1380 VkSwapchainCreateInfoKHR swapchain_create_info = {};
1381 uint32_t swapchain_image_count = 0;
1382// VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1383 uint32_t image_index = 0;
1384// VkPresentInfoKHR present_info = {};
1385
1386 ASSERT_NO_FATAL_FAILURE(InitState());
1387
Ian Elliott3f06ce52016-04-29 14:46:21 -06001388#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1389#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1390 // Use the functions from the VK_KHR_android_surface extension without
1391 // enabling that extension:
1392
1393 // Create a surface:
1394 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001395 m_errorMonitor->SetDesiredFailureMsg(
1396 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1397 "extension was not enabled for this");
1398 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL,
1399 &surface);
1400 pass = (err != VK_SUCCESS);
1401 ASSERT_TRUE(pass);
1402 m_errorMonitor->VerifyFound();
1403#endif // VK_USE_PLATFORM_ANDROID_KHR
1404
1405
1406#if defined(VK_USE_PLATFORM_MIR_KHR)
1407 // Use the functions from the VK_KHR_mir_surface extension without enabling
1408 // that extension:
1409
1410 // Create a surface:
1411 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001412 m_errorMonitor->SetDesiredFailureMsg(
1413 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1414 "extension was not enabled for this");
1415 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1416 pass = (err != VK_SUCCESS);
1417 ASSERT_TRUE(pass);
1418 m_errorMonitor->VerifyFound();
1419
1420 // Tell whether an mir_connection supports presentation:
1421 MirConnection *mir_connection = NULL;
1422 m_errorMonitor->SetDesiredFailureMsg(
1423 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1424 "extension was not enabled for this");
1425 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection,
1426 visual_id);
1427 m_errorMonitor->VerifyFound();
1428#endif // VK_USE_PLATFORM_MIR_KHR
1429
1430
1431#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1432 // Use the functions from the VK_KHR_wayland_surface extension without
1433 // enabling that extension:
1434
1435 // Create a surface:
1436 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001437 m_errorMonitor->SetDesiredFailureMsg(
1438 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1439 "extension was not enabled for this");
1440 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL,
1441 &surface);
1442 pass = (err != VK_SUCCESS);
1443 ASSERT_TRUE(pass);
1444 m_errorMonitor->VerifyFound();
1445
1446 // Tell whether an wayland_display supports presentation:
1447 struct wl_display wayland_display = {};
1448 m_errorMonitor->SetDesiredFailureMsg(
1449 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1450 "extension was not enabled for this");
1451 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0,
1452 &wayland_display);
1453 m_errorMonitor->VerifyFound();
1454#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001455#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001456
1457
1458#if defined(VK_USE_PLATFORM_WIN32_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001459// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1460// TO NON-LINUX PLATFORMS:
1461VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001462 // Use the functions from the VK_KHR_win32_surface extension without
1463 // enabling that extension:
1464
1465 // Create a surface:
1466 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001467 m_errorMonitor->SetDesiredFailureMsg(
1468 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1469 "extension was not enabled for this");
1470 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL,
1471 &surface);
1472 pass = (err != VK_SUCCESS);
1473 ASSERT_TRUE(pass);
1474 m_errorMonitor->VerifyFound();
1475
1476 // Tell whether win32 supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001477 m_errorMonitor->SetDesiredFailureMsg(
1478 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1479 "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001480 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001481 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001482// Set this (for now, until all platforms are supported and tested):
1483#define NEED_TO_TEST_THIS_ON_PLATFORM
1484#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001485
1486
Ian Elliott1c32c772016-04-28 14:47:13 -06001487#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001488// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1489// TO NON-LINUX PLATFORMS:
1490VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001491 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1492 // that extension:
1493
1494 // Create a surface:
1495 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001496 m_errorMonitor->SetDesiredFailureMsg(
1497 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1498 "extension was not enabled for this");
1499 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1500 pass = (err != VK_SUCCESS);
1501 ASSERT_TRUE(pass);
1502 m_errorMonitor->VerifyFound();
1503
1504 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001505 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001506 xcb_visualid_t visual_id = 0;
1507 m_errorMonitor->SetDesiredFailureMsg(
1508 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1509 "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001510 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection,
Ian Elliott1c32c772016-04-28 14:47:13 -06001511 visual_id);
1512 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001513// Set this (for now, until all platforms are supported and tested):
1514#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001515#endif // VK_USE_PLATFORM_XCB_KHR
1516
1517
Ian Elliott12630812016-04-29 14:35:43 -06001518#if defined(VK_USE_PLATFORM_XLIB_KHR)
1519 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1520 // that extension:
1521
1522 // Create a surface:
1523 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Ian Elliott12630812016-04-29 14:35:43 -06001524 m_errorMonitor->SetDesiredFailureMsg(
1525 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1526 "extension was not enabled for this");
1527 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1528 pass = (err != VK_SUCCESS);
1529 ASSERT_TRUE(pass);
1530 m_errorMonitor->VerifyFound();
1531
1532 // Tell whether an Xlib VisualID supports presentation:
1533 Display *dpy = NULL;
1534 VisualID visual = 0;
1535 m_errorMonitor->SetDesiredFailureMsg(
1536 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1537 "extension was not enabled for this");
1538 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1539 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001540// Set this (for now, until all platforms are supported and tested):
1541#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001542#endif // VK_USE_PLATFORM_XLIB_KHR
1543
1544
Ian Elliott1c32c772016-04-28 14:47:13 -06001545 // Use the functions from the VK_KHR_surface extension without enabling
1546 // that extension:
1547
Ian Elliott489eec02016-05-05 14:12:44 -06001548#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001549 // Destroy a surface:
1550 m_errorMonitor->SetDesiredFailureMsg(
1551 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1552 "extension was not enabled for this");
1553 vkDestroySurfaceKHR(instance(), surface, NULL);
1554 m_errorMonitor->VerifyFound();
1555
1556 // Check if surface supports presentation:
1557 VkBool32 supported = false;
1558 m_errorMonitor->SetDesiredFailureMsg(
1559 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1560 "extension was not enabled for this");
1561 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1562 pass = (err != VK_SUCCESS);
1563 ASSERT_TRUE(pass);
1564 m_errorMonitor->VerifyFound();
1565
1566 // Check surface capabilities:
1567 VkSurfaceCapabilitiesKHR capabilities = {};
1568 m_errorMonitor->SetDesiredFailureMsg(
1569 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1570 "extension was not enabled for this");
1571 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1572 &capabilities);
1573 pass = (err != VK_SUCCESS);
1574 ASSERT_TRUE(pass);
1575 m_errorMonitor->VerifyFound();
1576
1577 // Check surface formats:
1578 uint32_t format_count = 0;
1579 VkSurfaceFormatKHR *formats = NULL;
1580 m_errorMonitor->SetDesiredFailureMsg(
1581 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1582 "extension was not enabled for this");
1583 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1584 &format_count, formats);
1585 pass = (err != VK_SUCCESS);
1586 ASSERT_TRUE(pass);
1587 m_errorMonitor->VerifyFound();
1588
1589 // Check surface present modes:
1590 uint32_t present_mode_count = 0;
1591 VkSurfaceFormatKHR *present_modes = NULL;
1592 m_errorMonitor->SetDesiredFailureMsg(
1593 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1594 "extension was not enabled for this");
1595 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1596 &present_mode_count, present_modes);
1597 pass = (err != VK_SUCCESS);
1598 ASSERT_TRUE(pass);
1599 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001600#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001601
1602
1603 // Use the functions from the VK_KHR_swapchain extension without enabling
1604 // that extension:
1605
1606 // Create a swapchain:
1607 m_errorMonitor->SetDesiredFailureMsg(
1608 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1609 "extension was not enabled for this");
1610 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1611 swapchain_create_info.pNext = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001612 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info,
1613 NULL, &swapchain);
1614 pass = (err != VK_SUCCESS);
1615 ASSERT_TRUE(pass);
1616 m_errorMonitor->VerifyFound();
1617
1618 // Get the images from the swapchain:
1619 m_errorMonitor->SetDesiredFailureMsg(
1620 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1621 "extension was not enabled for this");
1622 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain,
1623 &swapchain_image_count, NULL);
1624 pass = (err != VK_SUCCESS);
1625 ASSERT_TRUE(pass);
1626 m_errorMonitor->VerifyFound();
1627
1628 // Try to acquire an image:
1629 m_errorMonitor->SetDesiredFailureMsg(
1630 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1631 "extension was not enabled for this");
1632 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0,
1633 VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index);
1634 pass = (err != VK_SUCCESS);
1635 ASSERT_TRUE(pass);
1636 m_errorMonitor->VerifyFound();
1637
1638 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001639 //
1640 // NOTE: Currently can't test this because a real swapchain is needed (as
1641 // opposed to the fake one we created) in order for the layer to lookup the
1642 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001643
1644 // Destroy the swapchain:
1645 m_errorMonitor->SetDesiredFailureMsg(
1646 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1647 "extension was not enabled for this");
1648 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1649 m_errorMonitor->VerifyFound();
1650}
1651
Ian Elliott2c1daf52016-05-12 09:41:46 -06001652TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06001653
Dustin Graves6c6d8982016-05-17 10:09:21 -06001654#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06001655 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001656
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001657 VkResult err;
1658 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06001659 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1660 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001661 // uint32_t swapchain_image_count = 0;
1662 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1663 // uint32_t image_index = 0;
1664 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06001665
1666 ASSERT_NO_FATAL_FAILURE(InitState());
1667
1668 // Use the create function from one of the VK_KHR_*_surface extension in
1669 // order to create a surface, testing all known errors in the process,
1670 // before successfully creating a surface:
1671 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1673 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001674 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
1675 pass = (err != VK_SUCCESS);
1676 ASSERT_TRUE(pass);
1677 m_errorMonitor->VerifyFound();
1678
1679 // Next, try to create a surface with the wrong
1680 // VkXcbSurfaceCreateInfoKHR::sType:
1681 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
1682 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1684 "called with the wrong value for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001685 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1686 pass = (err != VK_SUCCESS);
1687 ASSERT_TRUE(pass);
1688 m_errorMonitor->VerifyFound();
1689
Ian Elliott2c1daf52016-05-12 09:41:46 -06001690 // Create a native window, and then correctly create a surface:
1691 xcb_connection_t *connection;
1692 xcb_screen_t *screen;
1693 xcb_window_t xcb_window;
1694 xcb_intern_atom_reply_t *atom_wm_delete_window;
1695
1696 const xcb_setup_t *setup;
1697 xcb_screen_iterator_t iter;
1698 int scr;
1699 uint32_t value_mask, value_list[32];
1700 int width = 1;
1701 int height = 1;
1702
1703 connection = xcb_connect(NULL, &scr);
1704 ASSERT_TRUE(connection != NULL);
1705 setup = xcb_get_setup(connection);
1706 iter = xcb_setup_roots_iterator(setup);
1707 while (scr-- > 0)
1708 xcb_screen_next(&iter);
1709 screen = iter.data;
1710
1711 xcb_window = xcb_generate_id(connection);
1712
1713 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
1714 value_list[0] = screen->black_pixel;
1715 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE |
1716 XCB_EVENT_MASK_STRUCTURE_NOTIFY;
1717
1718 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window,
1719 screen->root, 0, 0, width, height, 0,
1720 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual,
1721 value_mask, value_list);
1722
1723 /* Magic code that will send notification when window is destroyed */
1724 xcb_intern_atom_cookie_t cookie =
1725 xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
1726 xcb_intern_atom_reply_t *reply =
1727 xcb_intern_atom_reply(connection, cookie, 0);
1728
1729 xcb_intern_atom_cookie_t cookie2 =
1730 xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001731 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001732 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window,
1733 (*reply).atom, 4, 32, 1,
1734 &(*atom_wm_delete_window).atom);
1735 free(reply);
1736
1737 xcb_map_window(connection, xcb_window);
1738
1739 // Force the x/y coordinates to 100,100 results are identical in consecutive
1740 // runs
1741 const uint32_t coords[] = {100, 100};
1742 xcb_configure_window(connection, xcb_window,
1743 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
1744
Ian Elliott2c1daf52016-05-12 09:41:46 -06001745 // Finally, try to correctly create a surface:
1746 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
1747 xcb_create_info.pNext = NULL;
1748 xcb_create_info.flags = 0;
1749 xcb_create_info.connection = connection;
1750 xcb_create_info.window = xcb_window;
1751 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1752 pass = (err == VK_SUCCESS);
1753 ASSERT_TRUE(pass);
1754
Ian Elliott2c1daf52016-05-12 09:41:46 -06001755 // Check if surface supports presentation:
1756
1757 // 1st, do so without having queried the queue families:
1758 VkBool32 supported = false;
1759 // TODO: Get the following error to come out:
1760 m_errorMonitor->SetDesiredFailureMsg(
1761 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1762 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
1763 "function");
1764 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1765 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001766 // ASSERT_TRUE(pass);
1767 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06001768
1769 // Next, query a queue family index that's too large:
1770 m_errorMonitor->SetDesiredFailureMsg(
1771 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1772 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001773 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface,
1774 &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001775 pass = (err != VK_SUCCESS);
1776 ASSERT_TRUE(pass);
1777 m_errorMonitor->VerifyFound();
1778
1779 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001780 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
1781 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06001782 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1783 pass = (err == VK_SUCCESS);
1784 ASSERT_TRUE(pass);
1785
Ian Elliott2c1daf52016-05-12 09:41:46 -06001786 // Before proceeding, try to create a swapchain without having called
1787 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
1788 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1789 swapchain_create_info.pNext = NULL;
1790 swapchain_create_info.flags = 0;
1791 m_errorMonitor->SetDesiredFailureMsg(
1792 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1793 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001794 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1795 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001796 pass = (err != VK_SUCCESS);
1797 ASSERT_TRUE(pass);
1798 m_errorMonitor->VerifyFound();
1799
Ian Elliott2c1daf52016-05-12 09:41:46 -06001800 // Get the surface capabilities:
1801 VkSurfaceCapabilitiesKHR surface_capabilities;
1802
1803 // Do so correctly (only error logged by this entrypoint is if the
1804 // extension isn't enabled):
1805 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1806 &surface_capabilities);
1807 pass = (err == VK_SUCCESS);
1808 ASSERT_TRUE(pass);
1809
Ian Elliott2c1daf52016-05-12 09:41:46 -06001810 // Get the surface formats:
1811 uint32_t surface_format_count;
1812
1813 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1815 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001816 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
1817 pass = (err == VK_SUCCESS);
1818 ASSERT_TRUE(pass);
1819 m_errorMonitor->VerifyFound();
1820
1821 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
1822 // correctly done a 1st try (to get the count):
1823 m_errorMonitor->SetDesiredFailureMsg(
1824 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1825 "but no prior positive value has been seen for");
1826 surface_format_count = 0;
1827 vkGetPhysicalDeviceSurfaceFormatsKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001828 gpu(), surface, &surface_format_count,
1829 (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001830 pass = (err == VK_SUCCESS);
1831 ASSERT_TRUE(pass);
1832 m_errorMonitor->VerifyFound();
1833
1834 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001835 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1836 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001837 pass = (err == VK_SUCCESS);
1838 ASSERT_TRUE(pass);
1839
1840 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001841 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(
1842 surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001843
1844 // Next, do a 2nd try with surface_format_count being set too high:
1845 surface_format_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1847 "that is greater than the value");
1848 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001849 surface_formats);
1850 pass = (err == VK_SUCCESS);
1851 ASSERT_TRUE(pass);
1852 m_errorMonitor->VerifyFound();
1853
1854 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001855 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1856 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001857 pass = (err == VK_SUCCESS);
1858 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001859 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001860 surface_formats);
1861 pass = (err == VK_SUCCESS);
1862 ASSERT_TRUE(pass);
1863
Ian Elliott2c1daf52016-05-12 09:41:46 -06001864 // Get the surface present modes:
1865 uint32_t surface_present_mode_count;
1866
1867 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1869 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001870 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
1871 pass = (err == VK_SUCCESS);
1872 ASSERT_TRUE(pass);
1873 m_errorMonitor->VerifyFound();
1874
1875 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
1876 // correctly done a 1st try (to get the count):
1877 m_errorMonitor->SetDesiredFailureMsg(
1878 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1879 "but no prior positive value has been seen for");
1880 surface_present_mode_count = 0;
1881 vkGetPhysicalDeviceSurfacePresentModesKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001882 gpu(), surface, &surface_present_mode_count,
1883 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001884 pass = (err == VK_SUCCESS);
1885 ASSERT_TRUE(pass);
1886 m_errorMonitor->VerifyFound();
1887
1888 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001889 vkGetPhysicalDeviceSurfacePresentModesKHR(
1890 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001891 pass = (err == VK_SUCCESS);
1892 ASSERT_TRUE(pass);
1893
1894 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001895 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(
1896 surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001897
1898 // Next, do a 2nd try with surface_format_count being set too high:
1899 surface_present_mode_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1901 "that is greater than the value");
1902 vkGetPhysicalDeviceSurfacePresentModesKHR(
1903 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001904 pass = (err == VK_SUCCESS);
1905 ASSERT_TRUE(pass);
1906 m_errorMonitor->VerifyFound();
1907
1908 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001909 vkGetPhysicalDeviceSurfacePresentModesKHR(
1910 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001911 pass = (err == VK_SUCCESS);
1912 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001913 vkGetPhysicalDeviceSurfacePresentModesKHR(
1914 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001915 pass = (err == VK_SUCCESS);
1916 ASSERT_TRUE(pass);
1917
Ian Elliott2c1daf52016-05-12 09:41:46 -06001918 // Create a swapchain:
1919
1920 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1922 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001923 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
1924 pass = (err != VK_SUCCESS);
1925 ASSERT_TRUE(pass);
1926 m_errorMonitor->VerifyFound();
1927
1928 // Next, call with a non-NULL swapchain_create_info, that has the wrong
1929 // sType:
1930 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1932 "called with the wrong value for");
1933 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1934 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001935 pass = (err != VK_SUCCESS);
1936 ASSERT_TRUE(pass);
1937 m_errorMonitor->VerifyFound();
1938
1939 // Next, call with a NULL swapchain pointer:
1940 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1941 swapchain_create_info.pNext = NULL;
1942 swapchain_create_info.flags = 0;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1944 "called with NULL pointer");
1945 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1946 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001947 pass = (err != VK_SUCCESS);
1948 ASSERT_TRUE(pass);
1949 m_errorMonitor->VerifyFound();
1950
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001951 // TODO: Enhance swapchain layer so that
1952 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06001953
1954 // Next, call with a queue family index that's too large:
1955 uint32_t queueFamilyIndex[2] = {100000, 0};
1956 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
1957 swapchain_create_info.queueFamilyIndexCount = 2;
1958 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
1959 m_errorMonitor->SetDesiredFailureMsg(
1960 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1961 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001962 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1963 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001964 pass = (err != VK_SUCCESS);
1965 ASSERT_TRUE(pass);
1966 m_errorMonitor->VerifyFound();
1967
1968 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
1969 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
1970 swapchain_create_info.queueFamilyIndexCount = 1;
1971 m_errorMonitor->SetDesiredFailureMsg(
1972 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1973 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
1974 "pCreateInfo->pQueueFamilyIndices).");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001975 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1976 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001977 pass = (err != VK_SUCCESS);
1978 ASSERT_TRUE(pass);
1979 m_errorMonitor->VerifyFound();
1980
1981 // Next, call with an invalid imageSharingMode:
1982 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
1983 swapchain_create_info.queueFamilyIndexCount = 1;
1984 m_errorMonitor->SetDesiredFailureMsg(
1985 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1986 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001987 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1988 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001989 pass = (err != VK_SUCCESS);
1990 ASSERT_TRUE(pass);
1991 m_errorMonitor->VerifyFound();
1992 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001993 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
1994 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06001995 swapchain_create_info.queueFamilyIndexCount = 0;
1996 queueFamilyIndex[0] = 0;
1997 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
1998
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001999 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002000 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002001 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002002 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002003 // Destroy the swapchain:
2004
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002005 // TODOs:
2006 //
2007 // - Try destroying the device without first destroying the swapchain
2008 //
2009 // - Try destroying the device without first destroying the surface
2010 //
2011 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002012
2013 // Destroy the surface:
2014 vkDestroySurfaceKHR(instance(), surface, NULL);
2015
Ian Elliott2c1daf52016-05-12 09:41:46 -06002016 // Tear down the window:
2017 xcb_destroy_window(connection, xcb_window);
2018 xcb_disconnect(connection);
2019
2020#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002021 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002022#endif // VK_USE_PLATFORM_XCB_KHR
2023}
2024
Karl Schultz6addd812016-02-02 17:17:23 -07002025TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2026 VkResult err;
2027 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002028
Karl Schultz6addd812016-02-02 17:17:23 -07002029 m_errorMonitor->SetDesiredFailureMsg(
2030 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002031 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
2032
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002033 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002034
2035 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002036 VkImage image;
2037 VkDeviceMemory mem;
2038 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002039
Karl Schultz6addd812016-02-02 17:17:23 -07002040 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2041 const int32_t tex_width = 32;
2042 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002043
Tony Barboureb254902015-07-15 12:50:33 -06002044 VkImageCreateInfo image_create_info = {};
2045 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002046 image_create_info.pNext = NULL;
2047 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2048 image_create_info.format = tex_format;
2049 image_create_info.extent.width = tex_width;
2050 image_create_info.extent.height = tex_height;
2051 image_create_info.extent.depth = 1;
2052 image_create_info.mipLevels = 1;
2053 image_create_info.arrayLayers = 1;
2054 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2055 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2056 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2057 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002058
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002059 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002060 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002061 mem_alloc.pNext = NULL;
2062 mem_alloc.allocationSize = 0;
2063 // Introduce failure, do NOT set memProps to
2064 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
2065 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002066
Chia-I Wuf7458c52015-10-26 21:10:41 +08002067 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002068 ASSERT_VK_SUCCESS(err);
2069
Karl Schultz6addd812016-02-02 17:17:23 -07002070 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002071
Mark Lobodzinski23065352015-05-29 09:32:35 -05002072 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002073
Karl Schultz6addd812016-02-02 17:17:23 -07002074 pass =
2075 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0,
2076 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
2077 if (!pass) { // If we can't find any unmappable memory this test doesn't
2078 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002079 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002080 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002081 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002082
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002083 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002084 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002085 ASSERT_VK_SUCCESS(err);
2086
2087 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002088 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002089 ASSERT_VK_SUCCESS(err);
2090
2091 // Map memory as if to initialize the image
2092 void *mappedAddress = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07002093 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0,
2094 &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002095
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002096 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002097
Chia-I Wuf7458c52015-10-26 21:10:41 +08002098 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002099}
2100
Karl Schultz6addd812016-02-02 17:17:23 -07002101TEST_F(VkLayerTest, RebindMemory) {
2102 VkResult err;
2103 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002104
Karl Schultz6addd812016-02-02 17:17:23 -07002105 m_errorMonitor->SetDesiredFailureMsg(
2106 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002107 "which has already been bound to mem object");
2108
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002109 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002110
2111 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002112 VkImage image;
2113 VkDeviceMemory mem1;
2114 VkDeviceMemory mem2;
2115 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002116
Karl Schultz6addd812016-02-02 17:17:23 -07002117 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2118 const int32_t tex_width = 32;
2119 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002120
Tony Barboureb254902015-07-15 12:50:33 -06002121 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002122 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2123 image_create_info.pNext = NULL;
2124 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2125 image_create_info.format = tex_format;
2126 image_create_info.extent.width = tex_width;
2127 image_create_info.extent.height = tex_height;
2128 image_create_info.extent.depth = 1;
2129 image_create_info.mipLevels = 1;
2130 image_create_info.arrayLayers = 1;
2131 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2132 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2133 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2134 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002135
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002136 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002137 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2138 mem_alloc.pNext = NULL;
2139 mem_alloc.allocationSize = 0;
2140 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002141
Karl Schultz6addd812016-02-02 17:17:23 -07002142 // Introduce failure, do NOT set memProps to
2143 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002144 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002145 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002146 ASSERT_VK_SUCCESS(err);
2147
Karl Schultz6addd812016-02-02 17:17:23 -07002148 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002149
2150 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002151 pass =
2152 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002153 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002154
2155 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002156 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002157 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002158 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002159 ASSERT_VK_SUCCESS(err);
2160
2161 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002162 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002163 ASSERT_VK_SUCCESS(err);
2164
Karl Schultz6addd812016-02-02 17:17:23 -07002165 // Introduce validation failure, try to bind a different memory object to
2166 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002167 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002168
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002169 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002170
Chia-I Wuf7458c52015-10-26 21:10:41 +08002171 vkDestroyImage(m_device->device(), image, NULL);
2172 vkFreeMemory(m_device->device(), mem1, NULL);
2173 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002174}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002175
Karl Schultz6addd812016-02-02 17:17:23 -07002176TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002177 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002178
Karl Schultz6addd812016-02-02 17:17:23 -07002179 m_errorMonitor->SetDesiredFailureMsg(
2180 VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2181 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002182
2183 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002184 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2185 fenceInfo.pNext = NULL;
2186 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002187
Tony Barbour300a6082015-04-07 13:44:53 -06002188 ASSERT_NO_FATAL_FAILURE(InitState());
2189 ASSERT_NO_FATAL_FAILURE(InitViewport());
2190 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2191
Tony Barbourfe3351b2015-07-28 10:17:20 -06002192 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002193 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
2194 m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002195 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002196
2197 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002198
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002199 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002200 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2201 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002202 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002203 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002204 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002205 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002206 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002207 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002208 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002209
2210 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002211 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002212
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002213 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002214}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002215// This is a positive test. We used to expect error in this case but spec now
2216// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002217TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002218 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002219 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002220 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002221 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2222 fenceInfo.pNext = NULL;
2223
Tony Barbour0b4d9562015-04-09 10:48:04 -06002224 ASSERT_NO_FATAL_FAILURE(InitState());
2225 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002226 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002227 VkResult result = vkResetFences(m_device->device(), 1, fences);
2228 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002229
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002230 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002231}
Tobin Ehlis41376e12015-07-03 08:45:14 -06002232
2233TEST_F(VkLayerTest, InvalidUsageBits)
2234{
Tony Barbourf92621a2016-05-02 14:28:12 -06002235 TEST_DESCRIPTION(
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002236 "Specify wrong usage for image then create conflicting view of image "
Tony Barbourf92621a2016-05-02 14:28:12 -06002237 "Initialize buffer with wrong usage then perform copy expecting errors "
2238 "from both the image and the buffer (2 calls)");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002240 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002241
2242 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002243 VkImageObj image(m_device);
2244 // Initialize image with USAGE_INPUT_ATTACHMENT
Tobin Ehlis8b313c02016-05-25 15:01:52 -06002245 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT,
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002246 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
2247 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002248
Tony Barbourf92621a2016-05-02 14:28:12 -06002249 VkImageView dsv;
2250 VkImageViewCreateInfo dsvci = {};
2251 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2252 dsvci.image = image.handle();
2253 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2254 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2255 dsvci.subresourceRange.layerCount = 1;
2256 dsvci.subresourceRange.baseMipLevel = 0;
2257 dsvci.subresourceRange.levelCount = 1;
2258 dsvci.subresourceRange.aspectMask =
2259 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002260
Tony Barbourf92621a2016-05-02 14:28:12 -06002261 // Create a view with depth / stencil aspect for image with different usage
2262 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002263
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002264 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002265
2266 // Initialize buffer with TRANSFER_DST usage
2267 vk_testing::Buffer buffer;
2268 VkMemoryPropertyFlags reqs = 0;
2269 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2270 VkBufferImageCopy region = {};
2271 region.bufferRowLength = 128;
2272 region.bufferImageHeight = 128;
2273 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2274 region.imageSubresource.layerCount = 1;
2275 region.imageExtent.height = 16;
2276 region.imageExtent.width = 16;
2277 region.imageExtent.depth = 1;
2278
2279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2280 "Invalid usage flag for buffer ");
2281 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2282 // TRANSFER_DST
2283 BeginCommandBuffer();
2284 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2285 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2286 1, &region);
2287 m_errorMonitor->VerifyFound();
2288
2289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2290 "Invalid usage flag for image ");
2291 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2292 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2293 1, &region);
2294 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002295}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002296#endif // MEM_TRACKER_TESTS
2297
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002298#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002299
2300TEST_F(VkLayerTest, LeakAnObject) {
2301 VkResult err;
2302
2303 TEST_DESCRIPTION(
2304 "Create a fence and destroy its device without first destroying the fence.");
2305
2306 // Note that we have to create a new device since destroying the
2307 // framework's device causes Teardown() to fail and just calling Teardown
2308 // will destroy the errorMonitor.
2309
2310 m_errorMonitor->SetDesiredFailureMsg(
2311 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2312 "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object");
2313
2314 ASSERT_NO_FATAL_FAILURE(InitState());
2315
2316 const std::vector<VkQueueFamilyProperties> queue_props =
2317 m_device->queue_props;
2318 std::vector<VkDeviceQueueCreateInfo> queue_info;
2319 queue_info.reserve(queue_props.size());
2320 std::vector<std::vector<float>> queue_priorities;
2321 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2322 VkDeviceQueueCreateInfo qi = {};
2323 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2324 qi.pNext = NULL;
2325 qi.queueFamilyIndex = i;
2326 qi.queueCount = queue_props[i].queueCount;
2327 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2328 qi.pQueuePriorities = queue_priorities[i].data();
2329 queue_info.push_back(qi);
2330 }
2331
2332 std::vector<const char *> device_layer_names;
2333 std::vector<const char *> device_extension_names;
2334 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
2335 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
2336 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
2337 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
2338 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
2339 device_layer_names.push_back("VK_LAYER_LUNARG_image");
2340 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
2341
2342 // The sacrificial device object
2343 VkDevice testDevice;
2344 VkDeviceCreateInfo device_create_info = {};
2345 auto features = m_device->phy().features();
2346 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2347 device_create_info.pNext = NULL;
2348 device_create_info.queueCreateInfoCount = queue_info.size();
2349 device_create_info.pQueueCreateInfos = queue_info.data();
2350 device_create_info.enabledLayerCount = device_layer_names.size();
2351 device_create_info.ppEnabledLayerNames = device_layer_names.data();
2352 device_create_info.pEnabledFeatures = &features;
2353 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2354 ASSERT_VK_SUCCESS(err);
2355
2356 VkFence fence;
2357 VkFenceCreateInfo fence_create_info = {};
2358 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2359 fence_create_info.pNext = NULL;
2360 fence_create_info.flags = 0;
2361 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2362 ASSERT_VK_SUCCESS(err);
2363
2364 // Induce failure by not calling vkDestroyFence
2365 vkDestroyDevice(testDevice, NULL);
2366 m_errorMonitor->VerifyFound();
2367}
2368
2369TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2370
2371 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2372 "attempt to delete them from another.");
2373
2374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2375 "FreeCommandBuffers is attempting to free Command Buffer");
2376
2377 VkCommandPool command_pool_one;
2378 VkCommandPool command_pool_two;
2379
2380 VkCommandPoolCreateInfo pool_create_info{};
2381 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2382 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2383 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2384
2385 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2386 &command_pool_one);
2387
2388 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2389 &command_pool_two);
2390
2391 VkCommandBuffer command_buffer[9];
2392 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2393 command_buffer_allocate_info.sType =
2394 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2395 command_buffer_allocate_info.commandPool = command_pool_one;
2396 command_buffer_allocate_info.commandBufferCount = 9;
2397 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2398 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2399 command_buffer);
2400
2401 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4,
2402 &command_buffer[3]);
2403
2404 m_errorMonitor->VerifyFound();
2405
2406 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2407 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2408}
2409
2410TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2411 VkResult err;
2412
2413 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
2414 "attempt to delete them from another.");
2415
2416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2417 "FreeDescriptorSets is attempting to free descriptorSet");
2418
2419 ASSERT_NO_FATAL_FAILURE(InitState());
2420 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2421
2422 VkDescriptorPoolSize ds_type_count = {};
2423 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2424 ds_type_count.descriptorCount = 1;
2425
2426 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2427 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2428 ds_pool_ci.pNext = NULL;
2429 ds_pool_ci.flags = 0;
2430 ds_pool_ci.maxSets = 1;
2431 ds_pool_ci.poolSizeCount = 1;
2432 ds_pool_ci.pPoolSizes = &ds_type_count;
2433
2434 VkDescriptorPool ds_pool_one;
2435 err =
2436 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
2437 ASSERT_VK_SUCCESS(err);
2438
2439 // Create a second descriptor pool
2440 VkDescriptorPool ds_pool_two;
2441 err =
2442 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
2443 ASSERT_VK_SUCCESS(err);
2444
2445 VkDescriptorSetLayoutBinding dsl_binding = {};
2446 dsl_binding.binding = 0;
2447 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2448 dsl_binding.descriptorCount = 1;
2449 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2450 dsl_binding.pImmutableSamplers = NULL;
2451
2452 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2453 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2454 ds_layout_ci.pNext = NULL;
2455 ds_layout_ci.bindingCount = 1;
2456 ds_layout_ci.pBindings = &dsl_binding;
2457
2458 VkDescriptorSetLayout ds_layout;
2459 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2460 &ds_layout);
2461 ASSERT_VK_SUCCESS(err);
2462
2463 VkDescriptorSet descriptorSet;
2464 VkDescriptorSetAllocateInfo alloc_info = {};
2465 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2466 alloc_info.descriptorSetCount = 1;
2467 alloc_info.descriptorPool = ds_pool_one;
2468 alloc_info.pSetLayouts = &ds_layout;
2469 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2470 &descriptorSet);
2471 ASSERT_VK_SUCCESS(err);
2472
2473 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2474
2475 m_errorMonitor->VerifyFound();
2476
2477 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2478 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2479 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2480}
2481
2482TEST_F(VkLayerTest, CreateUnknownObject) {
2483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2484 "Invalid VkImage Object ");
2485
2486 TEST_DESCRIPTION(
2487 "Pass an invalid image object handle into a Vulkan API call.");
2488
2489 ASSERT_NO_FATAL_FAILURE(InitState());
2490
2491 // Pass bogus handle into GetImageMemoryRequirements
2492 VkMemoryRequirements mem_reqs;
2493 uint64_t fakeImageHandle = 0xCADECADE;
2494 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2495
2496 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2497
2498 m_errorMonitor->VerifyFound();
2499}
2500
Karl Schultz6addd812016-02-02 17:17:23 -07002501TEST_F(VkLayerTest, PipelineNotBound) {
2502 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002503
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002504 TEST_DESCRIPTION(
2505 "Pass in an invalid pipeline object handle into a Vulkan API call.");
2506
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002508 "Invalid VkPipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002509
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002510 ASSERT_NO_FATAL_FAILURE(InitState());
2511 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002512
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002513 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002514 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2515 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002516
2517 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002518 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2519 ds_pool_ci.pNext = NULL;
2520 ds_pool_ci.maxSets = 1;
2521 ds_pool_ci.poolSizeCount = 1;
2522 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002523
2524 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002525 err =
2526 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002527 ASSERT_VK_SUCCESS(err);
2528
2529 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002530 dsl_binding.binding = 0;
2531 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2532 dsl_binding.descriptorCount = 1;
2533 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2534 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002535
2536 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002537 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2538 ds_layout_ci.pNext = NULL;
2539 ds_layout_ci.bindingCount = 1;
2540 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002541
2542 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002543 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2544 &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002545 ASSERT_VK_SUCCESS(err);
2546
2547 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002548 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002549 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002550 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002551 alloc_info.descriptorPool = ds_pool;
2552 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002553 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2554 &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002555 ASSERT_VK_SUCCESS(err);
2556
2557 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002558 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2559 pipeline_layout_ci.pNext = NULL;
2560 pipeline_layout_ci.setLayoutCount = 1;
2561 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002562
2563 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002564 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2565 &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002566 ASSERT_VK_SUCCESS(err);
2567
Mark Youngad779052016-01-06 14:26:04 -07002568 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002569
2570 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002571 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
2572 VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002573
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002574 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002575
Chia-I Wuf7458c52015-10-26 21:10:41 +08002576 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2577 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2578 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002579}
2580
Karl Schultz6addd812016-02-02 17:17:23 -07002581TEST_F(VkLayerTest, BindInvalidMemory) {
2582 VkResult err;
2583 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002584
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002586 "Invalid VkDeviceMemory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002587
Tobin Ehlisec598302015-09-15 15:02:17 -06002588 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002589
2590 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002591 VkImage image;
2592 VkDeviceMemory mem;
2593 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002594
Karl Schultz6addd812016-02-02 17:17:23 -07002595 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2596 const int32_t tex_width = 32;
2597 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002598
2599 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002600 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2601 image_create_info.pNext = NULL;
2602 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2603 image_create_info.format = tex_format;
2604 image_create_info.extent.width = tex_width;
2605 image_create_info.extent.height = tex_height;
2606 image_create_info.extent.depth = 1;
2607 image_create_info.mipLevels = 1;
2608 image_create_info.arrayLayers = 1;
2609 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2610 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2611 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2612 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002613
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002614 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002615 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2616 mem_alloc.pNext = NULL;
2617 mem_alloc.allocationSize = 0;
2618 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002619
Chia-I Wuf7458c52015-10-26 21:10:41 +08002620 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002621 ASSERT_VK_SUCCESS(err);
2622
Karl Schultz6addd812016-02-02 17:17:23 -07002623 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002624
2625 mem_alloc.allocationSize = mem_reqs.size;
2626
Karl Schultz6addd812016-02-02 17:17:23 -07002627 pass =
2628 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002629 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002630
2631 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002632 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002633 ASSERT_VK_SUCCESS(err);
2634
2635 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002636 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002637
2638 // Try to bind free memory that has been freed
2639 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2640 // This may very well return an error.
2641 (void)err;
2642
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002643 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002644
Chia-I Wuf7458c52015-10-26 21:10:41 +08002645 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002646}
2647
Karl Schultz6addd812016-02-02 17:17:23 -07002648TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2649 VkResult err;
2650 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002651
Karl Schultz6addd812016-02-02 17:17:23 -07002652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2653 "Invalid VkImage Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002654
Tobin Ehlisec598302015-09-15 15:02:17 -06002655 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002656
Karl Schultz6addd812016-02-02 17:17:23 -07002657 // Create an image object, allocate memory, destroy the object and then try
2658 // to bind it
2659 VkImage image;
2660 VkDeviceMemory mem;
2661 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002662
Karl Schultz6addd812016-02-02 17:17:23 -07002663 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2664 const int32_t tex_width = 32;
2665 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002666
2667 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002668 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2669 image_create_info.pNext = NULL;
2670 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2671 image_create_info.format = tex_format;
2672 image_create_info.extent.width = tex_width;
2673 image_create_info.extent.height = tex_height;
2674 image_create_info.extent.depth = 1;
2675 image_create_info.mipLevels = 1;
2676 image_create_info.arrayLayers = 1;
2677 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2678 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2679 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2680 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002681
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002682 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002683 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2684 mem_alloc.pNext = NULL;
2685 mem_alloc.allocationSize = 0;
2686 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002687
Chia-I Wuf7458c52015-10-26 21:10:41 +08002688 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002689 ASSERT_VK_SUCCESS(err);
2690
Karl Schultz6addd812016-02-02 17:17:23 -07002691 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002692
2693 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002694 pass =
2695 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002696 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002697
2698 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002699 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002700 ASSERT_VK_SUCCESS(err);
2701
2702 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002703 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002704 ASSERT_VK_SUCCESS(err);
2705
2706 // Now Try to bind memory to this destroyed object
2707 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2708 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002709 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002710
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002711 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002712
Chia-I Wuf7458c52015-10-26 21:10:41 +08002713 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002714}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002715
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002716#endif // OBJ_TRACKER_TESTS
2717
Tobin Ehlis0788f522015-05-26 16:11:58 -06002718#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002719
2720// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05002721TEST_F(VkLayerTest, WaitEventThenSet) {
2722 TEST_DESCRIPTION(
2723 "Wait on a event then set it after the wait has been submitted.");
2724
2725 if ((m_device->queue_props.empty()) ||
2726 (m_device->queue_props[0].queueCount < 2))
2727 return;
2728
2729 m_errorMonitor->ExpectSuccess();
2730
2731 VkEvent event;
2732 VkEventCreateInfo event_create_info{};
2733 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2734 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
2735
2736 VkCommandPool command_pool;
2737 VkCommandPoolCreateInfo pool_create_info{};
2738 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2739 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2740 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2741 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2742 &command_pool);
2743
2744 VkCommandBuffer command_buffer;
2745 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2746 command_buffer_allocate_info.sType =
2747 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2748 command_buffer_allocate_info.commandPool = command_pool;
2749 command_buffer_allocate_info.commandBufferCount = 1;
2750 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2751 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2752 &command_buffer);
2753
2754 VkQueue queue = VK_NULL_HANDLE;
2755 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2756 1, &queue);
2757
2758 {
2759 VkCommandBufferBeginInfo begin_info{};
2760 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2761 vkBeginCommandBuffer(command_buffer, &begin_info);
2762
2763 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT,
2764 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
2765 nullptr, 0, nullptr);
2766 vkCmdResetEvent(command_buffer, event,
2767 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
2768 vkEndCommandBuffer(command_buffer);
2769 }
2770 {
2771 VkSubmitInfo submit_info{};
2772 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2773 submit_info.commandBufferCount = 1;
2774 submit_info.pCommandBuffers = &command_buffer;
2775 submit_info.signalSemaphoreCount = 0;
2776 submit_info.pSignalSemaphores = nullptr;
2777 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2778 }
2779 { vkSetEvent(m_device->device(), event); }
2780
2781 vkQueueWaitIdle(queue);
2782
2783 vkDestroyEvent(m_device->device(), event, nullptr);
2784 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
2785 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2786
2787 m_errorMonitor->VerifyNotFound();
2788}
Michael Lentine5627e692016-05-20 17:45:02 -05002789// This is a positive test. No errors should be generated.
2790TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
2791 TEST_DESCRIPTION(
2792 "Issue a query and copy from it on a second command buffer.");
2793
2794 if ((m_device->queue_props.empty()) ||
2795 (m_device->queue_props[0].queueCount < 2))
2796 return;
2797
2798 m_errorMonitor->ExpectSuccess();
2799
2800 VkQueryPool query_pool;
2801 VkQueryPoolCreateInfo query_pool_create_info{};
2802 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
2803 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
2804 query_pool_create_info.queryCount = 1;
2805 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr,
2806 &query_pool);
2807
2808 VkCommandPool command_pool;
2809 VkCommandPoolCreateInfo pool_create_info{};
2810 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2811 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2812 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2813 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2814 &command_pool);
2815
2816 VkCommandBuffer command_buffer[2];
2817 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2818 command_buffer_allocate_info.sType =
2819 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2820 command_buffer_allocate_info.commandPool = command_pool;
2821 command_buffer_allocate_info.commandBufferCount = 2;
2822 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2823 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2824 command_buffer);
2825
2826 VkQueue queue = VK_NULL_HANDLE;
2827 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2828 1, &queue);
2829
2830 uint32_t qfi = 0;
2831 VkBufferCreateInfo buff_create_info = {};
2832 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2833 buff_create_info.size = 1024;
2834 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
2835 buff_create_info.queueFamilyIndexCount = 1;
2836 buff_create_info.pQueueFamilyIndices = &qfi;
2837
2838 VkResult err;
2839 VkBuffer buffer;
2840 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
2841 ASSERT_VK_SUCCESS(err);
2842 VkMemoryAllocateInfo mem_alloc = {};
2843 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2844 mem_alloc.pNext = NULL;
2845 mem_alloc.allocationSize = 1024;
2846 mem_alloc.memoryTypeIndex = 0;
2847
2848 VkMemoryRequirements memReqs;
2849 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
2850 bool pass =
2851 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
2852 if (!pass) {
2853 vkDestroyBuffer(m_device->device(), buffer, NULL);
2854 return;
2855 }
2856
2857 VkDeviceMemory mem;
2858 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2859 ASSERT_VK_SUCCESS(err);
2860 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
2861 ASSERT_VK_SUCCESS(err);
2862
2863 {
2864 VkCommandBufferBeginInfo begin_info{};
2865 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2866 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2867
2868 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
2869 vkCmdWriteTimestamp(command_buffer[0],
2870 VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
2871
2872 vkEndCommandBuffer(command_buffer[0]);
2873
2874 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2875
2876 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer,
2877 0, 0, 0);
2878
2879 vkEndCommandBuffer(command_buffer[1]);
2880 }
2881 {
2882 VkSubmitInfo submit_info{};
2883 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2884 submit_info.commandBufferCount = 2;
2885 submit_info.pCommandBuffers = command_buffer;
2886 submit_info.signalSemaphoreCount = 0;
2887 submit_info.pSignalSemaphores = nullptr;
2888 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2889 }
2890
2891 vkQueueWaitIdle(queue);
2892
2893 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
2894 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
2895 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2896
2897 m_errorMonitor->VerifyNotFound();
2898}
Michael Lentine860b0fe2016-05-20 10:14:00 -05002899
2900TEST_F(VkLayerTest, ResetEventThenSet) {
2901 TEST_DESCRIPTION(
2902 "Reset an event then set it after the reset has been submitted.");
2903
2904 if ((m_device->queue_props.empty()) ||
2905 (m_device->queue_props[0].queueCount < 2))
2906 return;
2907
2908 m_errorMonitor->ExpectSuccess();
2909
2910 VkEvent event;
2911 VkEventCreateInfo event_create_info{};
2912 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2913 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
2914
2915 VkCommandPool command_pool;
2916 VkCommandPoolCreateInfo pool_create_info{};
2917 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2918 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2919 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2920 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2921 &command_pool);
2922
2923 VkCommandBuffer command_buffer;
2924 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2925 command_buffer_allocate_info.sType =
2926 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2927 command_buffer_allocate_info.commandPool = command_pool;
2928 command_buffer_allocate_info.commandBufferCount = 1;
2929 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2930 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2931 &command_buffer);
2932
2933 VkQueue queue = VK_NULL_HANDLE;
2934 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2935 1, &queue);
2936
2937 {
2938 VkCommandBufferBeginInfo begin_info{};
2939 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2940 vkBeginCommandBuffer(command_buffer, &begin_info);
2941
2942 vkCmdResetEvent(command_buffer, event,
2943 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
2944 vkCmdWaitEvents(command_buffer, 1, &event,
2945 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2946 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
2947 nullptr, 0, nullptr);
2948 vkEndCommandBuffer(command_buffer);
2949 }
2950 {
2951 VkSubmitInfo submit_info{};
2952 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2953 submit_info.commandBufferCount = 1;
2954 submit_info.pCommandBuffers = &command_buffer;
2955 submit_info.signalSemaphoreCount = 0;
2956 submit_info.pSignalSemaphores = nullptr;
2957 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2958 }
2959 {
2960 m_errorMonitor->SetDesiredFailureMsg(
2961 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event "
2962 "0x1 that is already in use by a "
2963 "command buffer.");
2964 vkSetEvent(m_device->device(), event);
2965 m_errorMonitor->VerifyFound();
2966 }
2967
2968 vkQueueWaitIdle(queue);
2969
2970 vkDestroyEvent(m_device->device(), event, nullptr);
2971 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
2972 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2973}
2974
2975// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06002976TEST_F(VkLayerTest, TwoFencesThreeFrames) {
2977 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
2978 "run through a Submit & WaitForFences cycle 3 times. This "
2979 "previously revealed a bug so running this positive test "
2980 "to prevent a regression.");
2981 m_errorMonitor->ExpectSuccess();
2982
2983 ASSERT_NO_FATAL_FAILURE(InitState());
2984 VkQueue queue = VK_NULL_HANDLE;
2985 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2986 0, &queue);
2987
2988 static const uint32_t NUM_OBJECTS = 2;
2989 static const uint32_t NUM_FRAMES = 3;
2990 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
2991 VkFence fences[NUM_OBJECTS] = {};
2992
2993 VkCommandPool cmd_pool;
2994 VkCommandPoolCreateInfo cmd_pool_ci = {};
2995 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2996 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
2997 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2998 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci,
2999 nullptr, &cmd_pool);
3000 ASSERT_VK_SUCCESS(err);
3001
3002 VkCommandBufferAllocateInfo cmd_buf_info = {};
3003 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3004 cmd_buf_info.commandPool = cmd_pool;
3005 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3006 cmd_buf_info.commandBufferCount = 1;
3007
3008 VkFenceCreateInfo fence_ci = {};
3009 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3010 fence_ci.pNext = nullptr;
3011 fence_ci.flags = 0;
3012
3013 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3014 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info,
3015 &cmd_buffers[i]);
3016 ASSERT_VK_SUCCESS(err);
3017 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
3018 ASSERT_VK_SUCCESS(err);
3019 }
3020
3021 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06003022 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
3023 // Create empty cmd buffer
3024 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3025 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003026
Tobin Ehlisf9025162016-05-26 06:55:21 -06003027 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
3028 ASSERT_VK_SUCCESS(err);
3029 err = vkEndCommandBuffer(cmd_buffers[obj]);
3030 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003031
Tobin Ehlisf9025162016-05-26 06:55:21 -06003032 VkSubmitInfo submit_info = {};
3033 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3034 submit_info.commandBufferCount = 1;
3035 submit_info.pCommandBuffers = &cmd_buffers[obj];
3036 // Submit cmd buffer and wait for fence
3037 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
3038 ASSERT_VK_SUCCESS(err);
3039 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE,
3040 UINT64_MAX);
3041 ASSERT_VK_SUCCESS(err);
3042 err = vkResetFences(m_device->device(), 1, &fences[obj]);
3043 ASSERT_VK_SUCCESS(err);
3044 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003045 }
3046 m_errorMonitor->VerifyNotFound();
3047}
3048// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003049TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
3050
3051 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3052 "submitted on separate queues followed by a QueueWaitIdle.");
3053
Dustin Graves48458142016-04-29 16:11:55 -06003054 if ((m_device->queue_props.empty()) ||
3055 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003056 return;
3057
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003058 m_errorMonitor->ExpectSuccess();
3059
3060 VkSemaphore semaphore;
3061 VkSemaphoreCreateInfo semaphore_create_info{};
3062 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3063 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3064 &semaphore);
3065
3066 VkCommandPool command_pool;
3067 VkCommandPoolCreateInfo pool_create_info{};
3068 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3069 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3070 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3071 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3072 &command_pool);
3073
3074 VkCommandBuffer command_buffer[2];
3075 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3076 command_buffer_allocate_info.sType =
3077 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3078 command_buffer_allocate_info.commandPool = command_pool;
3079 command_buffer_allocate_info.commandBufferCount = 2;
3080 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3081 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3082 command_buffer);
3083
3084 VkQueue queue = VK_NULL_HANDLE;
3085 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3086 1, &queue);
3087
3088 {
3089 VkCommandBufferBeginInfo begin_info{};
3090 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3091 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3092
3093 vkCmdPipelineBarrier(command_buffer[0],
3094 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3095 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3096 0, nullptr, 0, nullptr);
3097
3098 VkViewport viewport{};
3099 viewport.maxDepth = 1.0f;
3100 viewport.minDepth = 0.0f;
3101 viewport.width = 512;
3102 viewport.height = 512;
3103 viewport.x = 0;
3104 viewport.y = 0;
3105 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3106 vkEndCommandBuffer(command_buffer[0]);
3107 }
3108 {
3109 VkCommandBufferBeginInfo begin_info{};
3110 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3111 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3112
3113 VkViewport viewport{};
3114 viewport.maxDepth = 1.0f;
3115 viewport.minDepth = 0.0f;
3116 viewport.width = 512;
3117 viewport.height = 512;
3118 viewport.x = 0;
3119 viewport.y = 0;
3120 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3121 vkEndCommandBuffer(command_buffer[1]);
3122 }
3123 {
3124 VkSubmitInfo submit_info{};
3125 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3126 submit_info.commandBufferCount = 1;
3127 submit_info.pCommandBuffers = &command_buffer[0];
3128 submit_info.signalSemaphoreCount = 1;
3129 submit_info.pSignalSemaphores = &semaphore;
3130 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3131 }
3132 {
3133 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3134 VkSubmitInfo submit_info{};
3135 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3136 submit_info.commandBufferCount = 1;
3137 submit_info.pCommandBuffers = &command_buffer[1];
3138 submit_info.waitSemaphoreCount = 1;
3139 submit_info.pWaitSemaphores = &semaphore;
3140 submit_info.pWaitDstStageMask = flags;
3141 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3142 }
3143
3144 vkQueueWaitIdle(m_device->m_queue);
3145
3146 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3147 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3148 &command_buffer[0]);
3149 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3150
3151 m_errorMonitor->VerifyNotFound();
3152}
3153
3154// This is a positive test. No errors should be generated.
3155TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
3156
3157 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3158 "submitted on separate queues, the second having a fence"
3159 "followed by a QueueWaitIdle.");
3160
Dustin Graves48458142016-04-29 16:11:55 -06003161 if ((m_device->queue_props.empty()) ||
3162 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003163 return;
3164
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003165 m_errorMonitor->ExpectSuccess();
3166
3167 VkFence fence;
3168 VkFenceCreateInfo fence_create_info{};
3169 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3170 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3171
3172 VkSemaphore semaphore;
3173 VkSemaphoreCreateInfo semaphore_create_info{};
3174 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3175 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3176 &semaphore);
3177
3178 VkCommandPool command_pool;
3179 VkCommandPoolCreateInfo pool_create_info{};
3180 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3181 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3182 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3183 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3184 &command_pool);
3185
3186 VkCommandBuffer command_buffer[2];
3187 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3188 command_buffer_allocate_info.sType =
3189 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3190 command_buffer_allocate_info.commandPool = command_pool;
3191 command_buffer_allocate_info.commandBufferCount = 2;
3192 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3193 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3194 command_buffer);
3195
3196 VkQueue queue = VK_NULL_HANDLE;
3197 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3198 1, &queue);
3199
3200 {
3201 VkCommandBufferBeginInfo begin_info{};
3202 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3203 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3204
3205 vkCmdPipelineBarrier(command_buffer[0],
3206 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3207 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3208 0, nullptr, 0, nullptr);
3209
3210 VkViewport viewport{};
3211 viewport.maxDepth = 1.0f;
3212 viewport.minDepth = 0.0f;
3213 viewport.width = 512;
3214 viewport.height = 512;
3215 viewport.x = 0;
3216 viewport.y = 0;
3217 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3218 vkEndCommandBuffer(command_buffer[0]);
3219 }
3220 {
3221 VkCommandBufferBeginInfo begin_info{};
3222 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3223 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3224
3225 VkViewport viewport{};
3226 viewport.maxDepth = 1.0f;
3227 viewport.minDepth = 0.0f;
3228 viewport.width = 512;
3229 viewport.height = 512;
3230 viewport.x = 0;
3231 viewport.y = 0;
3232 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3233 vkEndCommandBuffer(command_buffer[1]);
3234 }
3235 {
3236 VkSubmitInfo submit_info{};
3237 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3238 submit_info.commandBufferCount = 1;
3239 submit_info.pCommandBuffers = &command_buffer[0];
3240 submit_info.signalSemaphoreCount = 1;
3241 submit_info.pSignalSemaphores = &semaphore;
3242 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3243 }
3244 {
3245 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3246 VkSubmitInfo submit_info{};
3247 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3248 submit_info.commandBufferCount = 1;
3249 submit_info.pCommandBuffers = &command_buffer[1];
3250 submit_info.waitSemaphoreCount = 1;
3251 submit_info.pWaitSemaphores = &semaphore;
3252 submit_info.pWaitDstStageMask = flags;
3253 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3254 }
3255
3256 vkQueueWaitIdle(m_device->m_queue);
3257
3258 vkDestroyFence(m_device->device(), fence, nullptr);
3259 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3260 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3261 &command_buffer[0]);
3262 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3263
3264 m_errorMonitor->VerifyNotFound();
3265}
3266
3267// This is a positive test. No errors should be generated.
3268TEST_F(VkLayerTest,
3269 TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
3270
3271 TEST_DESCRIPTION(
3272 "Two command buffers, each in a separate QueueSubmit call "
3273 "submitted on separate queues, the second having a fence"
3274 "followed by two consecutive WaitForFences calls on the same fence.");
3275
Dustin Graves48458142016-04-29 16:11:55 -06003276 if ((m_device->queue_props.empty()) ||
3277 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003278 return;
3279
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003280 m_errorMonitor->ExpectSuccess();
3281
3282 VkFence fence;
3283 VkFenceCreateInfo fence_create_info{};
3284 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3285 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3286
3287 VkSemaphore semaphore;
3288 VkSemaphoreCreateInfo semaphore_create_info{};
3289 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3290 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3291 &semaphore);
3292
3293 VkCommandPool command_pool;
3294 VkCommandPoolCreateInfo pool_create_info{};
3295 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3296 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3297 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3298 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3299 &command_pool);
3300
3301 VkCommandBuffer command_buffer[2];
3302 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3303 command_buffer_allocate_info.sType =
3304 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3305 command_buffer_allocate_info.commandPool = command_pool;
3306 command_buffer_allocate_info.commandBufferCount = 2;
3307 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3308 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3309 command_buffer);
3310
3311 VkQueue queue = VK_NULL_HANDLE;
3312 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3313 1, &queue);
3314
3315 {
3316 VkCommandBufferBeginInfo begin_info{};
3317 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3318 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3319
3320 vkCmdPipelineBarrier(command_buffer[0],
3321 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3322 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3323 0, nullptr, 0, nullptr);
3324
3325 VkViewport viewport{};
3326 viewport.maxDepth = 1.0f;
3327 viewport.minDepth = 0.0f;
3328 viewport.width = 512;
3329 viewport.height = 512;
3330 viewport.x = 0;
3331 viewport.y = 0;
3332 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3333 vkEndCommandBuffer(command_buffer[0]);
3334 }
3335 {
3336 VkCommandBufferBeginInfo begin_info{};
3337 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3338 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3339
3340 VkViewport viewport{};
3341 viewport.maxDepth = 1.0f;
3342 viewport.minDepth = 0.0f;
3343 viewport.width = 512;
3344 viewport.height = 512;
3345 viewport.x = 0;
3346 viewport.y = 0;
3347 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3348 vkEndCommandBuffer(command_buffer[1]);
3349 }
3350 {
3351 VkSubmitInfo submit_info{};
3352 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3353 submit_info.commandBufferCount = 1;
3354 submit_info.pCommandBuffers = &command_buffer[0];
3355 submit_info.signalSemaphoreCount = 1;
3356 submit_info.pSignalSemaphores = &semaphore;
3357 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3358 }
3359 {
3360 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3361 VkSubmitInfo submit_info{};
3362 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3363 submit_info.commandBufferCount = 1;
3364 submit_info.pCommandBuffers = &command_buffer[1];
3365 submit_info.waitSemaphoreCount = 1;
3366 submit_info.pWaitSemaphores = &semaphore;
3367 submit_info.pWaitDstStageMask = flags;
3368 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3369 }
3370
3371 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3372 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3373
3374 vkDestroyFence(m_device->device(), fence, nullptr);
3375 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3376 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3377 &command_buffer[0]);
3378 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3379
3380 m_errorMonitor->VerifyNotFound();
3381}
3382
3383// This is a positive test. No errors should be generated.
3384TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
3385
3386 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3387 "submitted on separate queues, the second having a fence, "
3388 "followed by a WaitForFences call.");
3389
Dustin Graves48458142016-04-29 16:11:55 -06003390 if ((m_device->queue_props.empty()) ||
3391 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003392 return;
3393
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003394 m_errorMonitor->ExpectSuccess();
3395
3396 VkFence fence;
3397 VkFenceCreateInfo fence_create_info{};
3398 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3399 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3400
3401 VkSemaphore semaphore;
3402 VkSemaphoreCreateInfo semaphore_create_info{};
3403 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3404 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3405 &semaphore);
3406
3407 VkCommandPool command_pool;
3408 VkCommandPoolCreateInfo pool_create_info{};
3409 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3410 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3411 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3412 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3413 &command_pool);
3414
3415 VkCommandBuffer command_buffer[2];
3416 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3417 command_buffer_allocate_info.sType =
3418 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3419 command_buffer_allocate_info.commandPool = command_pool;
3420 command_buffer_allocate_info.commandBufferCount = 2;
3421 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3422 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3423 command_buffer);
3424
3425 VkQueue queue = VK_NULL_HANDLE;
3426 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3427 1, &queue);
3428
3429
3430 {
3431 VkCommandBufferBeginInfo begin_info{};
3432 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3433 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3434
3435 vkCmdPipelineBarrier(command_buffer[0],
3436 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3437 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3438 0, nullptr, 0, nullptr);
3439
3440 VkViewport viewport{};
3441 viewport.maxDepth = 1.0f;
3442 viewport.minDepth = 0.0f;
3443 viewport.width = 512;
3444 viewport.height = 512;
3445 viewport.x = 0;
3446 viewport.y = 0;
3447 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3448 vkEndCommandBuffer(command_buffer[0]);
3449 }
3450 {
3451 VkCommandBufferBeginInfo begin_info{};
3452 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3453 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3454
3455 VkViewport viewport{};
3456 viewport.maxDepth = 1.0f;
3457 viewport.minDepth = 0.0f;
3458 viewport.width = 512;
3459 viewport.height = 512;
3460 viewport.x = 0;
3461 viewport.y = 0;
3462 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3463 vkEndCommandBuffer(command_buffer[1]);
3464 }
3465 {
3466 VkSubmitInfo submit_info{};
3467 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3468 submit_info.commandBufferCount = 1;
3469 submit_info.pCommandBuffers = &command_buffer[0];
3470 submit_info.signalSemaphoreCount = 1;
3471 submit_info.pSignalSemaphores = &semaphore;
3472 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3473 }
3474 {
3475 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3476 VkSubmitInfo submit_info{};
3477 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3478 submit_info.commandBufferCount = 1;
3479 submit_info.pCommandBuffers = &command_buffer[1];
3480 submit_info.waitSemaphoreCount = 1;
3481 submit_info.pWaitSemaphores = &semaphore;
3482 submit_info.pWaitDstStageMask = flags;
3483 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3484 }
3485
3486 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3487
3488 vkDestroyFence(m_device->device(), fence, nullptr);
3489 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3490 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3491 &command_buffer[0]);
3492 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3493
3494 m_errorMonitor->VerifyNotFound();
3495}
3496
3497// This is a positive test. No errors should be generated.
3498TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
3499
3500 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3501 "on the same queue, sharing a signal/wait semaphore, the "
3502 "second having a fence, "
3503 "followed by a WaitForFences call.");
3504
3505 m_errorMonitor->ExpectSuccess();
3506
3507 VkFence fence;
3508 VkFenceCreateInfo fence_create_info{};
3509 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3510 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3511
3512 VkSemaphore semaphore;
3513 VkSemaphoreCreateInfo semaphore_create_info{};
3514 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3515 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3516 &semaphore);
3517
3518 VkCommandPool command_pool;
3519 VkCommandPoolCreateInfo pool_create_info{};
3520 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3521 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3522 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3523 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3524 &command_pool);
3525
3526 VkCommandBuffer command_buffer[2];
3527 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3528 command_buffer_allocate_info.sType =
3529 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3530 command_buffer_allocate_info.commandPool = command_pool;
3531 command_buffer_allocate_info.commandBufferCount = 2;
3532 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3533 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3534 command_buffer);
3535
3536 {
3537 VkCommandBufferBeginInfo begin_info{};
3538 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3539 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3540
3541 vkCmdPipelineBarrier(command_buffer[0],
3542 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3543 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3544 0, nullptr, 0, nullptr);
3545
3546 VkViewport viewport{};
3547 viewport.maxDepth = 1.0f;
3548 viewport.minDepth = 0.0f;
3549 viewport.width = 512;
3550 viewport.height = 512;
3551 viewport.x = 0;
3552 viewport.y = 0;
3553 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3554 vkEndCommandBuffer(command_buffer[0]);
3555 }
3556 {
3557 VkCommandBufferBeginInfo begin_info{};
3558 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3559 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3560
3561 VkViewport viewport{};
3562 viewport.maxDepth = 1.0f;
3563 viewport.minDepth = 0.0f;
3564 viewport.width = 512;
3565 viewport.height = 512;
3566 viewport.x = 0;
3567 viewport.y = 0;
3568 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3569 vkEndCommandBuffer(command_buffer[1]);
3570 }
3571 {
3572 VkSubmitInfo submit_info{};
3573 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3574 submit_info.commandBufferCount = 1;
3575 submit_info.pCommandBuffers = &command_buffer[0];
3576 submit_info.signalSemaphoreCount = 1;
3577 submit_info.pSignalSemaphores = &semaphore;
3578 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3579 }
3580 {
3581 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3582 VkSubmitInfo submit_info{};
3583 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3584 submit_info.commandBufferCount = 1;
3585 submit_info.pCommandBuffers = &command_buffer[1];
3586 submit_info.waitSemaphoreCount = 1;
3587 submit_info.pWaitSemaphores = &semaphore;
3588 submit_info.pWaitDstStageMask = flags;
3589 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3590 }
3591
3592 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3593
3594 vkDestroyFence(m_device->device(), fence, nullptr);
3595 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3596 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3597 &command_buffer[0]);
3598 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3599
3600 m_errorMonitor->VerifyNotFound();
3601}
3602
3603// This is a positive test. No errors should be generated.
3604TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
3605
3606 TEST_DESCRIPTION(
3607 "Two command buffers, each in a separate QueueSubmit call "
3608 "on the same queue, no fences, followed by a third QueueSubmit with NO "
3609 "SubmitInfos but with a fence, followed by a WaitForFences call.");
3610
3611 m_errorMonitor->ExpectSuccess();
3612
3613 VkFence fence;
3614 VkFenceCreateInfo fence_create_info{};
3615 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3616 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3617
3618 VkCommandPool command_pool;
3619 VkCommandPoolCreateInfo pool_create_info{};
3620 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3621 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3622 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3623 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3624 &command_pool);
3625
3626 VkCommandBuffer command_buffer[2];
3627 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3628 command_buffer_allocate_info.sType =
3629 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3630 command_buffer_allocate_info.commandPool = command_pool;
3631 command_buffer_allocate_info.commandBufferCount = 2;
3632 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3633 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3634 command_buffer);
3635
3636 {
3637 VkCommandBufferBeginInfo begin_info{};
3638 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3639 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3640
3641 vkCmdPipelineBarrier(command_buffer[0],
3642 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3643 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3644 0, nullptr, 0, nullptr);
3645
3646 VkViewport viewport{};
3647 viewport.maxDepth = 1.0f;
3648 viewport.minDepth = 0.0f;
3649 viewport.width = 512;
3650 viewport.height = 512;
3651 viewport.x = 0;
3652 viewport.y = 0;
3653 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3654 vkEndCommandBuffer(command_buffer[0]);
3655 }
3656 {
3657 VkCommandBufferBeginInfo begin_info{};
3658 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3659 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3660
3661 VkViewport viewport{};
3662 viewport.maxDepth = 1.0f;
3663 viewport.minDepth = 0.0f;
3664 viewport.width = 512;
3665 viewport.height = 512;
3666 viewport.x = 0;
3667 viewport.y = 0;
3668 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3669 vkEndCommandBuffer(command_buffer[1]);
3670 }
3671 {
3672 VkSubmitInfo submit_info{};
3673 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3674 submit_info.commandBufferCount = 1;
3675 submit_info.pCommandBuffers = &command_buffer[0];
3676 submit_info.signalSemaphoreCount = 0;
3677 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
3678 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3679 }
3680 {
3681 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3682 VkSubmitInfo submit_info{};
3683 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3684 submit_info.commandBufferCount = 1;
3685 submit_info.pCommandBuffers = &command_buffer[1];
3686 submit_info.waitSemaphoreCount = 0;
3687 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
3688 submit_info.pWaitDstStageMask = flags;
3689 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3690 }
3691
3692 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
3693
3694 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3695
3696 vkDestroyFence(m_device->device(), fence, nullptr);
3697 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3698 &command_buffer[0]);
3699 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3700
3701 m_errorMonitor->VerifyNotFound();
3702}
3703
3704// This is a positive test. No errors should be generated.
3705TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
3706
3707 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3708 "on the same queue, the second having a fence, followed "
3709 "by a WaitForFences call.");
3710
3711 m_errorMonitor->ExpectSuccess();
3712
3713 VkFence fence;
3714 VkFenceCreateInfo fence_create_info{};
3715 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3716 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3717
3718 VkCommandPool command_pool;
3719 VkCommandPoolCreateInfo pool_create_info{};
3720 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3721 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3722 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3723 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3724 &command_pool);
3725
3726 VkCommandBuffer command_buffer[2];
3727 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3728 command_buffer_allocate_info.sType =
3729 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3730 command_buffer_allocate_info.commandPool = command_pool;
3731 command_buffer_allocate_info.commandBufferCount = 2;
3732 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3733 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3734 command_buffer);
3735
3736 {
3737 VkCommandBufferBeginInfo begin_info{};
3738 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3739 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3740
3741 vkCmdPipelineBarrier(command_buffer[0],
3742 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3743 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3744 0, nullptr, 0, nullptr);
3745
3746 VkViewport viewport{};
3747 viewport.maxDepth = 1.0f;
3748 viewport.minDepth = 0.0f;
3749 viewport.width = 512;
3750 viewport.height = 512;
3751 viewport.x = 0;
3752 viewport.y = 0;
3753 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3754 vkEndCommandBuffer(command_buffer[0]);
3755 }
3756 {
3757 VkCommandBufferBeginInfo begin_info{};
3758 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3759 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3760
3761 VkViewport viewport{};
3762 viewport.maxDepth = 1.0f;
3763 viewport.minDepth = 0.0f;
3764 viewport.width = 512;
3765 viewport.height = 512;
3766 viewport.x = 0;
3767 viewport.y = 0;
3768 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3769 vkEndCommandBuffer(command_buffer[1]);
3770 }
3771 {
3772 VkSubmitInfo submit_info{};
3773 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3774 submit_info.commandBufferCount = 1;
3775 submit_info.pCommandBuffers = &command_buffer[0];
3776 submit_info.signalSemaphoreCount = 0;
3777 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
3778 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3779 }
3780 {
3781 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3782 VkSubmitInfo submit_info{};
3783 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3784 submit_info.commandBufferCount = 1;
3785 submit_info.pCommandBuffers = &command_buffer[1];
3786 submit_info.waitSemaphoreCount = 0;
3787 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
3788 submit_info.pWaitDstStageMask = flags;
3789 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3790 }
3791
3792 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3793
3794 vkDestroyFence(m_device->device(), fence, nullptr);
3795 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3796 &command_buffer[0]);
3797 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3798
3799 m_errorMonitor->VerifyNotFound();
3800}
3801
3802// This is a positive test. No errors should be generated.
3803TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
3804
3805 TEST_DESCRIPTION(
3806 "Two command buffers each in a separate SubmitInfo sent in a single "
3807 "QueueSubmit call followed by a WaitForFences call.");
3808
3809 m_errorMonitor->ExpectSuccess();
3810
3811 VkFence fence;
3812 VkFenceCreateInfo fence_create_info{};
3813 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3814 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3815
3816 VkSemaphore semaphore;
3817 VkSemaphoreCreateInfo semaphore_create_info{};
3818 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3819 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3820 &semaphore);
3821
3822 VkCommandPool command_pool;
3823 VkCommandPoolCreateInfo pool_create_info{};
3824 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3825 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3826 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3827 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3828 &command_pool);
3829
3830 VkCommandBuffer command_buffer[2];
3831 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3832 command_buffer_allocate_info.sType =
3833 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3834 command_buffer_allocate_info.commandPool = command_pool;
3835 command_buffer_allocate_info.commandBufferCount = 2;
3836 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3837 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3838 command_buffer);
3839
3840 {
3841 VkCommandBufferBeginInfo begin_info{};
3842 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3843 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3844
3845 vkCmdPipelineBarrier(command_buffer[0],
3846 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3847 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3848 0, nullptr, 0, nullptr);
3849
3850 VkViewport viewport{};
3851 viewport.maxDepth = 1.0f;
3852 viewport.minDepth = 0.0f;
3853 viewport.width = 512;
3854 viewport.height = 512;
3855 viewport.x = 0;
3856 viewport.y = 0;
3857 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3858 vkEndCommandBuffer(command_buffer[0]);
3859 }
3860 {
3861 VkCommandBufferBeginInfo begin_info{};
3862 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3863 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3864
3865 VkViewport viewport{};
3866 viewport.maxDepth = 1.0f;
3867 viewport.minDepth = 0.0f;
3868 viewport.width = 512;
3869 viewport.height = 512;
3870 viewport.x = 0;
3871 viewport.y = 0;
3872 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3873 vkEndCommandBuffer(command_buffer[1]);
3874 }
3875 {
3876 VkSubmitInfo submit_info[2];
3877 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3878
3879 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3880 submit_info[0].pNext = NULL;
3881 submit_info[0].commandBufferCount = 1;
3882 submit_info[0].pCommandBuffers = &command_buffer[0];
3883 submit_info[0].signalSemaphoreCount = 1;
3884 submit_info[0].pSignalSemaphores = &semaphore;
3885 submit_info[0].waitSemaphoreCount = 0;
3886 submit_info[0].pWaitSemaphores = NULL;
3887 submit_info[0].pWaitDstStageMask = 0;
3888
3889 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3890 submit_info[1].pNext = NULL;
3891 submit_info[1].commandBufferCount = 1;
3892 submit_info[1].pCommandBuffers = &command_buffer[1];
3893 submit_info[1].waitSemaphoreCount = 1;
3894 submit_info[1].pWaitSemaphores = &semaphore;
3895 submit_info[1].pWaitDstStageMask = flags;
3896 submit_info[1].signalSemaphoreCount = 0;
3897 submit_info[1].pSignalSemaphores = NULL;
3898 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
3899 }
3900
3901 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3902
3903 vkDestroyFence(m_device->device(), fence, nullptr);
3904 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3905 &command_buffer[0]);
3906 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3907
3908 m_errorMonitor->VerifyNotFound();
3909}
3910
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003911TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003912 TEST_DESCRIPTION(
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003913 "Run a simple draw calls to validate failure when Depth Bias dynamic "
3914 "state is required but not correctly bound.");
3915
3916 // Dynamic depth bias
3917 m_errorMonitor->SetDesiredFailureMsg(
3918 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3919 "Dynamic depth bias state not set for this command buffer");
3920 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3921 BsoFailDepthBias);
3922 m_errorMonitor->VerifyFound();
3923}
3924
3925TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
3926 TEST_DESCRIPTION(
3927 "Run a simple draw calls to validate failure when Line Width dynamic "
3928 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003929
3930 // Dynamic line width
Karl Schultz6addd812016-02-02 17:17:23 -07003931 m_errorMonitor->SetDesiredFailureMsg(
3932 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003933 "Dynamic line width state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003934 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3935 BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003936 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003937}
3938
3939TEST_F(VkLayerTest, DynamicViewportNotBound) {
3940 TEST_DESCRIPTION(
3941 "Run a simple draw calls to validate failure when Viewport dynamic "
3942 "state is required but not correctly bound.");
3943
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003944 // Dynamic viewport state
Karl Schultz6addd812016-02-02 17:17:23 -07003945 m_errorMonitor->SetDesiredFailureMsg(
3946 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003947 "Dynamic viewport state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003948 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3949 BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003950 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003951}
3952
3953TEST_F(VkLayerTest, DynamicScissorNotBound) {
3954 TEST_DESCRIPTION(
3955 "Run a simple draw calls to validate failure when Scissor dynamic "
3956 "state is required but not correctly bound.");
3957
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003958 // Dynamic scissor state
Karl Schultz6addd812016-02-02 17:17:23 -07003959 m_errorMonitor->SetDesiredFailureMsg(
3960 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003961 "Dynamic scissor state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003962 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3963 BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003964 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003965}
3966
Tobin Ehlis21c88352016-05-26 06:15:45 -06003967TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) {
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003968 TEST_DESCRIPTION(
Tobin Ehlis21c88352016-05-26 06:15:45 -06003969 "Run a simple draw calls to validate failure when Blend Constants "
3970 "dynamic state is required but not correctly bound.");
3971 // Dynamic blend constant state
3972 m_errorMonitor->SetDesiredFailureMsg(
3973 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3974 "Dynamic blend constants state not set for this command buffer");
3975 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3976 BsoFailBlend);
3977 m_errorMonitor->VerifyFound();
3978}
3979
3980TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
3981 TEST_DESCRIPTION(
3982 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003983 "state is required but not correctly bound.");
Tobin Ehlis21c88352016-05-26 06:15:45 -06003984 if (!m_device->phy().features().depthBounds) {
3985 printf("Device does not support depthBounds test; skipped.\n");
3986 return;
3987 }
3988 // Dynamic depth bounds
Karl Schultz6addd812016-02-02 17:17:23 -07003989 m_errorMonitor->SetDesiredFailureMsg(
3990 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003991 "Dynamic depth bounds state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003992 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3993 BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003994 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003995}
3996
3997TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
3998 TEST_DESCRIPTION(
3999 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4000 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004001 // Dynamic stencil read mask
Karl Schultz6addd812016-02-02 17:17:23 -07004002 m_errorMonitor->SetDesiredFailureMsg(
4003 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004004 "Dynamic stencil read mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004005 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4006 BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004007 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004008}
4009
4010TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
4011 TEST_DESCRIPTION(
4012 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4013 " state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004014 // Dynamic stencil write mask
Karl Schultz6addd812016-02-02 17:17:23 -07004015 m_errorMonitor->SetDesiredFailureMsg(
4016 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004017 "Dynamic stencil write mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004018 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4019 BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004020 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004021}
4022
4023TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
4024 TEST_DESCRIPTION(
4025 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4026 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004027 // Dynamic stencil reference
Karl Schultz6addd812016-02-02 17:17:23 -07004028 m_errorMonitor->SetDesiredFailureMsg(
4029 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004030 "Dynamic stencil reference state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004031 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4032 BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004033 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004034}
4035
Karl Schultz6addd812016-02-02 17:17:23 -07004036TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004037 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004038
Karl Schultz6addd812016-02-02 17:17:23 -07004039 m_errorMonitor->SetDesiredFailureMsg(
4040 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4041 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4042 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004043
4044 VkFenceCreateInfo fenceInfo = {};
4045 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4046 fenceInfo.pNext = NULL;
4047 fenceInfo.flags = 0;
4048
4049 ASSERT_NO_FATAL_FAILURE(InitState());
4050 ASSERT_NO_FATAL_FAILURE(InitViewport());
4051 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4052
Karl Schultz6addd812016-02-02 17:17:23 -07004053 // We luck out b/c by default the framework creates CB w/ the
4054 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004055 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004056 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
4057 m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004058 EndCommandBuffer();
4059
4060 testFence.init(*m_device, fenceInfo);
4061
4062 // Bypass framework since it does the waits automatically
4063 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004064 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004065 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4066 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004067 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004068 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004069 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004070 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004071 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004072 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004073 submit_info.pSignalSemaphores = NULL;
4074
Karl Schultz6addd812016-02-02 17:17:23 -07004075 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
4076 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004077
Karl Schultz6addd812016-02-02 17:17:23 -07004078 // Cause validation error by re-submitting cmd buffer that should only be
4079 // submitted once
4080 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004081
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004082 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004083}
4084
Karl Schultz6addd812016-02-02 17:17:23 -07004085TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004086 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07004087 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004088
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004090 "Unable to allocate 1 descriptors of "
4091 "type "
4092 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004093
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004094 ASSERT_NO_FATAL_FAILURE(InitState());
4095 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004096
Karl Schultz6addd812016-02-02 17:17:23 -07004097 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4098 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004099 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004100 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
4101 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004102
4103 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004104 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4105 ds_pool_ci.pNext = NULL;
4106 ds_pool_ci.flags = 0;
4107 ds_pool_ci.maxSets = 1;
4108 ds_pool_ci.poolSizeCount = 1;
4109 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004110
4111 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004112 err =
4113 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004114 ASSERT_VK_SUCCESS(err);
4115
4116 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004117 dsl_binding.binding = 0;
4118 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4119 dsl_binding.descriptorCount = 1;
4120 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4121 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004122
4123 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004124 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4125 ds_layout_ci.pNext = NULL;
4126 ds_layout_ci.bindingCount = 1;
4127 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004128
4129 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004130 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4131 &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004132 ASSERT_VK_SUCCESS(err);
4133
4134 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004135 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004136 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004137 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004138 alloc_info.descriptorPool = ds_pool;
4139 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004140 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4141 &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004142
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004143 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004144
Chia-I Wuf7458c52015-10-26 21:10:41 +08004145 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4146 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004147}
4148
Karl Schultz6addd812016-02-02 17:17:23 -07004149TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4150 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004151
Karl Schultz6addd812016-02-02 17:17:23 -07004152 m_errorMonitor->SetDesiredFailureMsg(
4153 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4154 "It is invalid to call vkFreeDescriptorSets() with a pool created "
4155 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004156
Tobin Ehlise735c692015-10-08 13:13:50 -06004157 ASSERT_NO_FATAL_FAILURE(InitState());
4158 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004159
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004160 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004161 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4162 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004163
4164 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004165 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4166 ds_pool_ci.pNext = NULL;
4167 ds_pool_ci.maxSets = 1;
4168 ds_pool_ci.poolSizeCount = 1;
4169 ds_pool_ci.flags = 0;
4170 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4171 // app can only call vkResetDescriptorPool on this pool.;
4172 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004173
4174 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004175 err =
4176 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004177 ASSERT_VK_SUCCESS(err);
4178
4179 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004180 dsl_binding.binding = 0;
4181 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4182 dsl_binding.descriptorCount = 1;
4183 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4184 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004185
4186 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004187 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4188 ds_layout_ci.pNext = NULL;
4189 ds_layout_ci.bindingCount = 1;
4190 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004191
4192 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004193 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4194 &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004195 ASSERT_VK_SUCCESS(err);
4196
4197 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004198 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004199 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004200 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004201 alloc_info.descriptorPool = ds_pool;
4202 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004203 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4204 &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004205 ASSERT_VK_SUCCESS(err);
4206
4207 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004208 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004209
Chia-I Wuf7458c52015-10-26 21:10:41 +08004210 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4211 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004212}
4213
Karl Schultz6addd812016-02-02 17:17:23 -07004214TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004215 // Attempt to clear Descriptor Pool with bad object.
4216 // ObjectTracker should catch this.
4217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4218 "Invalid VkDescriptorPool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004219 uint64_t fake_pool_handle = 0xbaad6001;
4220 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4221 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004222 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004223}
4224
Karl Schultz6addd812016-02-02 17:17:23 -07004225TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004226 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4227 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004228 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004229 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004230
4231 uint64_t fake_set_handle = 0xbaad6001;
4232 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004233 VkResult err;
4234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4235 "Invalid VkDescriptorSet Object 0xbaad6001");
4236
4237 ASSERT_NO_FATAL_FAILURE(InitState());
4238
4239 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4240 layout_bindings[0].binding = 0;
4241 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4242 layout_bindings[0].descriptorCount = 1;
4243 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4244 layout_bindings[0].pImmutableSamplers = NULL;
4245
4246 VkDescriptorSetLayout descriptor_set_layout;
4247 VkDescriptorSetLayoutCreateInfo dslci = {};
4248 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4249 dslci.pNext = NULL;
4250 dslci.bindingCount = 1;
4251 dslci.pBindings = layout_bindings;
4252 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004253 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004254
4255 VkPipelineLayout pipeline_layout;
4256 VkPipelineLayoutCreateInfo plci = {};
4257 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4258 plci.pNext = NULL;
4259 plci.setLayoutCount = 1;
4260 plci.pSetLayouts = &descriptor_set_layout;
4261 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004262 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004263
4264 BeginCommandBuffer();
4265 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004266 pipeline_layout, 0, 1, &bad_set, 0, NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004267 m_errorMonitor->VerifyFound();
4268 EndCommandBuffer();
4269 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4270 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004271}
4272
Karl Schultz6addd812016-02-02 17:17:23 -07004273TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004274 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4275 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004276 uint64_t fake_layout_handle = 0xbaad6001;
4277 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4279 "Invalid VkDescriptorSetLayout Object 0xbaad6001");
4280
4281 VkPipelineLayout pipeline_layout;
4282 VkPipelineLayoutCreateInfo plci = {};
4283 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4284 plci.pNext = NULL;
4285 plci.setLayoutCount = 1;
4286 plci.pSetLayouts = &bad_layout;
4287 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4288
4289 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004290}
4291
Karl Schultz6addd812016-02-02 17:17:23 -07004292TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004293 // Attempt to bind an invalid Pipeline to a valid Command Buffer
4294 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004295 // Create a valid cmd buffer
4296 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004297 uint64_t fake_pipeline_handle = 0xbaad6001;
4298 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4300 "Invalid VkPipeline Object 0xbaad6001");
4301 ASSERT_NO_FATAL_FAILURE(InitState());
4302 BeginCommandBuffer();
4303 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4304 VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
4305 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004306
4307 // Now issue a draw call with no pipeline bound
4308 m_errorMonitor->SetDesiredFailureMsg(
4309 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4310 "At Draw/Dispatch time no valid VkPipeline is bound!");
4311 ASSERT_NO_FATAL_FAILURE(InitState());
4312 BeginCommandBuffer();
4313 Draw(1, 0, 0, 0);
4314 m_errorMonitor->VerifyFound();
4315 // Finally same check once more but with Dispatch/Compute
4316 m_errorMonitor->SetDesiredFailureMsg(
4317 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4318 "At Draw/Dispatch time no valid VkPipeline is bound!");
4319 ASSERT_NO_FATAL_FAILURE(InitState());
4320 BeginCommandBuffer();
4321 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
4322 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004323}
4324
Karl Schultz6addd812016-02-02 17:17:23 -07004325TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
4326 // Create and update CommandBuffer then call QueueSubmit w/o calling End on
4327 // CommandBuffer
4328 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004329
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07004330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004331 " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004332
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004333 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06004334 ASSERT_NO_FATAL_FAILURE(InitViewport());
4335 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004336 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004337 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4338 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004339
4340 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004341 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4342 ds_pool_ci.pNext = NULL;
4343 ds_pool_ci.maxSets = 1;
4344 ds_pool_ci.poolSizeCount = 1;
4345 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06004346
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004347 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004348 err =
4349 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004350 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004351
Tony Barboureb254902015-07-15 12:50:33 -06004352 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004353 dsl_binding.binding = 0;
4354 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4355 dsl_binding.descriptorCount = 1;
4356 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4357 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004358
Tony Barboureb254902015-07-15 12:50:33 -06004359 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004360 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4361 ds_layout_ci.pNext = NULL;
4362 ds_layout_ci.bindingCount = 1;
4363 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004364 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004365 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4366 &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004367 ASSERT_VK_SUCCESS(err);
4368
4369 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004370 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004371 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004372 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004373 alloc_info.descriptorPool = ds_pool;
4374 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004375 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4376 &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004377 ASSERT_VK_SUCCESS(err);
4378
Tony Barboureb254902015-07-15 12:50:33 -06004379 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004380 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4381 pipeline_layout_ci.pNext = NULL;
4382 pipeline_layout_ci.setLayoutCount = 1;
4383 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004384
4385 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004386 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4387 &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004388 ASSERT_VK_SUCCESS(err);
4389
Karl Schultz6addd812016-02-02 17:17:23 -07004390 VkShaderObj vs(m_device, bindStateVertShaderText,
4391 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06004392 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07004393 // on more devices
4394 VkShaderObj fs(m_device, bindStateFragShaderText,
4395 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004396
Tony Barbourc95e4ac2015-08-04 17:05:26 -06004397 VkPipelineObj pipe(m_device);
4398 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06004399 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06004400 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06004401 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004402
4403 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004404 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4405 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4406 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4407 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4408 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004409
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004410 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06004411
Chia-I Wuf7458c52015-10-26 21:10:41 +08004412 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4413 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4414 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004415}
4416
Karl Schultz6addd812016-02-02 17:17:23 -07004417TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004418 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07004419 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004420
Karl Schultz6addd812016-02-02 17:17:23 -07004421 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004422 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
4423 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004424
4425 ASSERT_NO_FATAL_FAILURE(InitState());
4426 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004427 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
4428 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004429
4430 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004431 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4432 ds_pool_ci.pNext = NULL;
4433 ds_pool_ci.maxSets = 1;
4434 ds_pool_ci.poolSizeCount = 1;
4435 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004436
4437 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004438 err =
4439 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004440 ASSERT_VK_SUCCESS(err);
4441
4442 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004443 dsl_binding.binding = 0;
4444 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
4445 dsl_binding.descriptorCount = 1;
4446 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4447 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004448
4449 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004450 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4451 ds_layout_ci.pNext = NULL;
4452 ds_layout_ci.bindingCount = 1;
4453 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004454 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004455 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4456 &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004457 ASSERT_VK_SUCCESS(err);
4458
4459 VkDescriptorSet descriptorSet;
4460 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004461 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004462 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004463 alloc_info.descriptorPool = ds_pool;
4464 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004465 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4466 &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004467 ASSERT_VK_SUCCESS(err);
4468
Karl Schultz6addd812016-02-02 17:17:23 -07004469 VkBufferView view =
4470 (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004471 VkWriteDescriptorSet descriptor_write;
4472 memset(&descriptor_write, 0, sizeof(descriptor_write));
4473 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4474 descriptor_write.dstSet = descriptorSet;
4475 descriptor_write.dstBinding = 0;
4476 descriptor_write.descriptorCount = 1;
4477 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
4478 descriptor_write.pTexelBufferView = &view;
4479
4480 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4481
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004482 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004483
4484 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4485 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4486}
4487
Karl Schultz6addd812016-02-02 17:17:23 -07004488TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
4489 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
4490 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07004491 // 1. No dynamicOffset supplied
4492 // 2. Too many dynamicOffsets supplied
4493 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07004494 VkResult err;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004496 " requires 1 dynamicOffsets, but only "
4497 "0 dynamicOffsets are left in "
4498 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004499
4500 ASSERT_NO_FATAL_FAILURE(InitState());
4501 ASSERT_NO_FATAL_FAILURE(InitViewport());
4502 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4503
4504 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004505 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
4506 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004507
4508 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004509 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4510 ds_pool_ci.pNext = NULL;
4511 ds_pool_ci.maxSets = 1;
4512 ds_pool_ci.poolSizeCount = 1;
4513 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004514
4515 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004516 err =
4517 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004518 ASSERT_VK_SUCCESS(err);
4519
4520 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004521 dsl_binding.binding = 0;
4522 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
4523 dsl_binding.descriptorCount = 1;
4524 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4525 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004526
4527 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004528 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4529 ds_layout_ci.pNext = NULL;
4530 ds_layout_ci.bindingCount = 1;
4531 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004532 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004533 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4534 &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004535 ASSERT_VK_SUCCESS(err);
4536
4537 VkDescriptorSet descriptorSet;
4538 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004539 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004540 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004541 alloc_info.descriptorPool = ds_pool;
4542 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004543 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4544 &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004545 ASSERT_VK_SUCCESS(err);
4546
4547 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004548 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4549 pipeline_layout_ci.pNext = NULL;
4550 pipeline_layout_ci.setLayoutCount = 1;
4551 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004552
4553 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004554 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4555 &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004556 ASSERT_VK_SUCCESS(err);
4557
4558 // Create a buffer to update the descriptor with
4559 uint32_t qfi = 0;
4560 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004561 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4562 buffCI.size = 1024;
4563 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4564 buffCI.queueFamilyIndexCount = 1;
4565 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004566
4567 VkBuffer dyub;
4568 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4569 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004570 // Allocate memory and bind to buffer so we can make it to the appropriate
4571 // error
4572 VkMemoryAllocateInfo mem_alloc = {};
4573 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4574 mem_alloc.pNext = NULL;
4575 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12004576 mem_alloc.memoryTypeIndex = 0;
4577
4578 VkMemoryRequirements memReqs;
4579 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
4580 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc,
4581 0);
4582 if (!pass) {
4583 vkDestroyBuffer(m_device->device(), dyub, NULL);
4584 return;
4585 }
4586
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004587 VkDeviceMemory mem;
4588 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4589 ASSERT_VK_SUCCESS(err);
4590 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4591 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004592 // Correctly update descriptor to avoid "NOT_UPDATED" error
4593 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004594 buffInfo.buffer = dyub;
4595 buffInfo.offset = 0;
4596 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004597
4598 VkWriteDescriptorSet descriptor_write;
4599 memset(&descriptor_write, 0, sizeof(descriptor_write));
4600 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4601 descriptor_write.dstSet = descriptorSet;
4602 descriptor_write.dstBinding = 0;
4603 descriptor_write.descriptorCount = 1;
4604 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
4605 descriptor_write.pBufferInfo = &buffInfo;
4606
4607 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4608
4609 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004610 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4611 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4612 1, &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004613 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07004614 uint32_t pDynOff[2] = {512, 756};
4615 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Karl Schultz6addd812016-02-02 17:17:23 -07004616 m_errorMonitor->SetDesiredFailureMsg(
4617 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07004618 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
Karl Schultz6addd812016-02-02 17:17:23 -07004619 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4620 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4621 1, &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12004622 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07004623 // Finally cause error due to dynamicOffset being too big
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4625 " dynamic offset 512 combined with "
4626 "offset 0 and range 1024 that "
4627 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07004628 // Create PSO to be used for draw-time errors below
4629 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12004630 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07004631 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07004632 "out gl_PerVertex { \n"
4633 " vec4 gl_Position;\n"
4634 "};\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07004635 "void main(){\n"
4636 " gl_Position = vec4(1);\n"
4637 "}\n";
4638 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12004639 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07004640 "\n"
4641 "layout(location=0) out vec4 x;\n"
4642 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4643 "void main(){\n"
4644 " x = vec4(bar.y);\n"
4645 "}\n";
4646 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4647 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4648 VkPipelineObj pipe(m_device);
4649 pipe.AddShader(&vs);
4650 pipe.AddShader(&fs);
4651 pipe.AddColorAttachment();
4652 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4653
Karl Schultz6addd812016-02-02 17:17:23 -07004654 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4655 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4656 // This update should succeed, but offset size of 512 will overstep buffer
4657 // /w range 1024 & size 1024
4658 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4659 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4660 1, &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004661 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004662 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004663
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004664 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06004665 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004666
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004667 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4668 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4669}
4670
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004671TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004672 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004673 ASSERT_NO_FATAL_FAILURE(InitState());
4674 ASSERT_NO_FATAL_FAILURE(InitViewport());
4675 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4676
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004677 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004678 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004679 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4680 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4681 pipeline_layout_ci.pushConstantRangeCount = 1;
4682 pipeline_layout_ci.pPushConstantRanges = &pc_range;
4683
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004684 //
4685 // Check for invalid push constant ranges in pipeline layouts.
4686 //
4687 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06004688 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004689 char const *msg;
4690 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004691
Karl Schultzc81037d2016-05-12 08:11:23 -06004692 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
4693 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
4694 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
4695 "vkCreatePipelineLayout() call has push constants index 0 with "
4696 "size 0."},
4697 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
4698 "vkCreatePipelineLayout() call has push constants index 0 with "
4699 "size 1."},
4700 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
4701 "vkCreatePipelineLayout() call has push constants index 0 with "
4702 "size 1."},
4703 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
4704 "vkCreatePipelineLayout() call has push constants index 0 with "
4705 "size 0."},
4706 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
4707 "vkCreatePipelineLayout() call has push constants index 0 with "
4708 "offset 1. Offset must"},
4709 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
4710 "vkCreatePipelineLayout() call has push constants index 0 "
4711 "with offset "},
4712 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
4713 "vkCreatePipelineLayout() call has push constants "
4714 "index 0 with offset "},
4715 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
4716 "vkCreatePipelineLayout() call has push constants index 0 "
4717 "with offset "},
4718 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
4719 "vkCreatePipelineLayout() call has push "
4720 "constants index 0 with offset "},
4721 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
4722 "vkCreatePipelineLayout() call has push "
4723 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004724 }};
4725
4726 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06004727 for (const auto &iter : range_tests) {
4728 pc_range = iter.range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4730 iter.msg);
4731 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
4732 NULL, &pipeline_layout);
4733 m_errorMonitor->VerifyFound();
4734 if (VK_SUCCESS == err) {
4735 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4736 }
4737 }
4738
4739 // Check for invalid stage flag
4740 pc_range.offset = 0;
4741 pc_range.size = 16;
4742 pc_range.stageFlags = 0;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004743 m_errorMonitor->SetDesiredFailureMsg(
4744 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004745 "vkCreatePipelineLayout() call has no stageFlags set.");
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004746 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4747 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004748 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004749 if (VK_SUCCESS == err) {
4750 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4751 }
4752
4753 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06004754 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004755 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06004756 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004757 char const *msg;
4758 };
4759
Karl Schultzc81037d2016-05-12 08:11:23 -06004760 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004761 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4762 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4763 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4764 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4765 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4766 "vkCreatePipelineLayout() call has push constants with overlapping "
4767 "ranges: 0:[0, 4), 1:[0, 4)"},
4768 {
4769 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4770 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4771 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4772 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
4773 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
4774 "vkCreatePipelineLayout() call has push constants with "
4775 "overlapping "
4776 "ranges: 3:[12, 20), 4:[16, 20)",
4777 },
4778 {
4779 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4780 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
4781 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4782 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4783 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4784 "vkCreatePipelineLayout() call has push constants with "
4785 "overlapping "
4786 "ranges: 0:[16, 20), 1:[12, 20)",
4787 },
4788 {
4789 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4790 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4791 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4792 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
4793 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4794 "vkCreatePipelineLayout() call has push constants with "
4795 "overlapping "
4796 "ranges: 0:[16, 20), 3:[12, 20)",
4797 },
4798 {
4799 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4800 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
4801 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
4802 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
4803 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
4804 "vkCreatePipelineLayout() call has push constants with "
4805 "overlapping "
4806 "ranges: 0:[16, 20), 2:[4, 100)",
4807 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004808
Karl Schultzc81037d2016-05-12 08:11:23 -06004809 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004810 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06004811 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
4812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004813 iter.msg);
4814 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
4815 NULL, &pipeline_layout);
4816 m_errorMonitor->VerifyFound();
4817 if (VK_SUCCESS == err) {
4818 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4819 }
4820 }
4821
4822 // Run some positive tests to make sure overlap checking in the layer is OK
Karl Schultzc81037d2016-05-12 08:11:23 -06004823 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos =
4824 {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4825 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4826 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4827 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
4828 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
4829 ""},
4830 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
4831 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
4832 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
4833 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
4834 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4835 ""}}};
4836 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004837 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
4838 m_errorMonitor->ExpectSuccess();
4839 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
4840 NULL, &pipeline_layout);
4841 m_errorMonitor->VerifyNotFound();
4842 if (VK_SUCCESS == err) {
4843 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4844 }
4845 }
4846
4847 //
4848 // CmdPushConstants tests
4849 //
Karl Schultzc81037d2016-05-12 08:11:23 -06004850 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004851
4852 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzc81037d2016-05-12 08:11:23 -06004853 const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{
4854 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
4855 "vkCmdPushConstants() call has push constants with size 0. Size "
4856 "must be greater than zero and a multiple of 4."},
4857 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
4858 "vkCmdPushConstants() call has push constants with size 1. Size "
4859 "must be greater than zero and a multiple of 4."},
4860 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
4861 "vkCmdPushConstants() call has push constants with size 1. Size "
4862 "must be greater than zero and a multiple of 4."},
4863 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
4864 "vkCmdPushConstants() call has push constants with offset 1. "
4865 "Offset must be a multiple of 4."},
4866 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
4867 "vkCmdPushConstants() call has push constants with offset 1. "
4868 "Offset must be a multiple of 4."},
4869 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
4870 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
4871 "0x1 not within flag-matching ranges in pipeline layout"},
4872 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
4873 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
4874 "0x1 not within flag-matching ranges in pipeline layout"},
4875 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
4876 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
4877 "0x1 not within flag-matching ranges in pipeline layout"},
4878 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
4879 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
4880 "0x1 not within flag-matching ranges in pipeline layout"},
4881 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
4882 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
4883 "any of the ranges in pipeline layout"},
4884 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
4885 0, 16},
4886 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
4887 "any of the ranges in pipeline layout"},
4888 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004889 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004890 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004891 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004892 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004893 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004894 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004895 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004896 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004897 "vkCmdPushConstants() call has push constants with offset "},
4898 }};
4899
4900 // Two ranges for testing robustness
Karl Schultzc81037d2016-05-12 08:11:23 -06004901 const VkPushConstantRange pc_range2[] = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004902 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06004903 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004904 };
Karl Schultzc81037d2016-05-12 08:11:23 -06004905 pipeline_layout_ci.pushConstantRangeCount =
4906 sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004907 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004908 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4909 &pipeline_layout);
4910 ASSERT_VK_SUCCESS(err);
4911 BeginCommandBuffer();
Karl Schultzc81037d2016-05-12 08:11:23 -06004912 for (const auto &iter : cmd_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4914 iter.msg);
4915 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
Karl Schultzc81037d2016-05-12 08:11:23 -06004916 iter.range.stageFlags, iter.range.offset,
4917 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004918 m_errorMonitor->VerifyFound();
4919 }
4920
4921 // Check for invalid stage flag
4922 m_errorMonitor->SetDesiredFailureMsg(
4923 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4924 "vkCmdPushConstants() call has no stageFlags set.");
4925 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0,
Karl Schultzc81037d2016-05-12 08:11:23 -06004926 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004927 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06004928 EndCommandBuffer();
4929 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
4930 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004931
Karl Schultzc81037d2016-05-12 08:11:23 -06004932 // overlapping range tests with cmd
4933 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
4934 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
4935 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
4936 "0x1 not within flag-matching ranges in pipeline layout"},
4937 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4938 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
4939 "0x1 not within flag-matching ranges in pipeline layout"},
4940 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
4941 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
4942 "0x1 not within flag-matching ranges in pipeline layout"},
4943 }};
4944 const VkPushConstantRange pc_range3[] = {
4945 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
4946 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
4947 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4948 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
4949 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
4950 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
4951 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
4952 };
4953 pipeline_layout_ci.pushConstantRangeCount =
4954 sizeof(pc_range3) / sizeof(VkPushConstantRange);
4955 pipeline_layout_ci.pPushConstantRanges = pc_range3;
4956 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4957 &pipeline_layout);
4958 ASSERT_VK_SUCCESS(err);
4959 BeginCommandBuffer();
4960 for (const auto &iter : cmd_overlap_tests) {
4961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4962 iter.msg);
4963 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
4964 iter.range.stageFlags, iter.range.offset,
4965 iter.range.size, dummy_values);
4966 m_errorMonitor->VerifyFound();
4967 }
4968 EndCommandBuffer();
4969 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
4970 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4971
4972 // positive overlapping range tests with cmd
4973 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
4974 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
4975 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
4976 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
4977 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
4978 }};
4979 const VkPushConstantRange pc_range4[] = {
4980 {VK_SHADER_STAGE_VERTEX_BIT, 0, 64},
4981 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
4982 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
4983 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4984 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
4985 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
4986 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
4987 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
4988 };
4989 pipeline_layout_ci.pushConstantRangeCount =
4990 sizeof(pc_range4) / sizeof(VkPushConstantRange);
4991 pipeline_layout_ci.pPushConstantRanges = pc_range4;
4992 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4993 &pipeline_layout);
4994 ASSERT_VK_SUCCESS(err);
4995 BeginCommandBuffer();
4996 for (const auto &iter : cmd_overlap_tests_pos) {
4997 m_errorMonitor->ExpectSuccess();
4998 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
4999 iter.range.stageFlags, iter.range.offset,
5000 iter.range.size, dummy_values);
5001 m_errorMonitor->VerifyNotFound();
5002 }
5003 EndCommandBuffer();
5004 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005005 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5006}
5007
Karl Schultz6addd812016-02-02 17:17:23 -07005008TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005009 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07005010 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005011
5012 ASSERT_NO_FATAL_FAILURE(InitState());
5013 ASSERT_NO_FATAL_FAILURE(InitViewport());
5014 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5015
5016 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
5017 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005018 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5019 ds_type_count[0].descriptorCount = 10;
5020 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5021 ds_type_count[1].descriptorCount = 2;
5022 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5023 ds_type_count[2].descriptorCount = 2;
5024 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
5025 ds_type_count[3].descriptorCount = 5;
5026 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
5027 // type
5028 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
5029 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
5030 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005031
5032 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005033 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5034 ds_pool_ci.pNext = NULL;
5035 ds_pool_ci.maxSets = 5;
5036 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
5037 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005038
5039 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005040 err =
5041 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005042 ASSERT_VK_SUCCESS(err);
5043
5044 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
5045 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005046 dsl_binding[0].binding = 0;
5047 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5048 dsl_binding[0].descriptorCount = 5;
5049 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
5050 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005051
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005052 // Create layout identical to set0 layout but w/ different stageFlags
5053 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005054 dsl_fs_stage_only.binding = 0;
5055 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5056 dsl_fs_stage_only.descriptorCount = 5;
5057 dsl_fs_stage_only.stageFlags =
5058 VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
5059 // bind time
5060 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005061 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005062 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5063 ds_layout_ci.pNext = NULL;
5064 ds_layout_ci.bindingCount = 1;
5065 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005066 static const uint32_t NUM_LAYOUTS = 4;
5067 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005068 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005069 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
5070 // layout for error case
5071 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5072 &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005073 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005074 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005075 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5076 &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005077 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005078 dsl_binding[0].binding = 0;
5079 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005080 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005081 dsl_binding[1].binding = 1;
5082 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5083 dsl_binding[1].descriptorCount = 2;
5084 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
5085 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005086 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005087 ds_layout_ci.bindingCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005088 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5089 &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005090 ASSERT_VK_SUCCESS(err);
5091 dsl_binding[0].binding = 0;
5092 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005093 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005094 ds_layout_ci.bindingCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07005095 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5096 &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005097 ASSERT_VK_SUCCESS(err);
5098 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005099 dsl_binding[0].descriptorCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005100 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5101 &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005102 ASSERT_VK_SUCCESS(err);
5103
5104 static const uint32_t NUM_SETS = 4;
5105 VkDescriptorSet descriptorSet[NUM_SETS] = {};
5106 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005107 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005108 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005109 alloc_info.descriptorPool = ds_pool;
5110 alloc_info.pSetLayouts = ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005111 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5112 descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005113 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005114 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005115 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005116 alloc_info.pSetLayouts = &ds_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005117 err =
5118 vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005119 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005120
5121 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005122 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5123 pipeline_layout_ci.pNext = NULL;
5124 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
5125 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005126
5127 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005128 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5129 &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005130 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005131 // Create pipelineLayout with only one setLayout
5132 pipeline_layout_ci.setLayoutCount = 1;
5133 VkPipelineLayout single_pipe_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005134 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5135 &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005136 ASSERT_VK_SUCCESS(err);
5137 // Create pipelineLayout with 2 descriptor setLayout at index 0
5138 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
5139 VkPipelineLayout pipe_layout_one_desc;
Karl Schultz6addd812016-02-02 17:17:23 -07005140 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5141 &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005142 ASSERT_VK_SUCCESS(err);
5143 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
5144 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
5145 VkPipelineLayout pipe_layout_five_samp;
Karl Schultz6addd812016-02-02 17:17:23 -07005146 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5147 &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005148 ASSERT_VK_SUCCESS(err);
5149 // Create pipelineLayout with UB type, but stageFlags for FS only
5150 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
5151 VkPipelineLayout pipe_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005152 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5153 &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005154 ASSERT_VK_SUCCESS(err);
5155 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
5156 VkDescriptorSetLayout pl_bad_s0[2] = {};
5157 pl_bad_s0[0] = ds_layout_fs_only;
5158 pl_bad_s0[1] = ds_layout[1];
5159 pipeline_layout_ci.setLayoutCount = 2;
5160 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
5161 VkPipelineLayout pipe_layout_bad_set0;
Karl Schultz6addd812016-02-02 17:17:23 -07005162 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5163 &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005164 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005165
5166 // Create a buffer to update the descriptor with
5167 uint32_t qfi = 0;
5168 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005169 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5170 buffCI.size = 1024;
5171 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5172 buffCI.queueFamilyIndexCount = 1;
5173 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005174
5175 VkBuffer dyub;
5176 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5177 ASSERT_VK_SUCCESS(err);
5178 // Correctly update descriptor to avoid "NOT_UPDATED" error
5179 static const uint32_t NUM_BUFFS = 5;
5180 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005181 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005182 buffInfo[i].buffer = dyub;
5183 buffInfo[i].offset = 0;
5184 buffInfo[i].range = 1024;
5185 }
Karl Schultz6addd812016-02-02 17:17:23 -07005186 VkImage image;
5187 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5188 const int32_t tex_width = 32;
5189 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005190 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005191 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5192 image_create_info.pNext = NULL;
5193 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5194 image_create_info.format = tex_format;
5195 image_create_info.extent.width = tex_width;
5196 image_create_info.extent.height = tex_height;
5197 image_create_info.extent.depth = 1;
5198 image_create_info.mipLevels = 1;
5199 image_create_info.arrayLayers = 1;
5200 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5201 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5202 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5203 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005204 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5205 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005206
Karl Schultz6addd812016-02-02 17:17:23 -07005207 VkMemoryRequirements memReqs;
5208 VkDeviceMemory imageMem;
5209 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005210 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005211 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5212 memAlloc.pNext = NULL;
5213 memAlloc.allocationSize = 0;
5214 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005215 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
5216 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07005217 pass =
5218 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005219 ASSERT_TRUE(pass);
5220 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
5221 ASSERT_VK_SUCCESS(err);
5222 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
5223 ASSERT_VK_SUCCESS(err);
5224
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005225 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005226 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5227 image_view_create_info.image = image;
5228 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5229 image_view_create_info.format = tex_format;
5230 image_view_create_info.subresourceRange.layerCount = 1;
5231 image_view_create_info.subresourceRange.baseMipLevel = 0;
5232 image_view_create_info.subresourceRange.levelCount = 1;
5233 image_view_create_info.subresourceRange.aspectMask =
5234 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005235
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005236 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07005237 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
5238 &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005239 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005240 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005241 imageInfo[0].imageView = view;
5242 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5243 imageInfo[1].imageView = view;
5244 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005245 imageInfo[2].imageView = view;
5246 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5247 imageInfo[3].imageView = view;
5248 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005249
5250 static const uint32_t NUM_SET_UPDATES = 3;
5251 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
5252 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5253 descriptor_write[0].dstSet = descriptorSet[0];
5254 descriptor_write[0].dstBinding = 0;
5255 descriptor_write[0].descriptorCount = 5;
5256 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5257 descriptor_write[0].pBufferInfo = buffInfo;
5258 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5259 descriptor_write[1].dstSet = descriptorSet[1];
5260 descriptor_write[1].dstBinding = 0;
5261 descriptor_write[1].descriptorCount = 2;
5262 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5263 descriptor_write[1].pImageInfo = imageInfo;
5264 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5265 descriptor_write[2].dstSet = descriptorSet[1];
5266 descriptor_write[2].dstBinding = 1;
5267 descriptor_write[2].descriptorCount = 2;
5268 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005269 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005270
5271 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005272
Tobin Ehlis88452832015-12-03 09:40:56 -07005273 // Create PSO to be used for draw-time errors below
5274 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005275 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005276 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005277 "out gl_PerVertex {\n"
5278 " vec4 gl_Position;\n"
5279 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005280 "void main(){\n"
5281 " gl_Position = vec4(1);\n"
5282 "}\n";
5283 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005284 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005285 "\n"
5286 "layout(location=0) out vec4 x;\n"
5287 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5288 "void main(){\n"
5289 " x = vec4(bar.y);\n"
5290 "}\n";
5291 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5292 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005293 VkPipelineObj pipe(m_device);
5294 pipe.AddShader(&vs);
5295 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07005296 pipe.AddColorAttachment();
5297 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07005298
5299 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07005300
Karl Schultz6addd812016-02-02 17:17:23 -07005301 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5302 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5303 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
5304 // of PSO
5305 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
5306 // cmd_pipeline.c
5307 // due to the fact that cmd_alloc_dset_data() has not been called in
5308 // cmd_bind_graphics_pipeline()
5309 // TODO : Want to cause various binding incompatibility issues here to test
5310 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07005311 // First cause various verify_layout_compatibility() fails
5312 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005313 // verify_set_layout_compatibility fail cases:
5314 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultz6addd812016-02-02 17:17:23 -07005315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5316 " due to: invalid VkPipelineLayout ");
5317 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5318 VK_PIPELINE_BIND_POINT_GRAPHICS,
5319 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1,
5320 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005321 m_errorMonitor->VerifyFound();
5322
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005323 // 2. layoutIndex exceeds # of layouts in layout
Karl Schultz6addd812016-02-02 17:17:23 -07005324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5325 " attempting to bind set to index 1");
5326 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5327 VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout,
5328 0, 2, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005329 m_errorMonitor->VerifyFound();
5330
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005331 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005332 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
5333 // descriptors
5334 m_errorMonitor->SetDesiredFailureMsg(
5335 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005336 " has 2 descriptors, but DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005337 vkCmdBindDescriptorSets(
5338 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5339 pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005340 m_errorMonitor->VerifyFound();
5341
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005342 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
5343 // 4. same # of descriptors but mismatch in type
Karl Schultz6addd812016-02-02 17:17:23 -07005344 m_errorMonitor->SetDesiredFailureMsg(
5345 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005346 " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
Karl Schultz6addd812016-02-02 17:17:23 -07005347 vkCmdBindDescriptorSets(
5348 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5349 pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005350 m_errorMonitor->VerifyFound();
5351
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005352 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
5353 // 5. same # of descriptors but mismatch in stageFlags
Karl Schultz6addd812016-02-02 17:17:23 -07005354 m_errorMonitor->SetDesiredFailureMsg(
5355 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005356 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005357 vkCmdBindDescriptorSets(
5358 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5359 pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005360 m_errorMonitor->VerifyFound();
5361
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005362 // Cause INFO messages due to disturbing previously bound Sets
5363 // First bind sets 0 & 1
Karl Schultz6addd812016-02-02 17:17:23 -07005364 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5365 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5366 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005367 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Karl Schultz6addd812016-02-02 17:17:23 -07005368 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07005369 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005370 " previously bound as set #0 was disturbed ");
5371 vkCmdBindDescriptorSets(
5372 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5373 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005374 m_errorMonitor->VerifyFound();
5375
Karl Schultz6addd812016-02-02 17:17:23 -07005376 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5377 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5378 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005379 // 2. Disturb set after last bound set
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07005380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005381 " newly bound as set #0 so set #1 and "
5382 "any subsequent sets were disturbed ");
5383 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5384 VK_PIPELINE_BIND_POINT_GRAPHICS,
5385 pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005386 m_errorMonitor->VerifyFound();
5387
Tobin Ehlis88452832015-12-03 09:40:56 -07005388 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07005389 // 1. Error due to not binding required set (we actually use same code as
5390 // above to disturb set0)
5391 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5392 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5393 2, &descriptorSet[0], 0, NULL);
5394 vkCmdBindDescriptorSets(
5395 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5396 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
5397 m_errorMonitor->SetDesiredFailureMsg(
5398 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5399 " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07005400 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005401 m_errorMonitor->VerifyFound();
5402
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005403 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005404 // 2. Error due to bound set not being compatible with PSO's
5405 // VkPipelineLayout (diff stageFlags in this case)
5406 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5407 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5408 2, &descriptorSet[0], 0, NULL);
5409 m_errorMonitor->SetDesiredFailureMsg(
5410 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5411 " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07005412 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005413 m_errorMonitor->VerifyFound();
5414
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005415 // Remaining clean-up
5416 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005417 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005418 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
5419 }
5420 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06005421 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
5422 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005423 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005424 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5425 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5426}
Tobin Ehlis559c6382015-11-05 09:52:49 -07005427
Karl Schultz6addd812016-02-02 17:17:23 -07005428TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005429
Karl Schultz6addd812016-02-02 17:17:23 -07005430 m_errorMonitor->SetDesiredFailureMsg(
5431 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005432 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005433
5434 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005435 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005436 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005437 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005438
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005439 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005440}
5441
Karl Schultz6addd812016-02-02 17:17:23 -07005442TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
5443 VkResult err;
5444 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005445
Karl Schultz6addd812016-02-02 17:17:23 -07005446 m_errorMonitor->SetDesiredFailureMsg(
5447 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005448 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005449
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005450 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005451
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005452 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005453 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06005454 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005455 cmd.commandPool = m_commandPool;
5456 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005457 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06005458
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005459 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06005460 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005461
5462 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005463 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005464 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005465 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06005466 cmd_buf_info.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07005467 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
5468 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005469 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005470
5471 // The error should be caught by validation of the BeginCommandBuffer call
5472 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
5473
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005474 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005475 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005476}
5477
Karl Schultz6addd812016-02-02 17:17:23 -07005478TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005479 // Cause error due to Begin while recording CB
5480 // Then cause 2 errors for attempting to reset CB w/o having
5481 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
5482 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005484 "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005485
5486 ASSERT_NO_FATAL_FAILURE(InitState());
5487
5488 // Calls AllocateCommandBuffers
5489 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
5490
Karl Schultz6addd812016-02-02 17:17:23 -07005491 // Force the failure by setting the Renderpass and Framebuffer fields with
5492 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005493 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005494 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005495 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5496 cmd_buf_info.pNext = NULL;
5497 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005498 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005499
5500 // Begin CB to transition to recording state
5501 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
5502 // Can't re-begin. This should trigger error
5503 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005504 m_errorMonitor->VerifyFound();
5505
Karl Schultz6addd812016-02-02 17:17:23 -07005506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5507 "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005508 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
5509 // Reset attempt will trigger error due to incorrect CommandPool state
5510 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005511 m_errorMonitor->VerifyFound();
5512
Karl Schultz6addd812016-02-02 17:17:23 -07005513 m_errorMonitor->SetDesiredFailureMsg(
5514 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5515 " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005516 // Transition CB to RECORDED state
5517 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
5518 // Now attempting to Begin will implicitly reset, which triggers error
5519 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005520 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005521}
5522
Karl Schultz6addd812016-02-02 17:17:23 -07005523TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005524 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07005525 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005526
Karl Schultz6addd812016-02-02 17:17:23 -07005527 m_errorMonitor->SetDesiredFailureMsg(
5528 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005529 "Invalid Pipeline CreateInfo State: Vtx Shader required");
5530
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005531 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06005532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005533
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005534 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005535 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5536 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005537
5538 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005539 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5540 ds_pool_ci.pNext = NULL;
5541 ds_pool_ci.maxSets = 1;
5542 ds_pool_ci.poolSizeCount = 1;
5543 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005544
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005545 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005546 err =
5547 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005548 ASSERT_VK_SUCCESS(err);
5549
Tony Barboureb254902015-07-15 12:50:33 -06005550 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005551 dsl_binding.binding = 0;
5552 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5553 dsl_binding.descriptorCount = 1;
5554 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5555 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005556
Tony Barboureb254902015-07-15 12:50:33 -06005557 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005558 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5559 ds_layout_ci.pNext = NULL;
5560 ds_layout_ci.bindingCount = 1;
5561 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06005562
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005563 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005564 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5565 &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005566 ASSERT_VK_SUCCESS(err);
5567
5568 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005569 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005570 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005571 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005572 alloc_info.descriptorPool = ds_pool;
5573 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005574 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5575 &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005576 ASSERT_VK_SUCCESS(err);
5577
Tony Barboureb254902015-07-15 12:50:33 -06005578 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005579 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5580 pipeline_layout_ci.setLayoutCount = 1;
5581 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005582
5583 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005584 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5585 &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005586 ASSERT_VK_SUCCESS(err);
5587
Tobin Ehlise68360f2015-10-01 11:15:13 -06005588 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07005589 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06005590
5591 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005592 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5593 vp_state_ci.scissorCount = 1;
5594 vp_state_ci.pScissors = &sc;
5595 vp_state_ci.viewportCount = 1;
5596 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005597
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005598 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
5599 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5600 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
5601 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
5602 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
5603 rs_state_ci.depthClampEnable = VK_FALSE;
5604 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
5605 rs_state_ci.depthBiasEnable = VK_FALSE;
5606
Tony Barboureb254902015-07-15 12:50:33 -06005607 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005608 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5609 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005610 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07005611 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5612 gp_ci.layout = pipeline_layout;
5613 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06005614
5615 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005616 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5617 pc_ci.initialDataSize = 0;
5618 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005619
5620 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06005621 VkPipelineCache pipelineCache;
5622
Karl Schultz6addd812016-02-02 17:17:23 -07005623 err =
5624 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06005625 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005626 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5627 &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005628
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005629 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005630
Chia-I Wuf7458c52015-10-26 21:10:41 +08005631 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5632 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5633 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5634 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005635}
Tobin Ehlis912df022015-09-17 08:46:18 -06005636/*// TODO : This test should be good, but needs Tess support in compiler to run
5637TEST_F(VkLayerTest, InvalidPatchControlPoints)
5638{
5639 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06005640 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005641
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005643 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
5644primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005645
Tobin Ehlis912df022015-09-17 08:46:18 -06005646 ASSERT_NO_FATAL_FAILURE(InitState());
5647 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06005648
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005649 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06005650 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005651 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06005652
5653 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5654 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5655 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005656 ds_pool_ci.poolSizeCount = 1;
5657 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06005658
5659 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005660 err = vkCreateDescriptorPool(m_device->device(),
5661VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06005662 ASSERT_VK_SUCCESS(err);
5663
5664 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08005665 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06005666 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08005667 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06005668 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5669 dsl_binding.pImmutableSamplers = NULL;
5670
5671 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005672 ds_layout_ci.sType =
5673VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06005674 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005675 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005676 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06005677
5678 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005679 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5680&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06005681 ASSERT_VK_SUCCESS(err);
5682
5683 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07005684 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
5685VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06005686 ASSERT_VK_SUCCESS(err);
5687
5688 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005689 pipeline_layout_ci.sType =
5690VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06005691 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005692 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06005693 pipeline_layout_ci.pSetLayouts = &ds_layout;
5694
5695 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005696 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5697&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06005698 ASSERT_VK_SUCCESS(err);
5699
5700 VkPipelineShaderStageCreateInfo shaderStages[3];
5701 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
5702
Karl Schultz6addd812016-02-02 17:17:23 -07005703 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
5704this);
Tobin Ehlis912df022015-09-17 08:46:18 -06005705 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07005706 VkShaderObj
5707tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
5708this);
5709 VkShaderObj
5710te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
5711this);
Tobin Ehlis912df022015-09-17 08:46:18 -06005712
Karl Schultz6addd812016-02-02 17:17:23 -07005713 shaderStages[0].sType =
5714VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005715 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06005716 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07005717 shaderStages[1].sType =
5718VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005719 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06005720 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07005721 shaderStages[2].sType =
5722VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005723 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06005724 shaderStages[2].shader = te.handle();
5725
5726 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005727 iaCI.sType =
5728VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08005729 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06005730
5731 VkPipelineTessellationStateCreateInfo tsCI = {};
5732 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
5733 tsCI.patchControlPoints = 0; // This will cause an error
5734
5735 VkGraphicsPipelineCreateInfo gp_ci = {};
5736 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5737 gp_ci.pNext = NULL;
5738 gp_ci.stageCount = 3;
5739 gp_ci.pStages = shaderStages;
5740 gp_ci.pVertexInputState = NULL;
5741 gp_ci.pInputAssemblyState = &iaCI;
5742 gp_ci.pTessellationState = &tsCI;
5743 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005744 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06005745 gp_ci.pMultisampleState = NULL;
5746 gp_ci.pDepthStencilState = NULL;
5747 gp_ci.pColorBlendState = NULL;
5748 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5749 gp_ci.layout = pipeline_layout;
5750 gp_ci.renderPass = renderPass();
5751
5752 VkPipelineCacheCreateInfo pc_ci = {};
5753 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5754 pc_ci.pNext = NULL;
5755 pc_ci.initialSize = 0;
5756 pc_ci.initialData = 0;
5757 pc_ci.maxSize = 0;
5758
5759 VkPipeline pipeline;
5760 VkPipelineCache pipelineCache;
5761
Karl Schultz6addd812016-02-02 17:17:23 -07005762 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
5763&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06005764 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005765 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5766&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06005767
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005768 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005769
Chia-I Wuf7458c52015-10-26 21:10:41 +08005770 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5771 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5772 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5773 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06005774}
5775*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06005776// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07005777TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07005778 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005779
Karl Schultz6addd812016-02-02 17:17:23 -07005780 m_errorMonitor->SetDesiredFailureMsg(
5781 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005782 "Gfx Pipeline viewport count (1) must match scissor count (0).");
5783
Tobin Ehlise68360f2015-10-01 11:15:13 -06005784 ASSERT_NO_FATAL_FAILURE(InitState());
5785 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06005786
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005787 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005788 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5789 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005790
5791 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005792 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5793 ds_pool_ci.maxSets = 1;
5794 ds_pool_ci.poolSizeCount = 1;
5795 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005796
5797 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005798 err =
5799 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005800 ASSERT_VK_SUCCESS(err);
5801
5802 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005803 dsl_binding.binding = 0;
5804 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5805 dsl_binding.descriptorCount = 1;
5806 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005807
5808 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005809 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5810 ds_layout_ci.bindingCount = 1;
5811 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005812
5813 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005814 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5815 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005816 ASSERT_VK_SUCCESS(err);
5817
5818 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005819 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005820 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005821 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005822 alloc_info.descriptorPool = ds_pool;
5823 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005824 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5825 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005826 ASSERT_VK_SUCCESS(err);
5827
5828 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005829 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5830 pipeline_layout_ci.setLayoutCount = 1;
5831 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005832
5833 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005834 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5835 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005836 ASSERT_VK_SUCCESS(err);
5837
5838 VkViewport vp = {}; // Just need dummy vp to point to
5839
5840 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005841 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5842 vp_state_ci.scissorCount = 0;
5843 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
5844 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005845
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005846 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
5847 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5848 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
5849 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
5850 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
5851 rs_state_ci.depthClampEnable = VK_FALSE;
5852 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
5853 rs_state_ci.depthBiasEnable = VK_FALSE;
5854
Cody Northropeb3a6c12015-10-05 14:44:45 -06005855 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07005856 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06005857
Karl Schultz6addd812016-02-02 17:17:23 -07005858 VkShaderObj vs(m_device, bindStateVertShaderText,
5859 VK_SHADER_STAGE_VERTEX_BIT, this);
5860 VkShaderObj fs(m_device, bindStateFragShaderText,
5861 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06005862 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07005863 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08005864 shaderStages[0] = vs.GetStageCreateInfo();
5865 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005866
5867 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005868 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5869 gp_ci.stageCount = 2;
5870 gp_ci.pStages = shaderStages;
5871 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005872 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07005873 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5874 gp_ci.layout = pipeline_layout;
5875 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005876
5877 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005878 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005879
5880 VkPipeline pipeline;
5881 VkPipelineCache pipelineCache;
5882
Karl Schultz6addd812016-02-02 17:17:23 -07005883 err =
5884 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005885 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005886 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5887 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005888
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005889 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005890
Chia-I Wuf7458c52015-10-26 21:10:41 +08005891 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5892 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5893 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5894 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005895}
Karl Schultz6addd812016-02-02 17:17:23 -07005896// Don't set viewport state in PSO. This is an error b/c we always need this
5897// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06005898// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07005899TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06005900 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07005901 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005902
Karl Schultz6addd812016-02-02 17:17:23 -07005903 m_errorMonitor->SetDesiredFailureMsg(
5904 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005905 "Gfx Pipeline pViewportState is null. Even if ");
5906
Tobin Ehlise68360f2015-10-01 11:15:13 -06005907 ASSERT_NO_FATAL_FAILURE(InitState());
5908 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06005909
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005910 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005911 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5912 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005913
5914 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005915 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5916 ds_pool_ci.maxSets = 1;
5917 ds_pool_ci.poolSizeCount = 1;
5918 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005919
5920 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005921 err =
5922 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005923 ASSERT_VK_SUCCESS(err);
5924
5925 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005926 dsl_binding.binding = 0;
5927 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5928 dsl_binding.descriptorCount = 1;
5929 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005930
5931 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005932 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5933 ds_layout_ci.bindingCount = 1;
5934 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005935
5936 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005937 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5938 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005939 ASSERT_VK_SUCCESS(err);
5940
5941 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005942 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005943 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005944 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005945 alloc_info.descriptorPool = ds_pool;
5946 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005947 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5948 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005949 ASSERT_VK_SUCCESS(err);
5950
5951 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005952 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5953 pipeline_layout_ci.setLayoutCount = 1;
5954 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005955
5956 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005957 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5958 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005959 ASSERT_VK_SUCCESS(err);
5960
5961 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
5962 // Set scissor as dynamic to avoid second error
5963 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005964 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
5965 dyn_state_ci.dynamicStateCount = 1;
5966 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005967
Cody Northropeb3a6c12015-10-05 14:44:45 -06005968 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07005969 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06005970
Karl Schultz6addd812016-02-02 17:17:23 -07005971 VkShaderObj vs(m_device, bindStateVertShaderText,
5972 VK_SHADER_STAGE_VERTEX_BIT, this);
5973 VkShaderObj fs(m_device, bindStateFragShaderText,
5974 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06005975 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07005976 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08005977 shaderStages[0] = vs.GetStageCreateInfo();
5978 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005979
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005980
5981 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
5982 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5983 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
5984 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
5985 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
5986 rs_state_ci.depthClampEnable = VK_FALSE;
5987 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
5988 rs_state_ci.depthBiasEnable = VK_FALSE;
5989
Tobin Ehlise68360f2015-10-01 11:15:13 -06005990 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005991 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5992 gp_ci.stageCount = 2;
5993 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005994 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07005995 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
5996 // should cause validation error
5997 gp_ci.pDynamicState = &dyn_state_ci;
5998 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5999 gp_ci.layout = pipeline_layout;
6000 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006001
6002 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006003 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006004
6005 VkPipeline pipeline;
6006 VkPipelineCache pipelineCache;
6007
Karl Schultz6addd812016-02-02 17:17:23 -07006008 err =
6009 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006010 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006011 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6012 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006013
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006014 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006015
Chia-I Wuf7458c52015-10-26 21:10:41 +08006016 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6017 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6018 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6019 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006020}
6021// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07006022// Then run second test where dynamic scissor count doesn't match PSO scissor
6023// count
6024TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
6025 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006026
Karl Schultz6addd812016-02-02 17:17:23 -07006027 m_errorMonitor->SetDesiredFailureMsg(
6028 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006029 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
6030
Tobin Ehlise68360f2015-10-01 11:15:13 -06006031 ASSERT_NO_FATAL_FAILURE(InitState());
6032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006033
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006034 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006035 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6036 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006037
6038 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006039 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6040 ds_pool_ci.maxSets = 1;
6041 ds_pool_ci.poolSizeCount = 1;
6042 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006043
6044 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006045 err =
6046 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006047 ASSERT_VK_SUCCESS(err);
6048
6049 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006050 dsl_binding.binding = 0;
6051 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6052 dsl_binding.descriptorCount = 1;
6053 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006054
6055 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006056 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6057 ds_layout_ci.bindingCount = 1;
6058 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006059
6060 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006061 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6062 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006063 ASSERT_VK_SUCCESS(err);
6064
6065 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006066 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006067 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006068 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006069 alloc_info.descriptorPool = ds_pool;
6070 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006071 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6072 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006073 ASSERT_VK_SUCCESS(err);
6074
6075 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006076 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6077 pipeline_layout_ci.setLayoutCount = 1;
6078 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006079
6080 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006081 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6082 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006083 ASSERT_VK_SUCCESS(err);
6084
6085 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006086 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6087 vp_state_ci.viewportCount = 1;
6088 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
6089 vp_state_ci.scissorCount = 1;
6090 vp_state_ci.pScissors =
6091 NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06006092
6093 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6094 // Set scissor as dynamic to avoid that error
6095 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006096 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6097 dyn_state_ci.dynamicStateCount = 1;
6098 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006099
Cody Northropeb3a6c12015-10-05 14:44:45 -06006100 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006101 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006102
Karl Schultz6addd812016-02-02 17:17:23 -07006103 VkShaderObj vs(m_device, bindStateVertShaderText,
6104 VK_SHADER_STAGE_VERTEX_BIT, this);
6105 VkShaderObj fs(m_device, bindStateFragShaderText,
6106 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006107 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006108 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006109 shaderStages[0] = vs.GetStageCreateInfo();
6110 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006111
Cody Northropf6622dc2015-10-06 10:33:21 -06006112 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6113 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6114 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006115 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006116 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006117 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006118 vi_ci.pVertexAttributeDescriptions = nullptr;
6119
6120 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6121 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6122 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6123
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006124 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006125 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06006126 rs_ci.pNext = nullptr;
6127
Mark Youngc89c6312016-03-31 16:03:20 -06006128 VkPipelineColorBlendAttachmentState att = {};
6129 att.blendEnable = VK_FALSE;
6130 att.colorWriteMask = 0xf;
6131
Cody Northropf6622dc2015-10-06 10:33:21 -06006132 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6133 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6134 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006135 cb_ci.attachmentCount = 1;
6136 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06006137
Tobin Ehlise68360f2015-10-01 11:15:13 -06006138 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006139 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6140 gp_ci.stageCount = 2;
6141 gp_ci.pStages = shaderStages;
6142 gp_ci.pVertexInputState = &vi_ci;
6143 gp_ci.pInputAssemblyState = &ia_ci;
6144 gp_ci.pViewportState = &vp_state_ci;
6145 gp_ci.pRasterizationState = &rs_ci;
6146 gp_ci.pColorBlendState = &cb_ci;
6147 gp_ci.pDynamicState = &dyn_state_ci;
6148 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6149 gp_ci.layout = pipeline_layout;
6150 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006151
6152 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006153 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006154
6155 VkPipeline pipeline;
6156 VkPipelineCache pipelineCache;
6157
Karl Schultz6addd812016-02-02 17:17:23 -07006158 err =
6159 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006160 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006161 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6162 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006163
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006164 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006165
Tobin Ehlisd332f282015-10-02 11:00:56 -06006166 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07006167 // First need to successfully create the PSO from above by setting
6168 // pViewports
6169 m_errorMonitor->SetDesiredFailureMsg(
6170 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6171 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO "
6172 "scissorCount is 1. These counts must match.");
6173
6174 VkViewport vp = {}; // Just need dummy vp to point to
6175 vp_state_ci.pViewports = &vp;
6176 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6177 &gp_ci, NULL, &pipeline);
6178 ASSERT_VK_SUCCESS(err);
6179 BeginCommandBuffer();
6180 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6181 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
6182 VkRect2D scissors[2] = {}; // don't care about data
6183 // Count of 2 doesn't match PSO count of 1
6184 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
6185 Draw(1, 0, 0, 0);
6186
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006187 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006188
6189 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6190 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6191 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6192 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6193}
6194// Create PSO w/o non-zero scissorCount but no scissor data
6195// Then run second test where dynamic viewportCount doesn't match PSO
6196// viewportCount
6197TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
6198 VkResult err;
6199
6200 m_errorMonitor->SetDesiredFailureMsg(
6201 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6202 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
6203
6204 ASSERT_NO_FATAL_FAILURE(InitState());
6205 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6206
6207 VkDescriptorPoolSize ds_type_count = {};
6208 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6209 ds_type_count.descriptorCount = 1;
6210
6211 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6212 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6213 ds_pool_ci.maxSets = 1;
6214 ds_pool_ci.poolSizeCount = 1;
6215 ds_pool_ci.pPoolSizes = &ds_type_count;
6216
6217 VkDescriptorPool ds_pool;
6218 err =
6219 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6220 ASSERT_VK_SUCCESS(err);
6221
6222 VkDescriptorSetLayoutBinding dsl_binding = {};
6223 dsl_binding.binding = 0;
6224 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6225 dsl_binding.descriptorCount = 1;
6226 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6227
6228 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6229 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6230 ds_layout_ci.bindingCount = 1;
6231 ds_layout_ci.pBindings = &dsl_binding;
6232
6233 VkDescriptorSetLayout ds_layout;
6234 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6235 &ds_layout);
6236 ASSERT_VK_SUCCESS(err);
6237
6238 VkDescriptorSet descriptorSet;
6239 VkDescriptorSetAllocateInfo alloc_info = {};
6240 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6241 alloc_info.descriptorSetCount = 1;
6242 alloc_info.descriptorPool = ds_pool;
6243 alloc_info.pSetLayouts = &ds_layout;
6244 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6245 &descriptorSet);
6246 ASSERT_VK_SUCCESS(err);
6247
6248 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6249 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6250 pipeline_layout_ci.setLayoutCount = 1;
6251 pipeline_layout_ci.pSetLayouts = &ds_layout;
6252
6253 VkPipelineLayout pipeline_layout;
6254 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6255 &pipeline_layout);
6256 ASSERT_VK_SUCCESS(err);
6257
6258 VkPipelineViewportStateCreateInfo vp_state_ci = {};
6259 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6260 vp_state_ci.scissorCount = 1;
6261 vp_state_ci.pScissors =
6262 NULL; // Null scissor w/ count of 1 should cause error
6263 vp_state_ci.viewportCount = 1;
6264 vp_state_ci.pViewports =
6265 NULL; // vp is dynamic (below) so this won't cause error
6266
6267 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
6268 // Set scissor as dynamic to avoid that error
6269 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
6270 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6271 dyn_state_ci.dynamicStateCount = 1;
6272 dyn_state_ci.pDynamicStates = &vp_state;
6273
6274 VkPipelineShaderStageCreateInfo shaderStages[2];
6275 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6276
6277 VkShaderObj vs(m_device, bindStateVertShaderText,
6278 VK_SHADER_STAGE_VERTEX_BIT, this);
6279 VkShaderObj fs(m_device, bindStateFragShaderText,
6280 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006281 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006282 // but add it to be able to run on more devices
6283 shaderStages[0] = vs.GetStageCreateInfo();
6284 shaderStages[1] = fs.GetStageCreateInfo();
6285
6286 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6287 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6288 vi_ci.pNext = nullptr;
6289 vi_ci.vertexBindingDescriptionCount = 0;
6290 vi_ci.pVertexBindingDescriptions = nullptr;
6291 vi_ci.vertexAttributeDescriptionCount = 0;
6292 vi_ci.pVertexAttributeDescriptions = nullptr;
6293
6294 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6295 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6296 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6297
6298 VkPipelineRasterizationStateCreateInfo rs_ci = {};
6299 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6300 rs_ci.pNext = nullptr;
6301
Mark Youngc89c6312016-03-31 16:03:20 -06006302 VkPipelineColorBlendAttachmentState att = {};
6303 att.blendEnable = VK_FALSE;
6304 att.colorWriteMask = 0xf;
6305
Karl Schultz6addd812016-02-02 17:17:23 -07006306 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6307 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6308 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006309 cb_ci.attachmentCount = 1;
6310 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07006311
6312 VkGraphicsPipelineCreateInfo gp_ci = {};
6313 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6314 gp_ci.stageCount = 2;
6315 gp_ci.pStages = shaderStages;
6316 gp_ci.pVertexInputState = &vi_ci;
6317 gp_ci.pInputAssemblyState = &ia_ci;
6318 gp_ci.pViewportState = &vp_state_ci;
6319 gp_ci.pRasterizationState = &rs_ci;
6320 gp_ci.pColorBlendState = &cb_ci;
6321 gp_ci.pDynamicState = &dyn_state_ci;
6322 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6323 gp_ci.layout = pipeline_layout;
6324 gp_ci.renderPass = renderPass();
6325
6326 VkPipelineCacheCreateInfo pc_ci = {};
6327 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6328
6329 VkPipeline pipeline;
6330 VkPipelineCache pipelineCache;
6331
6332 err =
6333 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6334 ASSERT_VK_SUCCESS(err);
6335 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6336 &gp_ci, NULL, &pipeline);
6337
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006338 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006339
6340 // Now hit second fail case where we set scissor w/ different count than PSO
6341 // First need to successfully create the PSO from above by setting
6342 // pViewports
6343 m_errorMonitor->SetDesiredFailureMsg(
6344 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6345 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO "
6346 "viewportCount is 1. These counts must match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006347
Tobin Ehlisd332f282015-10-02 11:00:56 -06006348 VkRect2D sc = {}; // Just need dummy vp to point to
6349 vp_state_ci.pScissors = &sc;
Karl Schultz6addd812016-02-02 17:17:23 -07006350 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6351 &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006352 ASSERT_VK_SUCCESS(err);
6353 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006354 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6355 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006356 VkViewport viewports[2] = {}; // don't care about data
6357 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07006358 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006359 Draw(1, 0, 0, 0);
6360
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006361 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006362
Chia-I Wuf7458c52015-10-26 21:10:41 +08006363 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6364 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6365 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6366 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006367}
6368
Mark Young7394fdd2016-03-31 14:56:43 -06006369TEST_F(VkLayerTest, PSOLineWidthInvalid) {
6370 VkResult err;
6371
6372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06006373 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06006374
6375 ASSERT_NO_FATAL_FAILURE(InitState());
6376 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6377
6378 VkDescriptorPoolSize ds_type_count = {};
6379 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6380 ds_type_count.descriptorCount = 1;
6381
6382 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6383 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6384 ds_pool_ci.maxSets = 1;
6385 ds_pool_ci.poolSizeCount = 1;
6386 ds_pool_ci.pPoolSizes = &ds_type_count;
6387
6388 VkDescriptorPool ds_pool;
6389 err =
6390 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6391 ASSERT_VK_SUCCESS(err);
6392
6393 VkDescriptorSetLayoutBinding dsl_binding = {};
6394 dsl_binding.binding = 0;
6395 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6396 dsl_binding.descriptorCount = 1;
6397 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6398
6399 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6400 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6401 ds_layout_ci.bindingCount = 1;
6402 ds_layout_ci.pBindings = &dsl_binding;
6403
6404 VkDescriptorSetLayout ds_layout;
6405 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6406 &ds_layout);
6407 ASSERT_VK_SUCCESS(err);
6408
6409 VkDescriptorSet descriptorSet;
6410 VkDescriptorSetAllocateInfo alloc_info = {};
6411 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6412 alloc_info.descriptorSetCount = 1;
6413 alloc_info.descriptorPool = ds_pool;
6414 alloc_info.pSetLayouts = &ds_layout;
6415 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6416 &descriptorSet);
6417 ASSERT_VK_SUCCESS(err);
6418
6419 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6420 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6421 pipeline_layout_ci.setLayoutCount = 1;
6422 pipeline_layout_ci.pSetLayouts = &ds_layout;
6423
6424 VkPipelineLayout pipeline_layout;
6425 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6426 &pipeline_layout);
6427 ASSERT_VK_SUCCESS(err);
6428
6429 VkPipelineViewportStateCreateInfo vp_state_ci = {};
6430 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6431 vp_state_ci.scissorCount = 1;
6432 vp_state_ci.pScissors = NULL;
6433 vp_state_ci.viewportCount = 1;
6434 vp_state_ci.pViewports = NULL;
6435
6436 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT,
6437 VK_DYNAMIC_STATE_SCISSOR,
6438 VK_DYNAMIC_STATE_LINE_WIDTH};
6439 // Set scissor as dynamic to avoid that error
6440 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
6441 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6442 dyn_state_ci.dynamicStateCount = 2;
6443 dyn_state_ci.pDynamicStates = dynamic_states;
6444
6445 VkPipelineShaderStageCreateInfo shaderStages[2];
6446 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6447
6448 VkShaderObj vs(m_device, bindStateVertShaderText,
6449 VK_SHADER_STAGE_VERTEX_BIT, this);
6450 VkShaderObj fs(m_device, bindStateFragShaderText,
6451 VK_SHADER_STAGE_FRAGMENT_BIT,
6452 this); // TODO - We shouldn't need a fragment shader
6453 // but add it to be able to run on more devices
6454 shaderStages[0] = vs.GetStageCreateInfo();
6455 shaderStages[1] = fs.GetStageCreateInfo();
6456
6457 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6458 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6459 vi_ci.pNext = nullptr;
6460 vi_ci.vertexBindingDescriptionCount = 0;
6461 vi_ci.pVertexBindingDescriptions = nullptr;
6462 vi_ci.vertexAttributeDescriptionCount = 0;
6463 vi_ci.pVertexAttributeDescriptions = nullptr;
6464
6465 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6466 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6467 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6468
6469 VkPipelineRasterizationStateCreateInfo rs_ci = {};
6470 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6471 rs_ci.pNext = nullptr;
6472
Mark Young47107952016-05-02 15:59:55 -06006473 // Check too low (line width of -1.0f).
6474 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06006475
6476 VkPipelineColorBlendAttachmentState att = {};
6477 att.blendEnable = VK_FALSE;
6478 att.colorWriteMask = 0xf;
6479
6480 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6481 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6482 cb_ci.pNext = nullptr;
6483 cb_ci.attachmentCount = 1;
6484 cb_ci.pAttachments = &att;
6485
6486 VkGraphicsPipelineCreateInfo gp_ci = {};
6487 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6488 gp_ci.stageCount = 2;
6489 gp_ci.pStages = shaderStages;
6490 gp_ci.pVertexInputState = &vi_ci;
6491 gp_ci.pInputAssemblyState = &ia_ci;
6492 gp_ci.pViewportState = &vp_state_ci;
6493 gp_ci.pRasterizationState = &rs_ci;
6494 gp_ci.pColorBlendState = &cb_ci;
6495 gp_ci.pDynamicState = &dyn_state_ci;
6496 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6497 gp_ci.layout = pipeline_layout;
6498 gp_ci.renderPass = renderPass();
6499
6500 VkPipelineCacheCreateInfo pc_ci = {};
6501 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6502
6503 VkPipeline pipeline;
6504 VkPipelineCache pipelineCache;
6505
6506 err =
6507 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6508 ASSERT_VK_SUCCESS(err);
6509 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6510 &gp_ci, NULL, &pipeline);
6511
6512 m_errorMonitor->VerifyFound();
6513
6514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6515 "Attempt to set lineWidth to 65536");
6516
6517 // Check too high (line width of 65536.0f).
6518 rs_ci.lineWidth = 65536.0f;
6519
6520 err =
6521 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6522 ASSERT_VK_SUCCESS(err);
6523 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6524 &gp_ci, NULL, &pipeline);
6525
6526 m_errorMonitor->VerifyFound();
6527
6528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06006529 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06006530
6531 dyn_state_ci.dynamicStateCount = 3;
6532
6533 rs_ci.lineWidth = 1.0f;
6534
6535 err =
6536 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6537 ASSERT_VK_SUCCESS(err);
6538 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6539 &gp_ci, NULL, &pipeline);
6540 BeginCommandBuffer();
6541 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6542 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
6543
6544 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06006545 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06006546 m_errorMonitor->VerifyFound();
6547
6548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6549 "Attempt to set lineWidth to 65536");
6550
6551 // Check too high with dynamic setting.
6552 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
6553 m_errorMonitor->VerifyFound();
6554 EndCommandBuffer();
6555
6556 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6557 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6558 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6559 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6560}
6561
Karl Schultz6addd812016-02-02 17:17:23 -07006562TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006563 // Bind a NULL RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006564 m_errorMonitor->SetDesiredFailureMsg(
6565 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006566 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006567
6568 ASSERT_NO_FATAL_FAILURE(InitState());
6569 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006570
Tony Barbourfe3351b2015-07-28 10:17:20 -06006571 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006572 // Don't care about RenderPass handle b/c error should be flagged before
6573 // that
6574 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL,
6575 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006576
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006577 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006578}
6579
Karl Schultz6addd812016-02-02 17:17:23 -07006580TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006581 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006582 m_errorMonitor->SetDesiredFailureMsg(
6583 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006584 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006585
6586 ASSERT_NO_FATAL_FAILURE(InitState());
6587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006588
Tony Barbourfe3351b2015-07-28 10:17:20 -06006589 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006590 // Just create a dummy Renderpass that's non-NULL so we can get to the
6591 // proper error
Tony Barboureb254902015-07-15 12:50:33 -06006592 VkRenderPassBeginInfo rp_begin = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006593 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
6594 rp_begin.pNext = NULL;
6595 rp_begin.renderPass = renderPass();
6596 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006597
Karl Schultz6addd812016-02-02 17:17:23 -07006598 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
6599 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006600
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006601 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006602}
6603
Cody Northrop3bb4d962016-05-09 16:15:57 -06006604TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
6605
6606 TEST_DESCRIPTION("End a command buffer with an active render pass");
6607
6608 m_errorMonitor->SetDesiredFailureMsg(
6609 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6610 "It is invalid to issue this call inside an active render pass");
6611
6612 ASSERT_NO_FATAL_FAILURE(InitState());
6613 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6614
6615 // The framework's BeginCommandBuffer calls CreateRenderPass
6616 BeginCommandBuffer();
6617
6618 // Call directly into vkEndCommandBuffer instead of the
6619 // the framework's EndCommandBuffer, which inserts a
6620 // vkEndRenderPass
6621 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
6622
6623 m_errorMonitor->VerifyFound();
6624
6625 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
6626 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
6627}
6628
Karl Schultz6addd812016-02-02 17:17:23 -07006629TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006630 // Call CmdFillBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07006631 m_errorMonitor->SetDesiredFailureMsg(
6632 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006633 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006634
6635 ASSERT_NO_FATAL_FAILURE(InitState());
6636 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006637
6638 // Renderpass is started here
6639 BeginCommandBuffer();
6640
6641 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006642 vk_testing::Buffer dstBuffer;
6643 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006644
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006645 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006646
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006647 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006648}
6649
Karl Schultz6addd812016-02-02 17:17:23 -07006650TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006651 // Call CmdUpdateBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07006652 m_errorMonitor->SetDesiredFailureMsg(
6653 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006654 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006655
6656 ASSERT_NO_FATAL_FAILURE(InitState());
6657 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006658
6659 // Renderpass is started here
6660 BeginCommandBuffer();
6661
6662 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006663 vk_testing::Buffer dstBuffer;
6664 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006665
Karl Schultz6addd812016-02-02 17:17:23 -07006666 VkDeviceSize dstOffset = 0;
6667 VkDeviceSize dataSize = 1024;
6668 const uint32_t *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006669
Karl Schultz6addd812016-02-02 17:17:23 -07006670 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
6671 dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006672
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006673 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006674}
6675
Karl Schultz6addd812016-02-02 17:17:23 -07006676TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006677 // Call CmdClearColorImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006678 m_errorMonitor->SetDesiredFailureMsg(
6679 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006680 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006681
6682 ASSERT_NO_FATAL_FAILURE(InitState());
6683 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006684
6685 // Renderpass is started here
6686 BeginCommandBuffer();
6687
Michael Lentine0a369f62016-02-03 16:51:46 -06006688 VkClearColorValue clear_color;
6689 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07006690 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
6691 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6692 const int32_t tex_width = 32;
6693 const int32_t tex_height = 32;
6694 VkImageCreateInfo image_create_info = {};
6695 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6696 image_create_info.pNext = NULL;
6697 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6698 image_create_info.format = tex_format;
6699 image_create_info.extent.width = tex_width;
6700 image_create_info.extent.height = tex_height;
6701 image_create_info.extent.depth = 1;
6702 image_create_info.mipLevels = 1;
6703 image_create_info.arrayLayers = 1;
6704 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6705 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
6706 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006707
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006708 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07006709 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
6710 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006711
Karl Schultz6addd812016-02-02 17:17:23 -07006712 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
6713 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006714
Karl Schultz6addd812016-02-02 17:17:23 -07006715 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
6716 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006717
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006718 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006719}
6720
Karl Schultz6addd812016-02-02 17:17:23 -07006721TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006722 // Call CmdClearDepthStencilImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006723 m_errorMonitor->SetDesiredFailureMsg(
6724 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006725 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006726
6727 ASSERT_NO_FATAL_FAILURE(InitState());
6728 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006729
6730 // Renderpass is started here
6731 BeginCommandBuffer();
6732
6733 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07006734 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07006735 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
6736 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6737 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
6738 image_create_info.extent.width = 64;
6739 image_create_info.extent.height = 64;
6740 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6741 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006742
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006743 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07006744 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
6745 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006746
Karl Schultz6addd812016-02-02 17:17:23 -07006747 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
6748 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006749
Karl Schultz6addd812016-02-02 17:17:23 -07006750 vkCmdClearDepthStencilImage(
6751 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
6752 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
6753 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006754
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006755 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006756}
6757
Karl Schultz6addd812016-02-02 17:17:23 -07006758TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006759 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006760 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006761
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006763 "vkCmdClearAttachments: This call "
6764 "must be issued inside an active "
6765 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006766
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006767 ASSERT_NO_FATAL_FAILURE(InitState());
6768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006769
6770 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006771 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006772 ASSERT_VK_SUCCESS(err);
6773
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006774 VkClearAttachment color_attachment;
6775 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6776 color_attachment.clearValue.color.float32[0] = 0;
6777 color_attachment.clearValue.color.float32[1] = 0;
6778 color_attachment.clearValue.color.float32[2] = 0;
6779 color_attachment.clearValue.color.float32[3] = 0;
6780 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07006781 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
6782 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
6783 &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006784
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006785 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006786}
6787
Karl Schultz9e66a292016-04-21 15:57:51 -06006788TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
6789 // Try to add a buffer memory barrier with no buffer.
6790 m_errorMonitor->SetDesiredFailureMsg(
6791 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6792 "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE");
6793
6794 ASSERT_NO_FATAL_FAILURE(InitState());
6795 BeginCommandBuffer();
6796
6797 VkBufferMemoryBarrier buf_barrier = {};
6798 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
6799 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6800 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6801 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6802 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6803 buf_barrier.buffer = VK_NULL_HANDLE;
6804 buf_barrier.offset = 0;
6805 buf_barrier.size = VK_WHOLE_SIZE;
6806 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6807 VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
6808 0, 0, nullptr, 1, &buf_barrier, 0, nullptr);
6809
6810 m_errorMonitor->VerifyFound();
6811}
6812
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06006813TEST_F(VkLayerTest, InvalidBarriers) {
6814 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
6815
6816 m_errorMonitor->SetDesiredFailureMsg(
6817 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
6818
6819 ASSERT_NO_FATAL_FAILURE(InitState());
6820 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6821
6822 VkMemoryBarrier mem_barrier = {};
6823 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
6824 mem_barrier.pNext = NULL;
6825 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6826 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6827 BeginCommandBuffer();
6828 // BeginCommandBuffer() starts a render pass
6829 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6830 VK_PIPELINE_STAGE_HOST_BIT,
6831 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
6832 &mem_barrier, 0, nullptr, 0, nullptr);
6833 m_errorMonitor->VerifyFound();
6834
6835 m_errorMonitor->SetDesiredFailureMsg(
6836 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6837 "Image Layout cannot be transitioned to UNDEFINED");
6838 VkImageObj image(m_device);
6839 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
6840 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6841 ASSERT_TRUE(image.initialized());
6842 VkImageMemoryBarrier img_barrier = {};
6843 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
6844 img_barrier.pNext = NULL;
6845 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6846 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6847 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
6848 // New layout can't be UNDEFINED
6849 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6850 img_barrier.image = image.handle();
6851 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6852 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6853 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6854 img_barrier.subresourceRange.baseArrayLayer = 0;
6855 img_barrier.subresourceRange.baseMipLevel = 0;
6856 img_barrier.subresourceRange.layerCount = 1;
6857 img_barrier.subresourceRange.levelCount = 1;
6858 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6859 VK_PIPELINE_STAGE_HOST_BIT,
6860 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6861 nullptr, 1, &img_barrier);
6862 m_errorMonitor->VerifyFound();
6863 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
6864
6865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6866 "Subresource must have the sum of the "
6867 "baseArrayLayer");
6868 // baseArrayLayer + layerCount must be <= image's arrayLayers
6869 img_barrier.subresourceRange.baseArrayLayer = 1;
6870 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6871 VK_PIPELINE_STAGE_HOST_BIT,
6872 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6873 nullptr, 1, &img_barrier);
6874 m_errorMonitor->VerifyFound();
6875 img_barrier.subresourceRange.baseArrayLayer = 0;
6876
6877 m_errorMonitor->SetDesiredFailureMsg(
6878 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6879 "Subresource must have the sum of the baseMipLevel");
6880 // baseMipLevel + levelCount must be <= image's mipLevels
6881 img_barrier.subresourceRange.baseMipLevel = 1;
6882 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6883 VK_PIPELINE_STAGE_HOST_BIT,
6884 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6885 nullptr, 1, &img_barrier);
6886 m_errorMonitor->VerifyFound();
6887 img_barrier.subresourceRange.baseMipLevel = 0;
6888
6889 m_errorMonitor->SetDesiredFailureMsg(
6890 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6891 "Buffer Barriers cannot be used during a render pass");
6892 vk_testing::Buffer buffer;
6893 buffer.init(*m_device, 256);
6894 VkBufferMemoryBarrier buf_barrier = {};
6895 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
6896 buf_barrier.pNext = NULL;
6897 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6898 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6899 buf_barrier.buffer = buffer.handle();
6900 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6901 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6902 buf_barrier.offset = 0;
6903 buf_barrier.size = VK_WHOLE_SIZE;
6904 // Can't send buffer barrier during a render pass
6905 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6906 VK_PIPELINE_STAGE_HOST_BIT,
6907 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
6908 &buf_barrier, 0, nullptr);
6909 m_errorMonitor->VerifyFound();
6910 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
6911
6912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6913 "which is not less than total size");
6914 buf_barrier.offset = 257;
6915 // Offset greater than total size
6916 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6917 VK_PIPELINE_STAGE_HOST_BIT,
6918 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
6919 &buf_barrier, 0, nullptr);
6920 m_errorMonitor->VerifyFound();
6921 buf_barrier.offset = 0;
6922
6923 m_errorMonitor->SetDesiredFailureMsg(
6924 VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
6925 buf_barrier.size = 257;
6926 // Size greater than total size
6927 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6928 VK_PIPELINE_STAGE_HOST_BIT,
6929 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
6930 &buf_barrier, 0, nullptr);
6931 m_errorMonitor->VerifyFound();
6932 buf_barrier.size = VK_WHOLE_SIZE;
6933
6934 m_errorMonitor->SetDesiredFailureMsg(
6935 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6936 "Image is a depth and stencil format and thus must "
6937 "have both VK_IMAGE_ASPECT_DEPTH_BIT and "
6938 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
6939 VkDepthStencilObj ds_image(m_device);
6940 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
6941 ASSERT_TRUE(ds_image.initialized());
6942 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
6943 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
6944 img_barrier.image = ds_image.handle();
6945 // Leave aspectMask at COLOR on purpose
6946 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6947 VK_PIPELINE_STAGE_HOST_BIT,
6948 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6949 nullptr, 1, &img_barrier);
6950 m_errorMonitor->VerifyFound();
6951}
6952
Karl Schultz6addd812016-02-02 17:17:23 -07006953TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006954 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006955 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006956
Karl Schultz6addd812016-02-02 17:17:23 -07006957 m_errorMonitor->SetDesiredFailureMsg(
6958 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006959 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
6960
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006961 ASSERT_NO_FATAL_FAILURE(InitState());
6962 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006963 uint32_t qfi = 0;
6964 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006965 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6966 buffCI.size = 1024;
6967 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
6968 buffCI.queueFamilyIndexCount = 1;
6969 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006970
6971 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006972 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006973 ASSERT_VK_SUCCESS(err);
6974
6975 BeginCommandBuffer();
6976 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006977 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6978 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006979 // Should error before calling to driver so don't care about actual data
Karl Schultz6addd812016-02-02 17:17:23 -07006980 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
6981 VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006982
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006983 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006984
Chia-I Wuf7458c52015-10-26 21:10:41 +08006985 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006986}
6987
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07006988TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
6989 // Create an out-of-range queueFamilyIndex
6990 m_errorMonitor->SetDesiredFailureMsg(
6991 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesde628532016-04-21 16:30:17 -06006992 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
6993 "of the indices specified when the device was created, via the "
6994 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07006995
6996 ASSERT_NO_FATAL_FAILURE(InitState());
6997 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6998 VkBufferCreateInfo buffCI = {};
6999 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7000 buffCI.size = 1024;
7001 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7002 buffCI.queueFamilyIndexCount = 1;
7003 // Introduce failure by specifying invalid queue_family_index
7004 uint32_t qfi = 777;
7005 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06007006 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007007
7008 VkBuffer ib;
7009 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
7010
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007011 m_errorMonitor->VerifyFound();
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007012}
7013
Karl Schultz6addd812016-02-02 17:17:23 -07007014TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
7015 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
7016 // secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007017
Karl Schultz6addd812016-02-02 17:17:23 -07007018 m_errorMonitor->SetDesiredFailureMsg(
7019 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007020 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007021
7022 ASSERT_NO_FATAL_FAILURE(InitState());
7023 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007024
7025 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007026 // ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007027 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
7028 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007029
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007030 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007031}
7032
Karl Schultz6addd812016-02-02 17:17:23 -07007033TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007034 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07007035 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007036
Karl Schultz6addd812016-02-02 17:17:23 -07007037 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007038 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7039 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
7040 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007041
Tobin Ehlis3b780662015-05-28 12:11:26 -06007042 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007043 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007044 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007045 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7046 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007047
7048 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007049 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7050 ds_pool_ci.pNext = NULL;
7051 ds_pool_ci.maxSets = 1;
7052 ds_pool_ci.poolSizeCount = 1;
7053 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06007054
Tobin Ehlis3b780662015-05-28 12:11:26 -06007055 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007056 err =
7057 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007058 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06007059 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007060 dsl_binding.binding = 0;
7061 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7062 dsl_binding.descriptorCount = 1;
7063 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7064 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007065
Tony Barboureb254902015-07-15 12:50:33 -06007066 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007067 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7068 ds_layout_ci.pNext = NULL;
7069 ds_layout_ci.bindingCount = 1;
7070 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007071
Tobin Ehlis3b780662015-05-28 12:11:26 -06007072 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007073 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7074 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007075 ASSERT_VK_SUCCESS(err);
7076
7077 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007078 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007079 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007080 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007081 alloc_info.descriptorPool = ds_pool;
7082 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007083 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7084 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007085 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007086
Tobin Ehlis30db8f82016-05-05 08:19:48 -06007087 VkSamplerCreateInfo sampler_ci = {};
7088 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7089 sampler_ci.pNext = NULL;
7090 sampler_ci.magFilter = VK_FILTER_NEAREST;
7091 sampler_ci.minFilter = VK_FILTER_NEAREST;
7092 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7093 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7094 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7095 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7096 sampler_ci.mipLodBias = 1.0;
7097 sampler_ci.anisotropyEnable = VK_FALSE;
7098 sampler_ci.maxAnisotropy = 1;
7099 sampler_ci.compareEnable = VK_FALSE;
7100 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7101 sampler_ci.minLod = 1.0;
7102 sampler_ci.maxLod = 1.0;
7103 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7104 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7105 VkSampler sampler;
7106 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7107 ASSERT_VK_SUCCESS(err);
7108
7109 VkDescriptorImageInfo info = {};
7110 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007111
7112 VkWriteDescriptorSet descriptor_write;
7113 memset(&descriptor_write, 0, sizeof(descriptor_write));
7114 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007115 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007116 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007117 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007118 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007119 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007120
7121 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7122
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007123 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007124
Chia-I Wuf7458c52015-10-26 21:10:41 +08007125 vkDestroySampler(m_device->device(), sampler, NULL);
7126 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7127 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007128}
7129
Karl Schultz6addd812016-02-02 17:17:23 -07007130TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007131 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07007132 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007133
Karl Schultz6addd812016-02-02 17:17:23 -07007134 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007135 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7136 " binding #0 with 1 total descriptors but update of 1 descriptors "
7137 "starting at binding offset of 0 combined with update array element "
7138 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007139
Tobin Ehlis3b780662015-05-28 12:11:26 -06007140 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007141 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007142 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007143 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7144 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007145
7146 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007147 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7148 ds_pool_ci.pNext = NULL;
7149 ds_pool_ci.maxSets = 1;
7150 ds_pool_ci.poolSizeCount = 1;
7151 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06007152
Tobin Ehlis3b780662015-05-28 12:11:26 -06007153 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007154 err =
7155 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007156 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007157
Tony Barboureb254902015-07-15 12:50:33 -06007158 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007159 dsl_binding.binding = 0;
7160 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7161 dsl_binding.descriptorCount = 1;
7162 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7163 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06007164
7165 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007166 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7167 ds_layout_ci.pNext = NULL;
7168 ds_layout_ci.bindingCount = 1;
7169 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007170
Tobin Ehlis3b780662015-05-28 12:11:26 -06007171 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007172 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7173 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007174 ASSERT_VK_SUCCESS(err);
7175
7176 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007177 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007178 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007179 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007180 alloc_info.descriptorPool = ds_pool;
7181 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007182 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7183 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007184 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007185
Tobin Ehlis30db8f82016-05-05 08:19:48 -06007186 // Correctly update descriptor to avoid "NOT_UPDATED" error
7187 VkDescriptorBufferInfo buff_info = {};
7188 buff_info.buffer =
7189 VkBuffer(0); // Don't care about buffer handle for this test
7190 buff_info.offset = 0;
7191 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007192
7193 VkWriteDescriptorSet descriptor_write;
7194 memset(&descriptor_write, 0, sizeof(descriptor_write));
7195 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007196 descriptor_write.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007197 descriptor_write.dstArrayElement =
7198 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08007199 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007200 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7201 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007202
7203 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7204
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007205 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007206
Chia-I Wuf7458c52015-10-26 21:10:41 +08007207 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7208 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007209}
7210
Karl Schultz6addd812016-02-02 17:17:23 -07007211TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
7212 // Create layout w/ count of 1 and attempt update to that layout w/ binding
7213 // index 2
7214 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007215
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7217 " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007218
Tobin Ehlis3b780662015-05-28 12:11:26 -06007219 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007220 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007221 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007222 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7223 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007224
7225 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007226 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7227 ds_pool_ci.pNext = NULL;
7228 ds_pool_ci.maxSets = 1;
7229 ds_pool_ci.poolSizeCount = 1;
7230 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06007231
Tobin Ehlis3b780662015-05-28 12:11:26 -06007232 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007233 err =
7234 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007235 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007236
Tony Barboureb254902015-07-15 12:50:33 -06007237 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007238 dsl_binding.binding = 0;
7239 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7240 dsl_binding.descriptorCount = 1;
7241 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7242 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06007243
7244 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007245 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7246 ds_layout_ci.pNext = NULL;
7247 ds_layout_ci.bindingCount = 1;
7248 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007249 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007250 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7251 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007252 ASSERT_VK_SUCCESS(err);
7253
7254 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007255 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007256 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007257 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007258 alloc_info.descriptorPool = ds_pool;
7259 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007260 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7261 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007262 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007263
Tony Barboureb254902015-07-15 12:50:33 -06007264 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007265 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7266 sampler_ci.pNext = NULL;
7267 sampler_ci.magFilter = VK_FILTER_NEAREST;
7268 sampler_ci.minFilter = VK_FILTER_NEAREST;
7269 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7270 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7271 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7272 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7273 sampler_ci.mipLodBias = 1.0;
7274 sampler_ci.anisotropyEnable = VK_FALSE;
7275 sampler_ci.maxAnisotropy = 1;
7276 sampler_ci.compareEnable = VK_FALSE;
7277 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7278 sampler_ci.minLod = 1.0;
7279 sampler_ci.maxLod = 1.0;
7280 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7281 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06007282
Tobin Ehlis3b780662015-05-28 12:11:26 -06007283 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007284 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007285 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007286
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007287 VkDescriptorImageInfo info = {};
7288 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007289
7290 VkWriteDescriptorSet descriptor_write;
7291 memset(&descriptor_write, 0, sizeof(descriptor_write));
7292 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007293 descriptor_write.dstSet = descriptorSet;
7294 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007295 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007296 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007297 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007298 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007299
7300 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7301
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007302 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007303
Chia-I Wuf7458c52015-10-26 21:10:41 +08007304 vkDestroySampler(m_device->device(), sampler, NULL);
7305 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7306 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007307}
7308
Karl Schultz6addd812016-02-02 17:17:23 -07007309TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
7310 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
7311 // types
7312 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007313
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis660bcdc2016-05-17 10:39:46 -06007315 ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007316
Tobin Ehlis3b780662015-05-28 12:11:26 -06007317 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007318
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007319 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007320 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7321 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007322
7323 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007324 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7325 ds_pool_ci.pNext = NULL;
7326 ds_pool_ci.maxSets = 1;
7327 ds_pool_ci.poolSizeCount = 1;
7328 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06007329
Tobin Ehlis3b780662015-05-28 12:11:26 -06007330 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007331 err =
7332 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007333 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06007334 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007335 dsl_binding.binding = 0;
7336 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7337 dsl_binding.descriptorCount = 1;
7338 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7339 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007340
Tony Barboureb254902015-07-15 12:50:33 -06007341 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007342 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7343 ds_layout_ci.pNext = NULL;
7344 ds_layout_ci.bindingCount = 1;
7345 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007346
Tobin Ehlis3b780662015-05-28 12:11:26 -06007347 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007348 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7349 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007350 ASSERT_VK_SUCCESS(err);
7351
7352 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007353 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007354 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007355 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007356 alloc_info.descriptorPool = ds_pool;
7357 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007358 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7359 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007360 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007361
Tony Barboureb254902015-07-15 12:50:33 -06007362 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007363 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7364 sampler_ci.pNext = NULL;
7365 sampler_ci.magFilter = VK_FILTER_NEAREST;
7366 sampler_ci.minFilter = VK_FILTER_NEAREST;
7367 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7368 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7369 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7370 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7371 sampler_ci.mipLodBias = 1.0;
7372 sampler_ci.anisotropyEnable = VK_FALSE;
7373 sampler_ci.maxAnisotropy = 1;
7374 sampler_ci.compareEnable = VK_FALSE;
7375 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7376 sampler_ci.minLod = 1.0;
7377 sampler_ci.maxLod = 1.0;
7378 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7379 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007380 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007381 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007382 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007383
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007384 VkDescriptorImageInfo info = {};
7385 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007386
7387 VkWriteDescriptorSet descriptor_write;
7388 memset(&descriptor_write, 0, sizeof(descriptor_write));
Karl Schultz6addd812016-02-02 17:17:23 -07007389 descriptor_write.sType =
7390 (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007391 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007392 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007393 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007394 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007395 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007396
7397 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7398
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007399 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007400
Chia-I Wuf7458c52015-10-26 21:10:41 +08007401 vkDestroySampler(m_device->device(), sampler, NULL);
7402 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7403 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007404}
7405
Karl Schultz6addd812016-02-02 17:17:23 -07007406TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007407 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07007408 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007409
Karl Schultz6addd812016-02-02 17:17:23 -07007410 m_errorMonitor->SetDesiredFailureMsg(
7411 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007412 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007413
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007414 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007415 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
7416 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007417 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007418 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
7419 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007420
7421 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007422 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7423 ds_pool_ci.pNext = NULL;
7424 ds_pool_ci.maxSets = 1;
7425 ds_pool_ci.poolSizeCount = 1;
7426 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007427
7428 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007429 err =
7430 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007431 ASSERT_VK_SUCCESS(err);
7432
7433 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007434 dsl_binding.binding = 0;
7435 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7436 dsl_binding.descriptorCount = 1;
7437 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7438 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007439
7440 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007441 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7442 ds_layout_ci.pNext = NULL;
7443 ds_layout_ci.bindingCount = 1;
7444 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007445 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007446 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7447 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007448 ASSERT_VK_SUCCESS(err);
7449
7450 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007451 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007452 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007453 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007454 alloc_info.descriptorPool = ds_pool;
7455 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007456 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7457 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007458 ASSERT_VK_SUCCESS(err);
7459
Karl Schultz6addd812016-02-02 17:17:23 -07007460 VkSampler sampler =
7461 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007462
7463 VkDescriptorImageInfo descriptor_info;
7464 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
7465 descriptor_info.sampler = sampler;
7466
7467 VkWriteDescriptorSet descriptor_write;
7468 memset(&descriptor_write, 0, sizeof(descriptor_write));
7469 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007470 descriptor_write.dstSet = descriptorSet;
7471 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007472 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007473 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7474 descriptor_write.pImageInfo = &descriptor_info;
7475
7476 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7477
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007478 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007479
Chia-I Wuf7458c52015-10-26 21:10:41 +08007480 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7481 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007482}
7483
Karl Schultz6addd812016-02-02 17:17:23 -07007484TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
7485 // Create a single combined Image/Sampler descriptor and send it an invalid
7486 // imageView
7487 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007488
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7490 "Attempted write update to combined "
7491 "image sampler descriptor failed due "
Tobin Ehlis63c4b8a2016-05-09 10:29:34 -06007492 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007493
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007494 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007495 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007496 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7497 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007498
7499 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007500 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7501 ds_pool_ci.pNext = NULL;
7502 ds_pool_ci.maxSets = 1;
7503 ds_pool_ci.poolSizeCount = 1;
7504 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007505
7506 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007507 err =
7508 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007509 ASSERT_VK_SUCCESS(err);
7510
7511 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007512 dsl_binding.binding = 0;
7513 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7514 dsl_binding.descriptorCount = 1;
7515 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7516 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007517
7518 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007519 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7520 ds_layout_ci.pNext = NULL;
7521 ds_layout_ci.bindingCount = 1;
7522 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007523 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007524 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7525 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007526 ASSERT_VK_SUCCESS(err);
7527
7528 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007529 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007530 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007531 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007532 alloc_info.descriptorPool = ds_pool;
7533 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007534 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7535 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007536 ASSERT_VK_SUCCESS(err);
7537
7538 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007539 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7540 sampler_ci.pNext = NULL;
7541 sampler_ci.magFilter = VK_FILTER_NEAREST;
7542 sampler_ci.minFilter = VK_FILTER_NEAREST;
7543 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7544 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7545 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7546 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7547 sampler_ci.mipLodBias = 1.0;
7548 sampler_ci.anisotropyEnable = VK_FALSE;
7549 sampler_ci.maxAnisotropy = 1;
7550 sampler_ci.compareEnable = VK_FALSE;
7551 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7552 sampler_ci.minLod = 1.0;
7553 sampler_ci.maxLod = 1.0;
7554 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7555 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007556
7557 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007558 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007559 ASSERT_VK_SUCCESS(err);
7560
Karl Schultz6addd812016-02-02 17:17:23 -07007561 VkImageView view =
7562 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007563
7564 VkDescriptorImageInfo descriptor_info;
7565 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
7566 descriptor_info.sampler = sampler;
7567 descriptor_info.imageView = view;
7568
7569 VkWriteDescriptorSet descriptor_write;
7570 memset(&descriptor_write, 0, sizeof(descriptor_write));
7571 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007572 descriptor_write.dstSet = descriptorSet;
7573 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007574 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007575 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7576 descriptor_write.pImageInfo = &descriptor_info;
7577
7578 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7579
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007580 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007581
Chia-I Wuf7458c52015-10-26 21:10:41 +08007582 vkDestroySampler(m_device->device(), sampler, NULL);
7583 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7584 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007585}
7586
Karl Schultz6addd812016-02-02 17:17:23 -07007587TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
7588 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
7589 // into the other
7590 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007591
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7593 " binding #1 with type "
7594 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
7595 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007596
Tobin Ehlis04356f92015-10-27 16:35:27 -06007597 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007598 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007599 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007600 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7601 ds_type_count[0].descriptorCount = 1;
7602 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7603 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007604
7605 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007606 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7607 ds_pool_ci.pNext = NULL;
7608 ds_pool_ci.maxSets = 1;
7609 ds_pool_ci.poolSizeCount = 2;
7610 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007611
7612 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007613 err =
7614 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007615 ASSERT_VK_SUCCESS(err);
7616 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007617 dsl_binding[0].binding = 0;
7618 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7619 dsl_binding[0].descriptorCount = 1;
7620 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7621 dsl_binding[0].pImmutableSamplers = NULL;
7622 dsl_binding[1].binding = 1;
7623 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7624 dsl_binding[1].descriptorCount = 1;
7625 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7626 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007627
7628 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007629 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7630 ds_layout_ci.pNext = NULL;
7631 ds_layout_ci.bindingCount = 2;
7632 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007633
7634 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007635 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7636 &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007637 ASSERT_VK_SUCCESS(err);
7638
7639 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007640 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007641 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007642 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007643 alloc_info.descriptorPool = ds_pool;
7644 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007645 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7646 &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007647 ASSERT_VK_SUCCESS(err);
7648
7649 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007650 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7651 sampler_ci.pNext = NULL;
7652 sampler_ci.magFilter = VK_FILTER_NEAREST;
7653 sampler_ci.minFilter = VK_FILTER_NEAREST;
7654 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7655 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7656 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7657 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7658 sampler_ci.mipLodBias = 1.0;
7659 sampler_ci.anisotropyEnable = VK_FALSE;
7660 sampler_ci.maxAnisotropy = 1;
7661 sampler_ci.compareEnable = VK_FALSE;
7662 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7663 sampler_ci.minLod = 1.0;
7664 sampler_ci.maxLod = 1.0;
7665 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7666 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007667
7668 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007669 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007670 ASSERT_VK_SUCCESS(err);
7671
7672 VkDescriptorImageInfo info = {};
7673 info.sampler = sampler;
7674
7675 VkWriteDescriptorSet descriptor_write;
7676 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
7677 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007678 descriptor_write.dstSet = descriptorSet;
7679 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08007680 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007681 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7682 descriptor_write.pImageInfo = &info;
7683 // This write update should succeed
7684 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7685 // Now perform a copy update that fails due to type mismatch
7686 VkCopyDescriptorSet copy_ds_update;
7687 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
7688 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
7689 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06007690 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007691 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007692 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08007693 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06007694 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
7695
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007696 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06007697 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07007698 m_errorMonitor->SetDesiredFailureMsg(
7699 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007700 " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -06007701 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
7702 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
7703 copy_ds_update.srcSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007704 copy_ds_update.srcBinding =
7705 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007706 copy_ds_update.dstSet = descriptorSet;
7707 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06007708 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06007709 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
7710
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007711 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007712
Tobin Ehlis04356f92015-10-27 16:35:27 -06007713 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07007714 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007715 VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
7716 "update array offset of 0 and update of "
7717 "5 descriptors oversteps total number "
7718 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007719
Tobin Ehlis04356f92015-10-27 16:35:27 -06007720 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
7721 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
7722 copy_ds_update.srcSet = descriptorSet;
7723 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007724 copy_ds_update.dstSet = descriptorSet;
7725 copy_ds_update.dstBinding = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007726 copy_ds_update.descriptorCount =
7727 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06007728 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
7729
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007730 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06007731
Chia-I Wuf7458c52015-10-26 21:10:41 +08007732 vkDestroySampler(m_device->device(), sampler, NULL);
7733 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7734 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007735}
7736
Karl Schultz6addd812016-02-02 17:17:23 -07007737TEST_F(VkLayerTest, NumSamplesMismatch) {
7738 // Create CommandBuffer where MSAA samples doesn't match RenderPass
7739 // sampleCount
7740 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007741
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007743 "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007744
Tobin Ehlis3b780662015-05-28 12:11:26 -06007745 ASSERT_NO_FATAL_FAILURE(InitState());
7746 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007747 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06007748 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007749 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007750
7751 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007752 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7753 ds_pool_ci.pNext = NULL;
7754 ds_pool_ci.maxSets = 1;
7755 ds_pool_ci.poolSizeCount = 1;
7756 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06007757
Tobin Ehlis3b780662015-05-28 12:11:26 -06007758 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007759 err =
7760 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007761 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007762
Tony Barboureb254902015-07-15 12:50:33 -06007763 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007764 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06007765 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007766 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007767 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7768 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007769
Tony Barboureb254902015-07-15 12:50:33 -06007770 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7771 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7772 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007773 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007774 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007775
Tobin Ehlis3b780662015-05-28 12:11:26 -06007776 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007777 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7778 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007779 ASSERT_VK_SUCCESS(err);
7780
7781 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007782 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007783 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007784 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007785 alloc_info.descriptorPool = ds_pool;
7786 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007787 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7788 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007789 ASSERT_VK_SUCCESS(err);
7790
Tony Barboureb254902015-07-15 12:50:33 -06007791 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007792 pipe_ms_state_ci.sType =
7793 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7794 pipe_ms_state_ci.pNext = NULL;
7795 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7796 pipe_ms_state_ci.sampleShadingEnable = 0;
7797 pipe_ms_state_ci.minSampleShading = 1.0;
7798 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007799
Tony Barboureb254902015-07-15 12:50:33 -06007800 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007801 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7802 pipeline_layout_ci.pNext = NULL;
7803 pipeline_layout_ci.setLayoutCount = 1;
7804 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007805
7806 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007807 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7808 &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007809 ASSERT_VK_SUCCESS(err);
7810
Karl Schultz6addd812016-02-02 17:17:23 -07007811 VkShaderObj vs(m_device, bindStateVertShaderText,
7812 VK_SHADER_STAGE_VERTEX_BIT, this);
7813 VkShaderObj fs(m_device, bindStateFragShaderText,
7814 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06007815 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07007816 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06007817 VkPipelineObj pipe(m_device);
7818 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007819 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06007820 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06007821 pipe.SetMSAA(&pipe_ms_state_ci);
7822 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06007823
Tony Barbourfe3351b2015-07-28 10:17:20 -06007824 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007825 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7826 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06007827
Mark Young29927482016-05-04 14:38:51 -06007828 // Render triangle (the error should trigger on the attempt to draw).
7829 Draw(3, 1, 0, 0);
7830
7831 // Finalize recording of the command buffer
7832 EndCommandBuffer();
7833
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007834 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007835
Chia-I Wuf7458c52015-10-26 21:10:41 +08007836 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7837 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7838 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007839}
Mark Young29927482016-05-04 14:38:51 -06007840
Mark Youngc89c6312016-03-31 16:03:20 -06007841TEST_F(VkLayerTest, NumBlendAttachMismatch) {
7842 // Create Pipeline where the number of blend attachments doesn't match the
7843 // number of color attachments. In this case, we don't add any color
7844 // blend attachments even though we have a color attachment.
7845 VkResult err;
7846
7847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young29927482016-05-04 14:38:51 -06007848 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06007849
7850 ASSERT_NO_FATAL_FAILURE(InitState());
7851 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7852 VkDescriptorPoolSize ds_type_count = {};
7853 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7854 ds_type_count.descriptorCount = 1;
7855
7856 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7857 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7858 ds_pool_ci.pNext = NULL;
7859 ds_pool_ci.maxSets = 1;
7860 ds_pool_ci.poolSizeCount = 1;
7861 ds_pool_ci.pPoolSizes = &ds_type_count;
7862
7863 VkDescriptorPool ds_pool;
7864 err =
7865 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7866 ASSERT_VK_SUCCESS(err);
7867
7868 VkDescriptorSetLayoutBinding dsl_binding = {};
7869 dsl_binding.binding = 0;
7870 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7871 dsl_binding.descriptorCount = 1;
7872 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7873 dsl_binding.pImmutableSamplers = NULL;
7874
7875 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7876 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7877 ds_layout_ci.pNext = NULL;
7878 ds_layout_ci.bindingCount = 1;
7879 ds_layout_ci.pBindings = &dsl_binding;
7880
7881 VkDescriptorSetLayout ds_layout;
7882 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7883 &ds_layout);
7884 ASSERT_VK_SUCCESS(err);
7885
7886 VkDescriptorSet descriptorSet;
7887 VkDescriptorSetAllocateInfo alloc_info = {};
7888 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7889 alloc_info.descriptorSetCount = 1;
7890 alloc_info.descriptorPool = ds_pool;
7891 alloc_info.pSetLayouts = &ds_layout;
7892 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7893 &descriptorSet);
7894 ASSERT_VK_SUCCESS(err);
7895
7896 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7897 pipe_ms_state_ci.sType =
7898 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7899 pipe_ms_state_ci.pNext = NULL;
7900 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7901 pipe_ms_state_ci.sampleShadingEnable = 0;
7902 pipe_ms_state_ci.minSampleShading = 1.0;
7903 pipe_ms_state_ci.pSampleMask = NULL;
7904
7905 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7906 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7907 pipeline_layout_ci.pNext = NULL;
7908 pipeline_layout_ci.setLayoutCount = 1;
7909 pipeline_layout_ci.pSetLayouts = &ds_layout;
7910
7911 VkPipelineLayout pipeline_layout;
7912 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7913 &pipeline_layout);
7914 ASSERT_VK_SUCCESS(err);
7915
7916 VkShaderObj vs(m_device, bindStateVertShaderText,
7917 VK_SHADER_STAGE_VERTEX_BIT, this);
7918 VkShaderObj fs(m_device, bindStateFragShaderText,
7919 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06007920 this); // We shouldn't need a fragment shader
Mark Youngc89c6312016-03-31 16:03:20 -06007921 // but add it to be able to run on more devices
7922 VkPipelineObj pipe(m_device);
7923 pipe.AddShader(&vs);
7924 pipe.AddShader(&fs);
7925 pipe.SetMSAA(&pipe_ms_state_ci);
7926 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7927
7928 BeginCommandBuffer();
7929 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7930 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7931
Mark Young29927482016-05-04 14:38:51 -06007932 // Render triangle (the error should trigger on the attempt to draw).
7933 Draw(3, 1, 0, 0);
7934
7935 // Finalize recording of the command buffer
7936 EndCommandBuffer();
7937
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007938 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06007939
7940 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7941 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7942 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7943}
Mark Young29927482016-05-04 14:38:51 -06007944
Karl Schultz6addd812016-02-02 17:17:23 -07007945TEST_F(VkLayerTest, ClearCmdNoDraw) {
7946 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
7947 // to issuing a Draw
7948 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007949
Karl Schultz6addd812016-02-02 17:17:23 -07007950 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbour7e56d302016-03-02 15:12:01 -07007951 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007952 "vkCmdClearAttachments() issued on CB object ");
7953
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007954 ASSERT_NO_FATAL_FAILURE(InitState());
7955 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06007956
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007957 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007958 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7959 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007960
7961 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007962 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7963 ds_pool_ci.pNext = NULL;
7964 ds_pool_ci.maxSets = 1;
7965 ds_pool_ci.poolSizeCount = 1;
7966 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06007967
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007968 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007969 err =
7970 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007971 ASSERT_VK_SUCCESS(err);
7972
Tony Barboureb254902015-07-15 12:50:33 -06007973 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007974 dsl_binding.binding = 0;
7975 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7976 dsl_binding.descriptorCount = 1;
7977 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7978 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007979
Tony Barboureb254902015-07-15 12:50:33 -06007980 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007981 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7982 ds_layout_ci.pNext = NULL;
7983 ds_layout_ci.bindingCount = 1;
7984 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007985
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007986 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007987 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7988 &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007989 ASSERT_VK_SUCCESS(err);
7990
7991 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007992 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007993 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007994 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007995 alloc_info.descriptorPool = ds_pool;
7996 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007997 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7998 &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007999 ASSERT_VK_SUCCESS(err);
8000
Tony Barboureb254902015-07-15 12:50:33 -06008001 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008002 pipe_ms_state_ci.sType =
8003 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8004 pipe_ms_state_ci.pNext = NULL;
8005 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8006 pipe_ms_state_ci.sampleShadingEnable = 0;
8007 pipe_ms_state_ci.minSampleShading = 1.0;
8008 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008009
Tony Barboureb254902015-07-15 12:50:33 -06008010 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008011 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8012 pipeline_layout_ci.pNext = NULL;
8013 pipeline_layout_ci.setLayoutCount = 1;
8014 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008015
8016 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008017 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8018 &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008019 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008020
Karl Schultz6addd812016-02-02 17:17:23 -07008021 VkShaderObj vs(m_device, bindStateVertShaderText,
8022 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06008023 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07008024 // on more devices
8025 VkShaderObj fs(m_device, bindStateFragShaderText,
8026 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008027
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008028 VkPipelineObj pipe(m_device);
8029 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008030 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008031 pipe.SetMSAA(&pipe_ms_state_ci);
8032 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06008033
8034 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008035
Karl Schultz6addd812016-02-02 17:17:23 -07008036 // Main thing we care about for this test is that the VkImage obj we're
8037 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008038 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008039 VkClearAttachment color_attachment;
8040 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8041 color_attachment.clearValue.color.float32[0] = 1.0;
8042 color_attachment.clearValue.color.float32[1] = 1.0;
8043 color_attachment.clearValue.color.float32[2] = 1.0;
8044 color_attachment.clearValue.color.float32[3] = 1.0;
8045 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008046 VkClearRect clear_rect = {
8047 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008048
Karl Schultz6addd812016-02-02 17:17:23 -07008049 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
8050 &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008051
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008052 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008053
Chia-I Wuf7458c52015-10-26 21:10:41 +08008054 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8055 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8056 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008057}
8058
Karl Schultz6addd812016-02-02 17:17:23 -07008059TEST_F(VkLayerTest, VtxBufferBadIndex) {
8060 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008061
Karl Schultz6addd812016-02-02 17:17:23 -07008062 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008063 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07008064 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008065
Tobin Ehlis502480b2015-06-24 15:53:07 -06008066 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06008067 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06008068 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06008069
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008070 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008071 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8072 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008073
8074 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008075 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8076 ds_pool_ci.pNext = NULL;
8077 ds_pool_ci.maxSets = 1;
8078 ds_pool_ci.poolSizeCount = 1;
8079 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008080
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008081 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008082 err =
8083 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008084 ASSERT_VK_SUCCESS(err);
8085
Tony Barboureb254902015-07-15 12:50:33 -06008086 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008087 dsl_binding.binding = 0;
8088 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8089 dsl_binding.descriptorCount = 1;
8090 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8091 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008092
Tony Barboureb254902015-07-15 12:50:33 -06008093 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008094 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8095 ds_layout_ci.pNext = NULL;
8096 ds_layout_ci.bindingCount = 1;
8097 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008098
Tobin Ehlis502480b2015-06-24 15:53:07 -06008099 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008100 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8101 &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008102 ASSERT_VK_SUCCESS(err);
8103
8104 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008105 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008106 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008107 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008108 alloc_info.descriptorPool = ds_pool;
8109 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008110 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8111 &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008112 ASSERT_VK_SUCCESS(err);
8113
Tony Barboureb254902015-07-15 12:50:33 -06008114 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008115 pipe_ms_state_ci.sType =
8116 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8117 pipe_ms_state_ci.pNext = NULL;
8118 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8119 pipe_ms_state_ci.sampleShadingEnable = 0;
8120 pipe_ms_state_ci.minSampleShading = 1.0;
8121 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008122
Tony Barboureb254902015-07-15 12:50:33 -06008123 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008124 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8125 pipeline_layout_ci.pNext = NULL;
8126 pipeline_layout_ci.setLayoutCount = 1;
8127 pipeline_layout_ci.pSetLayouts = &ds_layout;
8128 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008129
Karl Schultz6addd812016-02-02 17:17:23 -07008130 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8131 &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008132 ASSERT_VK_SUCCESS(err);
8133
Karl Schultz6addd812016-02-02 17:17:23 -07008134 VkShaderObj vs(m_device, bindStateVertShaderText,
8135 VK_SHADER_STAGE_VERTEX_BIT, this);
8136 VkShaderObj fs(m_device, bindStateFragShaderText,
8137 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06008138 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07008139 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008140 VkPipelineObj pipe(m_device);
8141 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008142 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06008143 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008144 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008145 pipe.SetViewport(m_viewports);
8146 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008147 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06008148
8149 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008150 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8151 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06008152 // Don't care about actual data, just need to get to draw to flag error
8153 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz6addd812016-02-02 17:17:23 -07008154 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
8155 (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06008156 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06008157 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008158
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008159 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008160
Chia-I Wuf7458c52015-10-26 21:10:41 +08008161 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8162 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8163 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008164}
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06008165// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
8166TEST_F(VkLayerTest, InvalidImageLayout) {
8167 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
8168 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
8169 "images in the wrong layout when they're copied or transitioned.");
8170 // 3 in ValidateCmdBufImageLayouts
8171 // * -1 Attempt to submit cmd buf w/ deleted image
8172 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
8173 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
8174 m_errorMonitor->SetDesiredFailureMsg(
8175 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8176 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
8177
8178 ASSERT_NO_FATAL_FAILURE(InitState());
8179 // Create src & dst images to use for copy operations
8180 VkImage src_image;
8181 VkImage dst_image;
8182
8183 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8184 const int32_t tex_width = 32;
8185 const int32_t tex_height = 32;
8186
8187 VkImageCreateInfo image_create_info = {};
8188 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8189 image_create_info.pNext = NULL;
8190 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8191 image_create_info.format = tex_format;
8192 image_create_info.extent.width = tex_width;
8193 image_create_info.extent.height = tex_height;
8194 image_create_info.extent.depth = 1;
8195 image_create_info.mipLevels = 1;
8196 image_create_info.arrayLayers = 4;
8197 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8198 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8199 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8200 image_create_info.flags = 0;
8201
8202 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
8203 ASSERT_VK_SUCCESS(err);
8204 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
8205 ASSERT_VK_SUCCESS(err);
8206
8207 BeginCommandBuffer();
8208 VkImageCopy copyRegion;
8209 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8210 copyRegion.srcSubresource.mipLevel = 0;
8211 copyRegion.srcSubresource.baseArrayLayer = 0;
8212 copyRegion.srcSubresource.layerCount = 1;
8213 copyRegion.srcOffset.x = 0;
8214 copyRegion.srcOffset.y = 0;
8215 copyRegion.srcOffset.z = 0;
8216 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8217 copyRegion.dstSubresource.mipLevel = 0;
8218 copyRegion.dstSubresource.baseArrayLayer = 0;
8219 copyRegion.dstSubresource.layerCount = 1;
8220 copyRegion.dstOffset.x = 0;
8221 copyRegion.dstOffset.y = 0;
8222 copyRegion.dstOffset.z = 0;
8223 copyRegion.extent.width = 1;
8224 copyRegion.extent.height = 1;
8225 copyRegion.extent.depth = 1;
8226 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8227 m_errorMonitor->VerifyFound();
8228 // Now cause error due to src image layout changing
8229 m_errorMonitor->SetDesiredFailureMsg(
8230 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8231 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
8232 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8233 m_errorMonitor->VerifyFound();
8234 // Final src error is due to bad layout type
8235 m_errorMonitor->SetDesiredFailureMsg(
8236 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8237 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
8238 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8239 m_errorMonitor->VerifyFound();
8240 // Now verify same checks for dst
8241 m_errorMonitor->SetDesiredFailureMsg(
8242 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8243 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
8244 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8245 m_errorMonitor->VerifyFound();
8246 // Now cause error due to src image layout changing
8247 m_errorMonitor->SetDesiredFailureMsg(
8248 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8249 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
8250 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
8251 m_errorMonitor->VerifyFound();
8252 m_errorMonitor->SetDesiredFailureMsg(
8253 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8254 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
8255 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
8256 m_errorMonitor->VerifyFound();
8257 // Now cause error due to bad image layout transition in PipelineBarrier
8258 VkImageMemoryBarrier image_barrier[1] = {};
8259 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
8260 image_barrier[0].image = src_image;
8261 image_barrier[0].subresourceRange.layerCount = 2;
8262 image_barrier[0].subresourceRange.levelCount = 2;
8263 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8264 m_errorMonitor->SetDesiredFailureMsg(
8265 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8266 "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL.");
8267 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier);
8268 m_errorMonitor->VerifyFound();
8269
8270 // Finally some layout errors at RenderPass create time
8271 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
8272 VkAttachmentReference attach = {};
8273 // perf warning for GENERAL layout w/ non-DS input attachment
8274 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8275 VkSubpassDescription subpass = {};
8276 subpass.inputAttachmentCount = 1;
8277 subpass.pInputAttachments = &attach;
8278 VkRenderPassCreateInfo rpci = {};
8279 rpci.subpassCount = 1;
8280 rpci.pSubpasses = &subpass;
8281 rpci.attachmentCount = 1;
8282 VkAttachmentDescription attach_desc = {};
8283 attach_desc.format = VK_FORMAT_UNDEFINED;
8284 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -06008285 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06008286 VkRenderPass rp;
8287 m_errorMonitor->SetDesiredFailureMsg(
8288 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8289 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
8290 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8291 m_errorMonitor->VerifyFound();
8292 // error w/ non-general layout
8293 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
8294
8295 m_errorMonitor->SetDesiredFailureMsg(
8296 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8297 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
8298 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8299 m_errorMonitor->VerifyFound();
8300 subpass.inputAttachmentCount = 0;
8301 subpass.colorAttachmentCount = 1;
8302 subpass.pColorAttachments = &attach;
8303 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8304 // perf warning for GENERAL layout on color attachment
8305 m_errorMonitor->SetDesiredFailureMsg(
8306 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8307 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
8308 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8309 m_errorMonitor->VerifyFound();
8310 // error w/ non-color opt or GENERAL layout for color attachment
8311 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
8312 m_errorMonitor->SetDesiredFailureMsg(
8313 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8314 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
8315 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8316 m_errorMonitor->VerifyFound();
8317 subpass.colorAttachmentCount = 0;
8318 subpass.pDepthStencilAttachment = &attach;
8319 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8320 // perf warning for GENERAL layout on DS attachment
8321 m_errorMonitor->SetDesiredFailureMsg(
8322 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8323 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
8324 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8325 m_errorMonitor->VerifyFound();
8326 // error w/ non-ds opt or GENERAL layout for color attachment
8327 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
8328 m_errorMonitor->SetDesiredFailureMsg(
8329 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8330 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.");
8331 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8332 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -06008333 // For this error we need a valid renderpass so create default one
8334 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
8335 attach.attachment = 0;
8336 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
8337 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
8338 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
8339 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
8340 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
8341 // Can't do a CLEAR load on READ_ONLY initialLayout
8342 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8343 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
8344 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8346 " with invalid first layout "
8347 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
8348 "ONLY_OPTIMAL");
8349 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8350 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06008351
8352 vkDestroyImage(m_device->device(), src_image, NULL);
8353 vkDestroyImage(m_device->device(), dst_image, NULL);
8354}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008355#endif // DRAW_STATE_TESTS
8356
Tobin Ehlis0788f522015-05-26 16:11:58 -06008357#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06008358#if GTEST_IS_THREADSAFE
8359struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008360 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008361 VkEvent event;
8362 bool bailout;
8363};
8364
Karl Schultz6addd812016-02-02 17:17:23 -07008365extern "C" void *AddToCommandBuffer(void *arg) {
8366 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008367
Karl Schultz6addd812016-02-02 17:17:23 -07008368 for (int i = 0; i < 10000; i++) {
8369 vkCmdSetEvent(data->commandBuffer, data->event,
8370 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008371 if (data->bailout) {
8372 break;
8373 }
8374 }
8375 return NULL;
8376}
8377
Karl Schultz6addd812016-02-02 17:17:23 -07008378TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -06008379 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008380
Karl Schultz6addd812016-02-02 17:17:23 -07008381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8382 "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008383
Mike Stroyanaccf7692015-05-12 16:00:45 -06008384 ASSERT_NO_FATAL_FAILURE(InitState());
8385 ASSERT_NO_FATAL_FAILURE(InitViewport());
8386 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8387
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008388 // Calls AllocateCommandBuffers
8389 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06008390
8391 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008392 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008393
8394 VkEventCreateInfo event_info;
8395 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008396 VkResult err;
8397
8398 memset(&event_info, 0, sizeof(event_info));
8399 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8400
Chia-I Wuf7458c52015-10-26 21:10:41 +08008401 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008402 ASSERT_VK_SUCCESS(err);
8403
Mike Stroyanaccf7692015-05-12 16:00:45 -06008404 err = vkResetEvent(device(), event);
8405 ASSERT_VK_SUCCESS(err);
8406
8407 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008408 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008409 data.event = event;
8410 data.bailout = false;
8411 m_errorMonitor->SetBailout(&data.bailout);
8412 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06008413 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008414 // Add many entries to command buffer from this thread at the same time.
8415 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06008416
Mike Stroyan4268d1f2015-07-13 14:45:35 -06008417 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008418 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008419
Mike Stroyan10b8cb72016-01-22 15:22:03 -07008420 m_errorMonitor->SetBailout(NULL);
8421
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008422 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008423
Chia-I Wuf7458c52015-10-26 21:10:41 +08008424 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008425}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008426#endif // GTEST_IS_THREADSAFE
8427#endif // THREADING_TESTS
8428
Chris Forbes9f7ff632015-05-25 11:13:08 +12008429#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07008430TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008432 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008433
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008434 ASSERT_NO_FATAL_FAILURE(InitState());
8435 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8436
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008437 VkShaderModule module;
8438 VkShaderModuleCreateInfo moduleCreateInfo;
8439 struct icd_spv_header spv;
8440
8441 spv.magic = ICD_SPV_MAGIC;
8442 spv.version = ICD_SPV_VERSION;
8443 spv.gen_magic = 0;
8444
8445 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
8446 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07008447 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008448 moduleCreateInfo.codeSize = 4;
8449 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008450 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008451
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008452 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008453}
8454
Karl Schultz6addd812016-02-02 17:17:23 -07008455TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008457 "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008458
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008459 ASSERT_NO_FATAL_FAILURE(InitState());
8460 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8461
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008462 VkShaderModule module;
8463 VkShaderModuleCreateInfo moduleCreateInfo;
8464 struct icd_spv_header spv;
8465
8466 spv.magic = ~ICD_SPV_MAGIC;
8467 spv.version = ICD_SPV_VERSION;
8468 spv.gen_magic = 0;
8469
8470 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
8471 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07008472 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008473 moduleCreateInfo.codeSize = sizeof(spv) + 10;
8474 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008475 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008476
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008477 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008478}
8479
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008480#if 0
8481// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -07008482TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008484 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008485
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008486 ASSERT_NO_FATAL_FAILURE(InitState());
8487 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8488
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008489 VkShaderModule module;
8490 VkShaderModuleCreateInfo moduleCreateInfo;
8491 struct icd_spv_header spv;
8492
8493 spv.magic = ICD_SPV_MAGIC;
8494 spv.version = ~ICD_SPV_VERSION;
8495 spv.gen_magic = 0;
8496
8497 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
8498 moduleCreateInfo.pNext = NULL;
8499
Karl Schultz6addd812016-02-02 17:17:23 -07008500 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008501 moduleCreateInfo.codeSize = sizeof(spv) + 10;
8502 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008503 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008504
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008505 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008506}
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008507#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008508
Karl Schultz6addd812016-02-02 17:17:23 -07008509TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008511 "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008512
Chris Forbes9f7ff632015-05-25 11:13:08 +12008513 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008514 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12008515
8516 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008517 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12008518 "\n"
8519 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07008520 "out gl_PerVertex {\n"
8521 " vec4 gl_Position;\n"
8522 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12008523 "void main(){\n"
8524 " gl_Position = vec4(1);\n"
8525 " x = 0;\n"
8526 "}\n";
8527 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008528 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12008529 "\n"
8530 "layout(location=0) out vec4 color;\n"
8531 "void main(){\n"
8532 " color = vec4(1);\n"
8533 "}\n";
8534
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008535 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8536 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12008537
8538 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008539 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12008540 pipe.AddShader(&vs);
8541 pipe.AddShader(&fs);
8542
Chris Forbes9f7ff632015-05-25 11:13:08 +12008543 VkDescriptorSetObj descriptorSet(m_device);
8544 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008545 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12008546
Tony Barbour5781e8f2015-08-04 16:23:11 -06008547 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12008548
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008549 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +12008550}
Chris Forbes9f7ff632015-05-25 11:13:08 +12008551
Karl Schultz6addd812016-02-02 17:17:23 -07008552TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008554 "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008555
Chris Forbes59cb88d2015-05-25 11:13:13 +12008556 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008557 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12008558
8559 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008560 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12008561 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07008562 "out gl_PerVertex {\n"
8563 " vec4 gl_Position;\n"
8564 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12008565 "void main(){\n"
8566 " gl_Position = vec4(1);\n"
8567 "}\n";
8568 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008569 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12008570 "\n"
8571 "layout(location=0) in float x;\n"
8572 "layout(location=0) out vec4 color;\n"
8573 "void main(){\n"
8574 " color = vec4(x);\n"
8575 "}\n";
8576
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008577 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8578 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12008579
8580 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008581 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12008582 pipe.AddShader(&vs);
8583 pipe.AddShader(&fs);
8584
Chris Forbes59cb88d2015-05-25 11:13:13 +12008585 VkDescriptorSetObj descriptorSet(m_device);
8586 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008587 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12008588
Tony Barbour5781e8f2015-08-04 16:23:11 -06008589 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12008590
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008591 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +12008592}
8593
Karl Schultz6addd812016-02-02 17:17:23 -07008594TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13008595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008596 "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +13008597
8598 ASSERT_NO_FATAL_FAILURE(InitState());
8599 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8600
8601 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008602 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008603 "\n"
8604 "out gl_PerVertex {\n"
8605 " vec4 gl_Position;\n"
8606 "};\n"
8607 "void main(){\n"
8608 " gl_Position = vec4(1);\n"
8609 "}\n";
8610 char const *fsSource =
8611 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008612 "\n"
8613 "in block { layout(location=0) float x; } ins;\n"
8614 "layout(location=0) out vec4 color;\n"
8615 "void main(){\n"
8616 " color = vec4(ins.x);\n"
8617 "}\n";
8618
8619 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8620 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8621
8622 VkPipelineObj pipe(m_device);
8623 pipe.AddColorAttachment();
8624 pipe.AddShader(&vs);
8625 pipe.AddShader(&fs);
8626
8627 VkDescriptorSetObj descriptorSet(m_device);
8628 descriptorSet.AppendDummy();
8629 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8630
8631 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8632
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008633 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13008634}
8635
Karl Schultz6addd812016-02-02 17:17:23 -07008636TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes0036fd12016-01-26 14:19:49 +13008637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbese9928822016-02-17 14:44:52 +13008638 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz6addd812016-02-02 17:17:23 -07008639 "output arr[2] of float32' vs 'ptr to "
8640 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +13008641
8642 ASSERT_NO_FATAL_FAILURE(InitState());
8643 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8644
8645 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008646 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13008647 "\n"
8648 "layout(location=0) out float x[2];\n"
8649 "out gl_PerVertex {\n"
8650 " vec4 gl_Position;\n"
8651 "};\n"
8652 "void main(){\n"
8653 " x[0] = 0; x[1] = 0;\n"
8654 " gl_Position = vec4(1);\n"
8655 "}\n";
8656 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008657 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13008658 "\n"
8659 "layout(location=0) in float x[3];\n"
8660 "layout(location=0) out vec4 color;\n"
8661 "void main(){\n"
8662 " color = vec4(x[0] + x[1] + x[2]);\n"
8663 "}\n";
8664
8665 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8666 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8667
8668 VkPipelineObj pipe(m_device);
8669 pipe.AddColorAttachment();
8670 pipe.AddShader(&vs);
8671 pipe.AddShader(&fs);
8672
8673 VkDescriptorSetObj descriptorSet(m_device);
8674 descriptorSet.AppendDummy();
8675 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8676
8677 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8678
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008679 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +13008680}
8681
Karl Schultz6addd812016-02-02 17:17:23 -07008682TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008684 "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008685
Chris Forbesb56af562015-05-25 11:13:17 +12008686 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008687 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12008688
8689 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008690 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12008691 "\n"
8692 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07008693 "out gl_PerVertex {\n"
8694 " vec4 gl_Position;\n"
8695 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12008696 "void main(){\n"
8697 " x = 0;\n"
8698 " gl_Position = vec4(1);\n"
8699 "}\n";
8700 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008701 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12008702 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008703 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbesb56af562015-05-25 11:13:17 +12008704 "layout(location=0) out vec4 color;\n"
8705 "void main(){\n"
8706 " color = vec4(x);\n"
8707 "}\n";
8708
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008709 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8710 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12008711
8712 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008713 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12008714 pipe.AddShader(&vs);
8715 pipe.AddShader(&fs);
8716
Chris Forbesb56af562015-05-25 11:13:17 +12008717 VkDescriptorSetObj descriptorSet(m_device);
8718 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008719 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12008720
Tony Barbour5781e8f2015-08-04 16:23:11 -06008721 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12008722
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008723 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +12008724}
8725
Karl Schultz6addd812016-02-02 17:17:23 -07008726TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13008727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008728 "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +13008729
8730 ASSERT_NO_FATAL_FAILURE(InitState());
8731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8732
8733 char const *vsSource =
8734 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008735 "\n"
8736 "out block { layout(location=0) int x; } outs;\n"
8737 "out gl_PerVertex {\n"
8738 " vec4 gl_Position;\n"
8739 "};\n"
8740 "void main(){\n"
8741 " outs.x = 0;\n"
8742 " gl_Position = vec4(1);\n"
8743 "}\n";
8744 char const *fsSource =
8745 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008746 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008747 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbesa3e85f62016-01-15 14:53:11 +13008748 "layout(location=0) out vec4 color;\n"
8749 "void main(){\n"
8750 " color = vec4(ins.x);\n"
8751 "}\n";
8752
8753 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8754 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8755
8756 VkPipelineObj pipe(m_device);
8757 pipe.AddColorAttachment();
8758 pipe.AddShader(&vs);
8759 pipe.AddShader(&fs);
8760
8761 VkDescriptorSetObj descriptorSet(m_device);
8762 descriptorSet.AppendDummy();
8763 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8764
8765 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8766
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008767 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13008768}
8769
8770TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
8771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8772 "location 0.0 which is not written by vertex shader");
8773
8774 ASSERT_NO_FATAL_FAILURE(InitState());
8775 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8776
8777 char const *vsSource =
8778 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008779 "\n"
8780 "out block { layout(location=1) float x; } outs;\n"
8781 "out gl_PerVertex {\n"
8782 " vec4 gl_Position;\n"
8783 "};\n"
8784 "void main(){\n"
8785 " outs.x = 0;\n"
8786 " gl_Position = vec4(1);\n"
8787 "}\n";
8788 char const *fsSource =
8789 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008790 "\n"
8791 "in block { layout(location=0) float x; } ins;\n"
8792 "layout(location=0) out vec4 color;\n"
8793 "void main(){\n"
8794 " color = vec4(ins.x);\n"
8795 "}\n";
8796
8797 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8798 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8799
8800 VkPipelineObj pipe(m_device);
8801 pipe.AddColorAttachment();
8802 pipe.AddShader(&vs);
8803 pipe.AddShader(&fs);
8804
8805 VkDescriptorSetObj descriptorSet(m_device);
8806 descriptorSet.AppendDummy();
8807 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8808
8809 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8810
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008811 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13008812}
8813
8814TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
8815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8816 "location 0.1 which is not written by vertex shader");
8817
8818 ASSERT_NO_FATAL_FAILURE(InitState());
8819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8820
8821 char const *vsSource =
8822 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008823 "\n"
8824 "out block { layout(location=0, component=0) float x; } outs;\n"
8825 "out gl_PerVertex {\n"
8826 " vec4 gl_Position;\n"
8827 "};\n"
8828 "void main(){\n"
8829 " outs.x = 0;\n"
8830 " gl_Position = vec4(1);\n"
8831 "}\n";
8832 char const *fsSource =
8833 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008834 "\n"
8835 "in block { layout(location=0, component=1) float x; } ins;\n"
8836 "layout(location=0) out vec4 color;\n"
8837 "void main(){\n"
8838 " color = vec4(ins.x);\n"
8839 "}\n";
8840
8841 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8842 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8843
8844 VkPipelineObj pipe(m_device);
8845 pipe.AddColorAttachment();
8846 pipe.AddShader(&vs);
8847 pipe.AddShader(&fs);
8848
8849 VkDescriptorSetObj descriptorSet(m_device);
8850 descriptorSet.AppendDummy();
8851 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8852
8853 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8854
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008855 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13008856}
8857
Karl Schultz6addd812016-02-02 17:17:23 -07008858TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008860 "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008861
Chris Forbesde136e02015-05-25 11:13:28 +12008862 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008863 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12008864
8865 VkVertexInputBindingDescription input_binding;
8866 memset(&input_binding, 0, sizeof(input_binding));
8867
8868 VkVertexInputAttributeDescription input_attrib;
8869 memset(&input_attrib, 0, sizeof(input_attrib));
8870 input_attrib.format = VK_FORMAT_R32_SFLOAT;
8871
8872 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008873 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12008874 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07008875 "out gl_PerVertex {\n"
8876 " vec4 gl_Position;\n"
8877 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +12008878 "void main(){\n"
8879 " gl_Position = vec4(1);\n"
8880 "}\n";
8881 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008882 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12008883 "\n"
8884 "layout(location=0) out vec4 color;\n"
8885 "void main(){\n"
8886 " color = vec4(1);\n"
8887 "}\n";
8888
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008889 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8890 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12008891
8892 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008893 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12008894 pipe.AddShader(&vs);
8895 pipe.AddShader(&fs);
8896
8897 pipe.AddVertexInputBindings(&input_binding, 1);
8898 pipe.AddVertexInputAttribs(&input_attrib, 1);
8899
Chris Forbesde136e02015-05-25 11:13:28 +12008900 VkDescriptorSetObj descriptorSet(m_device);
8901 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008902 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12008903
Tony Barbour5781e8f2015-08-04 16:23:11 -06008904 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12008905
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008906 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +12008907}
8908
Karl Schultz6addd812016-02-02 17:17:23 -07008909TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008911 "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +13008912
8913 ASSERT_NO_FATAL_FAILURE(InitState());
8914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8915
8916 VkVertexInputBindingDescription input_binding;
8917 memset(&input_binding, 0, sizeof(input_binding));
8918
8919 VkVertexInputAttributeDescription input_attrib;
8920 memset(&input_attrib, 0, sizeof(input_attrib));
8921 input_attrib.format = VK_FORMAT_R32_SFLOAT;
8922
8923 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008924 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13008925 "\n"
8926 "layout(location=1) in float x;\n"
8927 "out gl_PerVertex {\n"
8928 " vec4 gl_Position;\n"
8929 "};\n"
8930 "void main(){\n"
8931 " gl_Position = vec4(x);\n"
8932 "}\n";
8933 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008934 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13008935 "\n"
8936 "layout(location=0) out vec4 color;\n"
8937 "void main(){\n"
8938 " color = vec4(1);\n"
8939 "}\n";
8940
8941 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8942 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8943
8944 VkPipelineObj pipe(m_device);
8945 pipe.AddColorAttachment();
8946 pipe.AddShader(&vs);
8947 pipe.AddShader(&fs);
8948
8949 pipe.AddVertexInputBindings(&input_binding, 1);
8950 pipe.AddVertexInputAttribs(&input_attrib, 1);
8951
8952 VkDescriptorSetObj descriptorSet(m_device);
8953 descriptorSet.AppendDummy();
8954 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8955
8956 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8957
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008958 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +13008959}
8960
Karl Schultz6addd812016-02-02 17:17:23 -07008961TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
8962 m_errorMonitor->SetDesiredFailureMsg(
8963 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008964 "VS consumes input at location 0 but not provided");
8965
Chris Forbes62e8e502015-05-25 11:13:29 +12008966 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008967 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12008968
8969 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008970 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12008971 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008972 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -07008973 "out gl_PerVertex {\n"
8974 " vec4 gl_Position;\n"
8975 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12008976 "void main(){\n"
8977 " gl_Position = x;\n"
8978 "}\n";
8979 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008980 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12008981 "\n"
8982 "layout(location=0) out vec4 color;\n"
8983 "void main(){\n"
8984 " color = vec4(1);\n"
8985 "}\n";
8986
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008987 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8988 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12008989
8990 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008991 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12008992 pipe.AddShader(&vs);
8993 pipe.AddShader(&fs);
8994
Chris Forbes62e8e502015-05-25 11:13:29 +12008995 VkDescriptorSetObj descriptorSet(m_device);
8996 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008997 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12008998
Tony Barbour5781e8f2015-08-04 16:23:11 -06008999 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12009000
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009001 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +12009002}
9003
Karl Schultz6addd812016-02-02 17:17:23 -07009004TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
9005 m_errorMonitor->SetDesiredFailureMsg(
9006 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009007 "location 0 does not match VS input type");
9008
Chris Forbesc97d98e2015-05-25 11:13:31 +12009009 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009010 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12009011
9012 VkVertexInputBindingDescription input_binding;
9013 memset(&input_binding, 0, sizeof(input_binding));
9014
9015 VkVertexInputAttributeDescription input_attrib;
9016 memset(&input_attrib, 0, sizeof(input_attrib));
9017 input_attrib.format = VK_FORMAT_R32_SFLOAT;
9018
9019 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009020 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12009021 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009022 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07009023 "out gl_PerVertex {\n"
9024 " vec4 gl_Position;\n"
9025 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12009026 "void main(){\n"
9027 " gl_Position = vec4(x);\n"
9028 "}\n";
9029 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009030 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12009031 "\n"
9032 "layout(location=0) out vec4 color;\n"
9033 "void main(){\n"
9034 " color = vec4(1);\n"
9035 "}\n";
9036
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009037 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9038 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12009039
9040 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009041 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12009042 pipe.AddShader(&vs);
9043 pipe.AddShader(&fs);
9044
9045 pipe.AddVertexInputBindings(&input_binding, 1);
9046 pipe.AddVertexInputAttribs(&input_attrib, 1);
9047
Chris Forbesc97d98e2015-05-25 11:13:31 +12009048 VkDescriptorSetObj descriptorSet(m_device);
9049 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009050 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12009051
Tony Barbour5781e8f2015-08-04 16:23:11 -06009052 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12009053
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009054 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +12009055}
9056
Chris Forbesc68b43c2016-04-06 11:18:47 +12009057TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
9058 m_errorMonitor->SetDesiredFailureMsg(
9059 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9060 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
9061
9062 ASSERT_NO_FATAL_FAILURE(InitState());
9063 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9064
9065 char const *vsSource =
9066 "#version 450\n"
9067 "\n"
9068 "out gl_PerVertex {\n"
9069 " vec4 gl_Position;\n"
9070 "};\n"
9071 "void main(){\n"
9072 " gl_Position = vec4(1);\n"
9073 "}\n";
9074 char const *fsSource =
9075 "#version 450\n"
9076 "\n"
9077 "layout(location=0) out vec4 color;\n"
9078 "void main(){\n"
9079 " color = vec4(1);\n"
9080 "}\n";
9081
9082 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9083 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9084
9085 VkPipelineObj pipe(m_device);
9086 pipe.AddColorAttachment();
9087 pipe.AddShader(&vs);
9088 pipe.AddShader(&vs);
9089 pipe.AddShader(&fs);
9090
9091 VkDescriptorSetObj descriptorSet(m_device);
9092 descriptorSet.AppendDummy();
9093 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9094
9095 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9096
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009097 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +12009098}
9099
Karl Schultz6addd812016-02-02 17:17:23 -07009100TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009101 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13009102
9103 ASSERT_NO_FATAL_FAILURE(InitState());
9104 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9105
9106 VkVertexInputBindingDescription input_binding;
9107 memset(&input_binding, 0, sizeof(input_binding));
9108
9109 VkVertexInputAttributeDescription input_attribs[2];
9110 memset(input_attribs, 0, sizeof(input_attribs));
9111
9112 for (int i = 0; i < 2; i++) {
9113 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
9114 input_attribs[i].location = i;
9115 }
9116
9117 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009118 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009119 "\n"
9120 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009121 "out gl_PerVertex {\n"
9122 " vec4 gl_Position;\n"
9123 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009124 "void main(){\n"
9125 " gl_Position = x[0] + x[1];\n"
9126 "}\n";
9127 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009128 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009129 "\n"
9130 "layout(location=0) out vec4 color;\n"
9131 "void main(){\n"
9132 " color = vec4(1);\n"
9133 "}\n";
9134
9135 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9136 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9137
9138 VkPipelineObj pipe(m_device);
9139 pipe.AddColorAttachment();
9140 pipe.AddShader(&vs);
9141 pipe.AddShader(&fs);
9142
9143 pipe.AddVertexInputBindings(&input_binding, 1);
9144 pipe.AddVertexInputAttribs(input_attribs, 2);
9145
9146 VkDescriptorSetObj descriptorSet(m_device);
9147 descriptorSet.AppendDummy();
9148 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9149
9150 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9151
9152 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009153 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +13009154}
9155
Chris Forbes2682b242015-11-24 11:13:14 +13009156TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
9157{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009158 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13009159
9160 ASSERT_NO_FATAL_FAILURE(InitState());
9161 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9162
9163 VkVertexInputBindingDescription input_binding;
9164 memset(&input_binding, 0, sizeof(input_binding));
9165
9166 VkVertexInputAttributeDescription input_attribs[2];
9167 memset(input_attribs, 0, sizeof(input_attribs));
9168
9169 for (int i = 0; i < 2; i++) {
9170 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
9171 input_attribs[i].location = i;
9172 }
9173
9174 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009175 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009176 "\n"
9177 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -07009178 "out gl_PerVertex {\n"
9179 " vec4 gl_Position;\n"
9180 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009181 "void main(){\n"
9182 " gl_Position = x[0] + x[1];\n"
9183 "}\n";
9184 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009185 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009186 "\n"
9187 "layout(location=0) out vec4 color;\n"
9188 "void main(){\n"
9189 " color = vec4(1);\n"
9190 "}\n";
9191
9192 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9193 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9194
9195 VkPipelineObj pipe(m_device);
9196 pipe.AddColorAttachment();
9197 pipe.AddShader(&vs);
9198 pipe.AddShader(&fs);
9199
9200 pipe.AddVertexInputBindings(&input_binding, 1);
9201 pipe.AddVertexInputAttribs(input_attribs, 2);
9202
9203 VkDescriptorSetObj descriptorSet(m_device);
9204 descriptorSet.AppendDummy();
9205 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9206
9207 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9208
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009209 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +13009210}
Chris Forbes2682b242015-11-24 11:13:14 +13009211
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009212TEST_F(VkLayerTest, CreatePipelineSimplePositive)
9213{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009214 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009215
9216 ASSERT_NO_FATAL_FAILURE(InitState());
9217 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9218
9219 char const *vsSource =
9220 "#version 450\n"
9221 "out gl_PerVertex {\n"
9222 " vec4 gl_Position;\n"
9223 "};\n"
9224 "void main(){\n"
9225 " gl_Position = vec4(0);\n"
9226 "}\n";
9227 char const *fsSource =
9228 "#version 450\n"
9229 "\n"
9230 "layout(location=0) out vec4 color;\n"
9231 "void main(){\n"
9232 " color = vec4(1);\n"
9233 "}\n";
9234
9235 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9236 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9237
9238 VkPipelineObj pipe(m_device);
9239 pipe.AddColorAttachment();
9240 pipe.AddShader(&vs);
9241 pipe.AddShader(&fs);
9242
9243 VkDescriptorSetObj descriptorSet(m_device);
9244 descriptorSet.AppendDummy();
9245 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9246
9247 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9248
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009249 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009250}
9251
Chris Forbes912c9192016-04-05 17:50:35 +12009252TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch)
9253{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009254 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +12009255
9256 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
9257
9258 ASSERT_NO_FATAL_FAILURE(InitState());
9259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9260
9261 char const *vsSource =
9262 "#version 450\n"
9263 "out gl_PerVertex {\n"
9264 " vec4 gl_Position;\n"
9265 "};\n"
9266 "layout(location=0) out vec3 x;\n"
9267 "layout(location=1) out ivec3 y;\n"
9268 "layout(location=2) out vec3 z;\n"
9269 "void main(){\n"
9270 " gl_Position = vec4(0);\n"
9271 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
9272 "}\n";
9273 char const *fsSource =
9274 "#version 450\n"
9275 "\n"
9276 "layout(location=0) out vec4 color;\n"
9277 "layout(location=0) in float x;\n"
9278 "layout(location=1) flat in int y;\n"
9279 "layout(location=2) in vec2 z;\n"
9280 "void main(){\n"
9281 " color = vec4(1 + x + y + z.x);\n"
9282 "}\n";
9283
9284 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9285 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9286
9287 VkPipelineObj pipe(m_device);
9288 pipe.AddColorAttachment();
9289 pipe.AddShader(&vs);
9290 pipe.AddShader(&fs);
9291
9292 VkDescriptorSetObj descriptorSet(m_device);
9293 descriptorSet.AppendDummy();
9294 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9295
9296 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9297
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009298 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +12009299}
9300
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009301TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
9302{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009303 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009304
9305 ASSERT_NO_FATAL_FAILURE(InitState());
9306 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9307
Chris Forbesc1e852d2016-04-04 19:26:42 +12009308 if (!m_device->phy().features().tessellationShader) {
9309 printf("Device does not support tessellation shaders; skipped.\n");
9310 return;
9311 }
9312
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009313 char const *vsSource =
9314 "#version 450\n"
9315 "void main(){}\n";
9316 char const *tcsSource =
9317 "#version 450\n"
9318 "layout(location=0) out int x[];\n"
9319 "layout(vertices=3) out;\n"
9320 "void main(){\n"
9321 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
9322 " gl_TessLevelInner[0] = 1;\n"
9323 " x[gl_InvocationID] = gl_InvocationID;\n"
9324 "}\n";
9325 char const *tesSource =
9326 "#version 450\n"
9327 "layout(triangles, equal_spacing, cw) in;\n"
9328 "layout(location=0) in int x[];\n"
9329 "out gl_PerVertex { vec4 gl_Position; };\n"
9330 "void main(){\n"
9331 " gl_Position.xyz = gl_TessCoord;\n"
9332 " gl_Position.w = x[0] + x[1] + x[2];\n"
9333 "}\n";
9334 char const *fsSource =
9335 "#version 450\n"
9336 "layout(location=0) out vec4 color;\n"
9337 "void main(){\n"
9338 " color = vec4(1);\n"
9339 "}\n";
9340
9341 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9342 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
9343 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
9344 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9345
9346 VkPipelineInputAssemblyStateCreateInfo iasci{
9347 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
9348 nullptr,
9349 0,
9350 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
9351 VK_FALSE};
9352
Chris Forbesb4cacb62016-04-04 19:15:00 +12009353 VkPipelineTessellationStateCreateInfo tsci{
9354 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
9355 nullptr,
9356 0,
9357 3};
9358
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009359 VkPipelineObj pipe(m_device);
9360 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +12009361 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009362 pipe.AddColorAttachment();
9363 pipe.AddShader(&vs);
9364 pipe.AddShader(&tcs);
9365 pipe.AddShader(&tes);
9366 pipe.AddShader(&fs);
9367
9368 VkDescriptorSetObj descriptorSet(m_device);
9369 descriptorSet.AppendDummy();
9370 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9371
9372 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9373
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009374 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009375}
9376
Chris Forbesa0ab8152016-04-20 13:34:27 +12009377TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive)
9378{
9379 m_errorMonitor->ExpectSuccess();
9380
9381 ASSERT_NO_FATAL_FAILURE(InitState());
9382 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9383
9384 if (!m_device->phy().features().geometryShader) {
9385 printf("Device does not support geometry shaders; skipped.\n");
9386 return;
9387 }
9388
9389 char const *vsSource =
9390 "#version 450\n"
9391 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
9392 "void main(){\n"
9393 " vs_out.x = vec4(1);\n"
9394 "}\n";
9395 char const *gsSource =
9396 "#version 450\n"
9397 "layout(triangles) in;\n"
9398 "layout(triangle_strip, max_vertices=3) out;\n"
9399 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
9400 "out gl_PerVertex { vec4 gl_Position; };\n"
9401 "void main() {\n"
9402 " gl_Position = gs_in[0].x;\n"
9403 " EmitVertex();\n"
9404 "}\n";
9405 char const *fsSource =
9406 "#version 450\n"
9407 "layout(location=0) out vec4 color;\n"
9408 "void main(){\n"
9409 " color = vec4(1);\n"
9410 "}\n";
9411
9412 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9413 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
9414 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9415
9416 VkPipelineObj pipe(m_device);
9417 pipe.AddColorAttachment();
9418 pipe.AddShader(&vs);
9419 pipe.AddShader(&gs);
9420 pipe.AddShader(&fs);
9421
9422 VkDescriptorSetObj descriptorSet(m_device);
9423 descriptorSet.AppendDummy();
9424 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9425
9426 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9427
9428 m_errorMonitor->VerifyNotFound();
9429}
9430
Chris Forbesa0193bc2016-04-04 19:19:47 +12009431TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
9432{
9433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9434 "is per-vertex in tessellation control shader stage "
9435 "but per-patch in tessellation evaluation shader stage");
9436
9437 ASSERT_NO_FATAL_FAILURE(InitState());
9438 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9439
Chris Forbesc1e852d2016-04-04 19:26:42 +12009440 if (!m_device->phy().features().tessellationShader) {
9441 printf("Device does not support tessellation shaders; skipped.\n");
9442 return;
9443 }
9444
Chris Forbesa0193bc2016-04-04 19:19:47 +12009445 char const *vsSource =
9446 "#version 450\n"
9447 "void main(){}\n";
9448 char const *tcsSource =
9449 "#version 450\n"
9450 "layout(location=0) out int x[];\n"
9451 "layout(vertices=3) out;\n"
9452 "void main(){\n"
9453 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
9454 " gl_TessLevelInner[0] = 1;\n"
9455 " x[gl_InvocationID] = gl_InvocationID;\n"
9456 "}\n";
9457 char const *tesSource =
9458 "#version 450\n"
9459 "layout(triangles, equal_spacing, cw) in;\n"
9460 "layout(location=0) patch in int x;\n"
9461 "out gl_PerVertex { vec4 gl_Position; };\n"
9462 "void main(){\n"
9463 " gl_Position.xyz = gl_TessCoord;\n"
9464 " gl_Position.w = x;\n"
9465 "}\n";
9466 char const *fsSource =
9467 "#version 450\n"
9468 "layout(location=0) out vec4 color;\n"
9469 "void main(){\n"
9470 " color = vec4(1);\n"
9471 "}\n";
9472
9473 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9474 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
9475 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
9476 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9477
9478 VkPipelineInputAssemblyStateCreateInfo iasci{
9479 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
9480 nullptr,
9481 0,
9482 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
9483 VK_FALSE};
9484
9485 VkPipelineTessellationStateCreateInfo tsci{
9486 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
9487 nullptr,
9488 0,
9489 3};
9490
9491 VkPipelineObj pipe(m_device);
9492 pipe.SetInputAssembly(&iasci);
9493 pipe.SetTessellation(&tsci);
9494 pipe.AddColorAttachment();
9495 pipe.AddShader(&vs);
9496 pipe.AddShader(&tcs);
9497 pipe.AddShader(&tes);
9498 pipe.AddShader(&fs);
9499
9500 VkDescriptorSetObj descriptorSet(m_device);
9501 descriptorSet.AppendDummy();
9502 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9503
9504 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9505
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009506 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +12009507}
9508
Karl Schultz6addd812016-02-02 17:17:23 -07009509TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
9510 m_errorMonitor->SetDesiredFailureMsg(
9511 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009512 "Duplicate vertex input binding descriptions for binding 0");
9513
Chris Forbes280ba2c2015-06-12 11:16:41 +12009514 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12009516
9517 /* Two binding descriptions for binding 0 */
9518 VkVertexInputBindingDescription input_bindings[2];
9519 memset(input_bindings, 0, sizeof(input_bindings));
9520
9521 VkVertexInputAttributeDescription input_attrib;
9522 memset(&input_attrib, 0, sizeof(input_attrib));
9523 input_attrib.format = VK_FORMAT_R32_SFLOAT;
9524
9525 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009526 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12009527 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009528 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07009529 "out gl_PerVertex {\n"
9530 " vec4 gl_Position;\n"
9531 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12009532 "void main(){\n"
9533 " gl_Position = vec4(x);\n"
9534 "}\n";
9535 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009536 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12009537 "\n"
9538 "layout(location=0) out vec4 color;\n"
9539 "void main(){\n"
9540 " color = vec4(1);\n"
9541 "}\n";
9542
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009543 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9544 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +12009545
9546 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009547 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12009548 pipe.AddShader(&vs);
9549 pipe.AddShader(&fs);
9550
9551 pipe.AddVertexInputBindings(input_bindings, 2);
9552 pipe.AddVertexInputAttribs(&input_attrib, 1);
9553
Chris Forbes280ba2c2015-06-12 11:16:41 +12009554 VkDescriptorSetObj descriptorSet(m_device);
9555 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009556 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12009557
Tony Barbour5781e8f2015-08-04 16:23:11 -06009558 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12009559
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009560 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +12009561}
Chris Forbes8f68b562015-05-25 11:13:32 +12009562
Chris Forbes35efec72016-04-21 14:32:08 +12009563TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
9564 m_errorMonitor->ExpectSuccess();
9565
9566 ASSERT_NO_FATAL_FAILURE(InitState());
9567 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9568
9569 if (!m_device->phy().features().tessellationShader) {
9570 printf("Device does not support 64bit vertex attributes; skipped.\n");
9571 return;
9572 }
9573
9574 VkVertexInputBindingDescription input_bindings[1];
9575 memset(input_bindings, 0, sizeof(input_bindings));
9576
9577 VkVertexInputAttributeDescription input_attribs[4];
9578 memset(input_attribs, 0, sizeof(input_attribs));
9579 input_attribs[0].location = 0;
9580 input_attribs[0].offset = 0;
9581 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9582 input_attribs[1].location = 2;
9583 input_attribs[1].offset = 32;
9584 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9585 input_attribs[2].location = 4;
9586 input_attribs[2].offset = 64;
9587 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9588 input_attribs[3].location = 6;
9589 input_attribs[3].offset = 96;
9590 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9591
9592 char const *vsSource =
9593 "#version 450\n"
9594 "\n"
9595 "layout(location=0) in dmat4 x;\n"
9596 "out gl_PerVertex {\n"
9597 " vec4 gl_Position;\n"
9598 "};\n"
9599 "void main(){\n"
9600 " gl_Position = vec4(x[0][0]);\n"
9601 "}\n";
9602 char const *fsSource =
9603 "#version 450\n"
9604 "\n"
9605 "layout(location=0) out vec4 color;\n"
9606 "void main(){\n"
9607 " color = vec4(1);\n"
9608 "}\n";
9609
9610 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9611 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9612
9613 VkPipelineObj pipe(m_device);
9614 pipe.AddColorAttachment();
9615 pipe.AddShader(&vs);
9616 pipe.AddShader(&fs);
9617
9618 pipe.AddVertexInputBindings(input_bindings, 1);
9619 pipe.AddVertexInputAttribs(input_attribs, 4);
9620
9621 VkDescriptorSetObj descriptorSet(m_device);
9622 descriptorSet.AppendDummy();
9623 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9624
9625 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9626
9627 m_errorMonitor->VerifyNotFound();
9628}
9629
Karl Schultz6addd812016-02-02 17:17:23 -07009630TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009632 "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009633
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009634 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009635
9636 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009637 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009638 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009639 "out gl_PerVertex {\n"
9640 " vec4 gl_Position;\n"
9641 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009642 "void main(){\n"
9643 " gl_Position = vec4(1);\n"
9644 "}\n";
9645 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009646 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009647 "\n"
9648 "void main(){\n"
9649 "}\n";
9650
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009651 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9652 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009653
9654 VkPipelineObj pipe(m_device);
9655 pipe.AddShader(&vs);
9656 pipe.AddShader(&fs);
9657
Chia-I Wu08accc62015-07-07 11:50:03 +08009658 /* set up CB 0, not written */
9659 pipe.AddColorAttachment();
9660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009661
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009662 VkDescriptorSetObj descriptorSet(m_device);
9663 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009664 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009665
Tony Barbour5781e8f2015-08-04 16:23:11 -06009666 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009667
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009668 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009669}
9670
Karl Schultz6addd812016-02-02 17:17:23 -07009671TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Karl Schultz6addd812016-02-02 17:17:23 -07009672 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009673 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009674 "FS writes to output location 1 with no matching attachment");
9675
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009676 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009677
9678 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009679 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009680 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009681 "out gl_PerVertex {\n"
9682 " vec4 gl_Position;\n"
9683 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009684 "void main(){\n"
9685 " gl_Position = vec4(1);\n"
9686 "}\n";
9687 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009688 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009689 "\n"
9690 "layout(location=0) out vec4 x;\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009691 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009692 "void main(){\n"
9693 " x = vec4(1);\n"
9694 " y = vec4(1);\n"
9695 "}\n";
9696
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009697 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9698 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009699
9700 VkPipelineObj pipe(m_device);
9701 pipe.AddShader(&vs);
9702 pipe.AddShader(&fs);
9703
Chia-I Wu08accc62015-07-07 11:50:03 +08009704 /* set up CB 0, not written */
9705 pipe.AddColorAttachment();
9706 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009707 /* FS writes CB 1, but we don't configure it */
9708
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009709 VkDescriptorSetObj descriptorSet(m_device);
9710 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009711 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009712
Tony Barbour5781e8f2015-08-04 16:23:11 -06009713 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009714
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009715 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009716}
9717
Karl Schultz6addd812016-02-02 17:17:23 -07009718TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009720 "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009721
Chris Forbesa36d69e2015-05-25 11:13:44 +12009722 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12009723
9724 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009725 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12009726 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009727 "out gl_PerVertex {\n"
9728 " vec4 gl_Position;\n"
9729 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12009730 "void main(){\n"
9731 " gl_Position = vec4(1);\n"
9732 "}\n";
9733 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009734 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12009735 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009736 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbesa36d69e2015-05-25 11:13:44 +12009737 "void main(){\n"
9738 " x = ivec4(1);\n"
9739 "}\n";
9740
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009741 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9742 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +12009743
9744 VkPipelineObj pipe(m_device);
9745 pipe.AddShader(&vs);
9746 pipe.AddShader(&fs);
9747
Chia-I Wu08accc62015-07-07 11:50:03 +08009748 /* set up CB 0; type is UNORM by default */
9749 pipe.AddColorAttachment();
9750 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12009751
Chris Forbesa36d69e2015-05-25 11:13:44 +12009752 VkDescriptorSetObj descriptorSet(m_device);
9753 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009754 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12009755
Tony Barbour5781e8f2015-08-04 16:23:11 -06009756 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12009757
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009758 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +12009759}
Chris Forbes7b1b8932015-06-05 14:43:36 +12009760
Karl Schultz6addd812016-02-02 17:17:23 -07009761TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009763 "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009764
Chris Forbes556c76c2015-08-14 12:04:59 +12009765 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12009766
9767 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009768 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12009769 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009770 "out gl_PerVertex {\n"
9771 " vec4 gl_Position;\n"
9772 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12009773 "void main(){\n"
9774 " gl_Position = vec4(1);\n"
9775 "}\n";
9776 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009777 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12009778 "\n"
9779 "layout(location=0) out vec4 x;\n"
9780 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
9781 "void main(){\n"
9782 " x = vec4(bar.y);\n"
9783 "}\n";
9784
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009785 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9786 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +12009787
Chris Forbes556c76c2015-08-14 12:04:59 +12009788 VkPipelineObj pipe(m_device);
9789 pipe.AddShader(&vs);
9790 pipe.AddShader(&fs);
9791
9792 /* set up CB 0; type is UNORM by default */
9793 pipe.AddColorAttachment();
9794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9795
9796 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009797 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +12009798
9799 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9800
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009801 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +12009802}
9803
Chris Forbes5c59e902016-02-26 16:56:09 +13009804TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
9805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9806 "not declared in layout");
9807
9808 ASSERT_NO_FATAL_FAILURE(InitState());
9809
9810 char const *vsSource =
9811 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +13009812 "\n"
9813 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
9814 "out gl_PerVertex {\n"
9815 " vec4 gl_Position;\n"
9816 "};\n"
9817 "void main(){\n"
9818 " gl_Position = vec4(consts.x);\n"
9819 "}\n";
9820 char const *fsSource =
9821 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +13009822 "\n"
9823 "layout(location=0) out vec4 x;\n"
9824 "void main(){\n"
9825 " x = vec4(1);\n"
9826 "}\n";
9827
9828 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9829 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9830
9831 VkPipelineObj pipe(m_device);
9832 pipe.AddShader(&vs);
9833 pipe.AddShader(&fs);
9834
9835 /* set up CB 0; type is UNORM by default */
9836 pipe.AddColorAttachment();
9837 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9838
9839 VkDescriptorSetObj descriptorSet(m_device);
9840 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9841
9842 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9843
9844 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009845 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +13009846}
9847
Chris Forbes10eb9ae2016-05-31 16:09:42 +12009848TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
9849 m_errorMonitor->SetDesiredFailureMsg(
9850 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9851 "Shader uses descriptor slot 0.0");
9852
9853 ASSERT_NO_FATAL_FAILURE(InitState());
9854
9855 char const *csSource =
9856 "#version 450\n"
9857 "\n"
9858 "layout(local_size_x=1) in;\n"
9859 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
9860 "void main(){\n"
9861 " x = vec4(1);\n"
9862 "}\n";
9863
9864 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
9865
9866 VkDescriptorSetObj descriptorSet(m_device);
9867 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9868
9869 VkComputePipelineCreateInfo cpci = {
9870 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
9871 nullptr, 0, {
9872 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
9873 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
9874 cs.handle(), "main", nullptr
9875 },
9876 descriptorSet.GetPipelineLayout(),
9877 VK_NULL_HANDLE, -1
9878 };
9879
9880 VkPipeline pipe;
9881 VkResult err = vkCreateComputePipelines(
9882 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
9883
9884 m_errorMonitor->VerifyFound();
9885
9886 if (err == VK_SUCCESS) {
9887 vkDestroyPipeline(m_device->device(), pipe, nullptr);
9888 }
9889}
9890
9891TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
9892 m_errorMonitor->ExpectSuccess();
9893
9894 ASSERT_NO_FATAL_FAILURE(InitState());
9895
9896 char const *csSource =
9897 "#version 450\n"
9898 "\n"
9899 "layout(local_size_x=1) in;\n"
9900 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
9901 "void main(){\n"
9902 " // x is not used.\n"
9903 "}\n";
9904
9905 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
9906
9907 VkDescriptorSetObj descriptorSet(m_device);
9908 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9909
9910 VkComputePipelineCreateInfo cpci = {
9911 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
9912 nullptr, 0, {
9913 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
9914 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
9915 cs.handle(), "main", nullptr
9916 },
9917 descriptorSet.GetPipelineLayout(),
9918 VK_NULL_HANDLE, -1
9919 };
9920
9921 VkPipeline pipe;
9922 VkResult err = vkCreateComputePipelines(
9923 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
9924
9925 m_errorMonitor->VerifyNotFound();
9926
9927 if (err == VK_SUCCESS) {
9928 vkDestroyPipeline(m_device->device(), pipe, nullptr);
9929 }
9930}
9931
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009932#endif // SHADER_CHECKER_TESTS
9933
9934#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -06009935TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Karl Schultz6addd812016-02-02 17:17:23 -07009936 m_errorMonitor->SetDesiredFailureMsg(
9937 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009938 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009939
9940 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009941
9942 // Create an image
9943 VkImage image;
9944
Karl Schultz6addd812016-02-02 17:17:23 -07009945 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9946 const int32_t tex_width = 32;
9947 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009948
9949 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009950 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9951 image_create_info.pNext = NULL;
9952 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9953 image_create_info.format = tex_format;
9954 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009955 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -07009956 image_create_info.extent.depth = 1;
9957 image_create_info.mipLevels = 1;
9958 image_create_info.arrayLayers = 1;
9959 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9960 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9961 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9962 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009963
9964 // Introduce error by sending down a bogus width extent
9965 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009966 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009967
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009968 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009969}
9970
Mark Youngc48c4c12016-04-11 14:26:49 -06009971TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
9972 m_errorMonitor->SetDesiredFailureMsg(
9973 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9974 "CreateImage extents is 0 for at least one required dimension");
9975
9976 ASSERT_NO_FATAL_FAILURE(InitState());
9977
9978 // Create an image
9979 VkImage image;
9980
9981 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9982 const int32_t tex_width = 32;
9983 const int32_t tex_height = 32;
9984
9985 VkImageCreateInfo image_create_info = {};
9986 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9987 image_create_info.pNext = NULL;
9988 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9989 image_create_info.format = tex_format;
9990 image_create_info.extent.width = tex_width;
9991 image_create_info.extent.height = tex_height;
9992 image_create_info.extent.depth = 1;
9993 image_create_info.mipLevels = 1;
9994 image_create_info.arrayLayers = 1;
9995 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9996 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9997 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9998 image_create_info.flags = 0;
9999
10000 // Introduce error by sending down a bogus width extent
10001 image_create_info.extent.width = 0;
10002 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
10003
10004 m_errorMonitor->VerifyFound();
10005}
10006
Karl Schultz6addd812016-02-02 17:17:23 -070010007TEST_F(VkLayerTest, UpdateBufferAlignment) {
10008 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mike Stroyana3082432015-09-25 13:39:21 -060010009
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010011 "dstOffset, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010012
Mike Stroyana3082432015-09-25 13:39:21 -060010013 ASSERT_NO_FATAL_FAILURE(InitState());
10014
10015 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
10016 vk_testing::Buffer buffer;
10017 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
10018
10019 BeginCommandBuffer();
10020 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010021 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010022 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010023
Mike Stroyana3082432015-09-25 13:39:21 -060010024 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010026 "dataSize, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010027
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010028 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010029 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010030 EndCommandBuffer();
10031}
10032
Karl Schultz6addd812016-02-02 17:17:23 -070010033TEST_F(VkLayerTest, FillBufferAlignment) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010035 "dstOffset, is not a multiple of 4");
Mike Stroyana3082432015-09-25 13:39:21 -060010036
10037 ASSERT_NO_FATAL_FAILURE(InitState());
10038
10039 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
10040 vk_testing::Buffer buffer;
10041 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
10042
10043 BeginCommandBuffer();
10044 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010045 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010046 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010047
Mike Stroyana3082432015-09-25 13:39:21 -060010048 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010050 "size, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010051
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010052 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010053
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010054 m_errorMonitor->VerifyFound();
10055
Mike Stroyana3082432015-09-25 13:39:21 -060010056 EndCommandBuffer();
10057}
10058
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010059#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120010060
Tobin Ehliscde08892015-09-22 10:11:37 -060010061#if IMAGE_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070010062TEST_F(VkLayerTest, InvalidImageView) {
10063 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060010064
Karl Schultz6addd812016-02-02 17:17:23 -070010065 m_errorMonitor->SetDesiredFailureMsg(
10066 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010067 "vkCreateImageView called with baseMipLevel 10 ");
10068
Tobin Ehliscde08892015-09-22 10:11:37 -060010069 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060010070
Mike Stroyana3082432015-09-25 13:39:21 -060010071 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070010072 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060010073
Karl Schultz6addd812016-02-02 17:17:23 -070010074 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10075 const int32_t tex_width = 32;
10076 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060010077
10078 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010079 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10080 image_create_info.pNext = NULL;
10081 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10082 image_create_info.format = tex_format;
10083 image_create_info.extent.width = tex_width;
10084 image_create_info.extent.height = tex_height;
10085 image_create_info.extent.depth = 1;
10086 image_create_info.mipLevels = 1;
10087 image_create_info.arrayLayers = 1;
10088 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10089 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10090 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10091 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060010092
Chia-I Wuf7458c52015-10-26 21:10:41 +080010093 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060010094 ASSERT_VK_SUCCESS(err);
10095
10096 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010097 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10098 image_view_create_info.image = image;
10099 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
10100 image_view_create_info.format = tex_format;
10101 image_view_create_info.subresourceRange.layerCount = 1;
10102 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
10103 image_view_create_info.subresourceRange.levelCount = 1;
10104 image_view_create_info.subresourceRange.aspectMask =
10105 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060010106
10107 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070010108 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
10109 &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060010110
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010111 m_errorMonitor->VerifyFound();
Tobin Ehliscde08892015-09-22 10:11:37 -060010112}
Mike Stroyana3082432015-09-25 13:39:21 -060010113
Karl Schultz6addd812016-02-02 17:17:23 -070010114TEST_F(VkLayerTest, InvalidImageViewAspect) {
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010115 TEST_DESCRIPTION(
10116 "Create an image and try to create a view with an invalid aspectMask");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010118 "vkCreateImageView: Color image "
10119 "formats must have ONLY the "
10120 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010121
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010122 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010123
Karl Schultz6addd812016-02-02 17:17:23 -070010124 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010125 VkImageObj image(m_device);
10126 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT,
10127 VK_IMAGE_TILING_LINEAR, 0);
10128 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010129
10130 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010131 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010132 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070010133 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
10134 image_view_create_info.format = tex_format;
10135 image_view_create_info.subresourceRange.baseMipLevel = 0;
10136 image_view_create_info.subresourceRange.levelCount = 1;
10137 // Cause an error by setting an invalid image aspect
10138 image_view_create_info.subresourceRange.aspectMask =
10139 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010140
10141 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010142 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010143
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010144 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010145}
10146
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010147TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070010148 VkResult err;
10149 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010150
Karl Schultz6addd812016-02-02 17:17:23 -070010151 m_errorMonitor->SetDesiredFailureMsg(
10152 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010153 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010154
Mike Stroyana3082432015-09-25 13:39:21 -060010155 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010156
10157 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010158 VkImage srcImage;
10159 VkImage dstImage;
10160 VkDeviceMemory srcMem;
10161 VkDeviceMemory destMem;
10162 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010163
10164 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010165 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10166 image_create_info.pNext = NULL;
10167 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10168 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10169 image_create_info.extent.width = 32;
10170 image_create_info.extent.height = 32;
10171 image_create_info.extent.depth = 1;
10172 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010173 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070010174 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10175 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10176 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10177 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010178
Karl Schultz6addd812016-02-02 17:17:23 -070010179 err =
10180 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010181 ASSERT_VK_SUCCESS(err);
10182
Karl Schultz6addd812016-02-02 17:17:23 -070010183 err =
10184 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010185 ASSERT_VK_SUCCESS(err);
10186
10187 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010188 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010189 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10190 memAlloc.pNext = NULL;
10191 memAlloc.allocationSize = 0;
10192 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010193
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010194 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010195 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010196 pass =
10197 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010198 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010199 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010200 ASSERT_VK_SUCCESS(err);
10201
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010202 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010203 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010204 pass =
10205 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010206 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010207 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010208 ASSERT_VK_SUCCESS(err);
10209
10210 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10211 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010212 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010213 ASSERT_VK_SUCCESS(err);
10214
10215 BeginCommandBuffer();
10216 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010217 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010218 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010219 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010220 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060010221 copyRegion.srcOffset.x = 0;
10222 copyRegion.srcOffset.y = 0;
10223 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010224 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010225 copyRegion.dstSubresource.mipLevel = 0;
10226 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010227 // Introduce failure by forcing the dst layerCount to differ from src
10228 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010229 copyRegion.dstOffset.x = 0;
10230 copyRegion.dstOffset.y = 0;
10231 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010232 copyRegion.extent.width = 1;
10233 copyRegion.extent.height = 1;
10234 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010235 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10236 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010237 EndCommandBuffer();
10238
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010239 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010240
Chia-I Wuf7458c52015-10-26 21:10:41 +080010241 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010242 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010243 vkFreeMemory(m_device->device(), srcMem, NULL);
10244 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010245}
10246
Tony Barbourd6673642016-05-05 14:46:39 -060010247TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
10248
10249 TEST_DESCRIPTION("Creating images with unsuported formats ");
10250
10251 ASSERT_NO_FATAL_FAILURE(InitState());
10252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10253 VkImageObj image(m_device);
10254 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
10255 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
10256 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
10257 VK_IMAGE_TILING_OPTIMAL, 0);
10258 ASSERT_TRUE(image.initialized());
10259
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010260 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
10261 VkImageCreateInfo image_create_info;
10262 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10263 image_create_info.pNext = NULL;
10264 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10265 image_create_info.format = VK_FORMAT_UNDEFINED;
10266 image_create_info.extent.width = 32;
10267 image_create_info.extent.height = 32;
10268 image_create_info.extent.depth = 1;
10269 image_create_info.mipLevels = 1;
10270 image_create_info.arrayLayers = 1;
10271 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10272 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10273 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10274 image_create_info.flags = 0;
10275
10276 m_errorMonitor->SetDesiredFailureMsg(
10277 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10278 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
10279
10280 VkImage localImage;
10281 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
10282 m_errorMonitor->VerifyFound();
10283
Tony Barbourd6673642016-05-05 14:46:39 -060010284 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010285 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060010286 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
10287 VkFormat format = static_cast<VkFormat>(f);
10288 VkFormatProperties fProps = m_device->format_properties(format);
10289 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
10290 fProps.optimalTilingFeatures == 0) {
10291 unsupported = format;
10292 break;
10293 }
10294 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010295
Tony Barbourd6673642016-05-05 14:46:39 -060010296 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060010297 image_create_info.format = unsupported;
Tony Barbourd6673642016-05-05 14:46:39 -060010298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010299 "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060010300
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010301 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060010302 m_errorMonitor->VerifyFound();
10303 }
10304}
10305
10306TEST_F(VkLayerTest, ImageLayerViewTests) {
10307 VkResult ret;
10308 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
10309
10310 ASSERT_NO_FATAL_FAILURE(InitState());
10311
10312 VkImageObj image(m_device);
10313 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
10314 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
10315 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
10316 VK_IMAGE_TILING_OPTIMAL, 0);
10317 ASSERT_TRUE(image.initialized());
10318
10319 VkImageView imgView;
10320 VkImageViewCreateInfo imgViewInfo = {};
10321 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10322 imgViewInfo.image = image.handle();
10323 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
10324 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
10325 imgViewInfo.subresourceRange.layerCount = 1;
10326 imgViewInfo.subresourceRange.baseMipLevel = 0;
10327 imgViewInfo.subresourceRange.levelCount = 1;
10328 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10329
10330 m_errorMonitor->SetDesiredFailureMsg(
10331 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10332 "vkCreateImageView called with baseMipLevel");
10333 // View can't have baseMipLevel >= image's mipLevels - Expect
10334 // VIEW_CREATE_ERROR
10335 imgViewInfo.subresourceRange.baseMipLevel = 1;
10336 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10337 m_errorMonitor->VerifyFound();
10338 imgViewInfo.subresourceRange.baseMipLevel = 0;
10339
10340 m_errorMonitor->SetDesiredFailureMsg(
10341 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10342 "vkCreateImageView called with baseArrayLayer");
10343 // View can't have baseArrayLayer >= image's arraySize - Expect
10344 // VIEW_CREATE_ERROR
10345 imgViewInfo.subresourceRange.baseArrayLayer = 1;
10346 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10347 m_errorMonitor->VerifyFound();
10348 imgViewInfo.subresourceRange.baseArrayLayer = 0;
10349
10350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10351 "vkCreateImageView called with 0 in "
10352 "pCreateInfo->subresourceRange."
10353 "levelCount");
10354 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
10355 imgViewInfo.subresourceRange.levelCount = 0;
10356 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10357 m_errorMonitor->VerifyFound();
10358 imgViewInfo.subresourceRange.levelCount = 1;
10359
10360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10361 "vkCreateImageView called with 0 in "
10362 "pCreateInfo->subresourceRange."
10363 "layerCount");
10364 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
10365 imgViewInfo.subresourceRange.layerCount = 0;
10366 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10367 m_errorMonitor->VerifyFound();
10368 imgViewInfo.subresourceRange.layerCount = 1;
10369
10370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10371 "but both must be color formats");
10372 // Can't use depth format for view into color image - Expect INVALID_FORMAT
10373 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
10374 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10375 m_errorMonitor->VerifyFound();
10376 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
10377
10378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10379 "Formats MUST be IDENTICAL unless "
10380 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
10381 "was set on image creation.");
10382 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
10383 // VIEW_CREATE_ERROR
10384 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
10385 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10386 m_errorMonitor->VerifyFound();
10387 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
10388
10389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10390 "can support ImageViews with "
10391 "differing formats but they must be "
10392 "in the same compatibility class.");
10393 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
10394 // VIEW_CREATE_ERROR
10395 VkImageCreateInfo mutImgInfo = image.create_info();
10396 VkImage mutImage;
10397 mutImgInfo.format = VK_FORMAT_R8_UINT;
10398 assert(
10399 m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures &
10400 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
10401 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
10402 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10403 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
10404 ASSERT_VK_SUCCESS(ret);
10405 imgViewInfo.image = mutImage;
10406 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10407 m_errorMonitor->VerifyFound();
10408 imgViewInfo.image = image.handle();
10409 vkDestroyImage(m_device->handle(), mutImage, NULL);
10410}
10411
10412TEST_F(VkLayerTest, MiscImageLayerTests) {
10413
10414 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
10415
10416 ASSERT_NO_FATAL_FAILURE(InitState());
10417
10418 VkImageObj image(m_device);
10419 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
10420 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
10421 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
10422 VK_IMAGE_TILING_OPTIMAL, 0);
10423 ASSERT_TRUE(image.initialized());
10424
10425 m_errorMonitor->SetDesiredFailureMsg(
10426 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10427 "number of layers in image subresource is zero");
10428 vk_testing::Buffer buffer;
10429 VkMemoryPropertyFlags reqs = 0;
10430 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
10431 VkBufferImageCopy region = {};
10432 region.bufferRowLength = 128;
10433 region.bufferImageHeight = 128;
10434 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10435 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
10436 region.imageSubresource.layerCount = 0;
10437 region.imageExtent.height = 4;
10438 region.imageExtent.width = 4;
10439 region.imageExtent.depth = 1;
10440 m_commandBuffer->BeginCommandBuffer();
10441 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
10442 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
10443 1, &region);
10444 m_errorMonitor->VerifyFound();
10445 region.imageSubresource.layerCount = 1;
10446
10447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10448 "aspectMasks for each region must "
10449 "specify only COLOR or DEPTH or "
10450 "STENCIL");
10451 // Expect MISMATCHED_IMAGE_ASPECT
10452 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
10453 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
10454 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
10455 1, &region);
10456 m_errorMonitor->VerifyFound();
10457 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10458
10459 m_errorMonitor->SetDesiredFailureMsg(
10460 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10461 "If the format of srcImage is a depth, stencil, depth stencil or "
10462 "integer-based format then filter must be VK_FILTER_NEAREST");
10463 // Expect INVALID_FILTER
10464 VkImageObj intImage1(m_device);
10465 intImage1.init(128, 128, VK_FORMAT_R8_UINT,
10466 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
10467 0);
10468 VkImageObj intImage2(m_device);
10469 intImage2.init(128, 128, VK_FORMAT_R8_UINT,
10470 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
10471 0);
10472 VkImageBlit blitRegion = {};
10473 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10474 blitRegion.srcSubresource.baseArrayLayer = 0;
10475 blitRegion.srcSubresource.layerCount = 1;
10476 blitRegion.srcSubresource.mipLevel = 0;
10477 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10478 blitRegion.dstSubresource.baseArrayLayer = 0;
10479 blitRegion.dstSubresource.layerCount = 1;
10480 blitRegion.dstSubresource.mipLevel = 0;
10481
10482 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(),
10483 intImage1.layout(), intImage2.handle(), intImage2.layout(),
10484 16, &blitRegion, VK_FILTER_LINEAR);
10485 m_errorMonitor->VerifyFound();
10486
10487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10488 "called with 0 in ppMemoryBarriers");
10489 VkImageMemoryBarrier img_barrier;
10490 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10491 img_barrier.pNext = NULL;
10492 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10493 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10494 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10495 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10496 img_barrier.image = image.handle();
10497 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10498 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10499 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10500 img_barrier.subresourceRange.baseArrayLayer = 0;
10501 img_barrier.subresourceRange.baseMipLevel = 0;
10502 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
10503 img_barrier.subresourceRange.layerCount = 0;
10504 img_barrier.subresourceRange.levelCount = 1;
10505 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
10506 VK_PIPELINE_STAGE_HOST_BIT,
10507 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
10508 nullptr, 1, &img_barrier);
10509 m_errorMonitor->VerifyFound();
10510 img_barrier.subresourceRange.layerCount = 1;
10511}
10512
10513TEST_F(VkLayerTest, ImageFormatLimits) {
10514
10515 TEST_DESCRIPTION("Exceed the limits of image format ");
10516
10517 m_errorMonitor->SetDesiredFailureMsg(
10518 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10519 "CreateImage extents exceed allowable limits for format");
10520 VkImageCreateInfo image_create_info = {};
10521 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10522 image_create_info.pNext = NULL;
10523 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10524 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10525 image_create_info.extent.width = 32;
10526 image_create_info.extent.height = 32;
10527 image_create_info.extent.depth = 1;
10528 image_create_info.mipLevels = 1;
10529 image_create_info.arrayLayers = 1;
10530 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10531 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10532 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10533 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10534 image_create_info.flags = 0;
10535
10536 VkImage nullImg;
10537 VkImageFormatProperties imgFmtProps;
10538 vkGetPhysicalDeviceImageFormatProperties(
10539 gpu(), image_create_info.format, image_create_info.imageType,
10540 image_create_info.tiling, image_create_info.usage,
10541 image_create_info.flags, &imgFmtProps);
10542 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
10543 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10544 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10545 m_errorMonitor->VerifyFound();
10546 image_create_info.extent.depth = 1;
10547
10548 m_errorMonitor->SetDesiredFailureMsg(
10549 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10550 "exceeds allowable maximum supported by format of");
10551 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
10552 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10553 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10554 m_errorMonitor->VerifyFound();
10555 image_create_info.mipLevels = 1;
10556
10557 m_errorMonitor->SetDesiredFailureMsg(
10558 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10559 "exceeds allowable maximum supported by format of");
10560 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
10561 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10562 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10563 m_errorMonitor->VerifyFound();
10564 image_create_info.arrayLayers = 1;
10565
10566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10567 "is not supported by format");
10568 int samples = imgFmtProps.sampleCounts >> 1;
10569 image_create_info.samples = (VkSampleCountFlagBits)samples;
10570 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10571 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10572 m_errorMonitor->VerifyFound();
10573 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10574
10575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10576 "pCreateInfo->initialLayout, must be "
10577 "VK_IMAGE_LAYOUT_UNDEFINED or "
10578 "VK_IMAGE_LAYOUT_PREINITIALIZED");
10579 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10580 // Expect INVALID_LAYOUT
10581 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10582 m_errorMonitor->VerifyFound();
10583 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10584}
10585
Karl Schultz6addd812016-02-02 17:17:23 -070010586TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060010587 VkResult err;
10588 bool pass;
10589
10590 // Create color images with different format sizes and try to copy between them
10591 m_errorMonitor->SetDesiredFailureMsg(
10592 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10593 "vkCmdCopyImage called with unmatched source and dest image format sizes");
10594
10595 ASSERT_NO_FATAL_FAILURE(InitState());
10596
10597 // Create two images of different types and try to copy between them
10598 VkImage srcImage;
10599 VkImage dstImage;
10600 VkDeviceMemory srcMem;
10601 VkDeviceMemory destMem;
10602 VkMemoryRequirements memReqs;
10603
10604 VkImageCreateInfo image_create_info = {};
10605 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10606 image_create_info.pNext = NULL;
10607 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10608 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10609 image_create_info.extent.width = 32;
10610 image_create_info.extent.height = 32;
10611 image_create_info.extent.depth = 1;
10612 image_create_info.mipLevels = 1;
10613 image_create_info.arrayLayers = 1;
10614 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10615 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10616 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10617 image_create_info.flags = 0;
10618
10619 err =
10620 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
10621 ASSERT_VK_SUCCESS(err);
10622
10623 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
10624 // Introduce failure by creating second image with a different-sized format.
10625 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
10626
10627 err =
10628 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
10629 ASSERT_VK_SUCCESS(err);
10630
10631 // Allocate memory
10632 VkMemoryAllocateInfo memAlloc = {};
10633 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10634 memAlloc.pNext = NULL;
10635 memAlloc.allocationSize = 0;
10636 memAlloc.memoryTypeIndex = 0;
10637
10638 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
10639 memAlloc.allocationSize = memReqs.size;
10640 pass =
10641 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
10642 ASSERT_TRUE(pass);
10643 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
10644 ASSERT_VK_SUCCESS(err);
10645
10646 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
10647 memAlloc.allocationSize = memReqs.size;
10648 pass =
10649 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
10650 ASSERT_TRUE(pass);
10651 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
10652 ASSERT_VK_SUCCESS(err);
10653
10654 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10655 ASSERT_VK_SUCCESS(err);
10656 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
10657 ASSERT_VK_SUCCESS(err);
10658
10659 BeginCommandBuffer();
10660 VkImageCopy copyRegion;
10661 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10662 copyRegion.srcSubresource.mipLevel = 0;
10663 copyRegion.srcSubresource.baseArrayLayer = 0;
10664 copyRegion.srcSubresource.layerCount = 0;
10665 copyRegion.srcOffset.x = 0;
10666 copyRegion.srcOffset.y = 0;
10667 copyRegion.srcOffset.z = 0;
10668 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10669 copyRegion.dstSubresource.mipLevel = 0;
10670 copyRegion.dstSubresource.baseArrayLayer = 0;
10671 copyRegion.dstSubresource.layerCount = 0;
10672 copyRegion.dstOffset.x = 0;
10673 copyRegion.dstOffset.y = 0;
10674 copyRegion.dstOffset.z = 0;
10675 copyRegion.extent.width = 1;
10676 copyRegion.extent.height = 1;
10677 copyRegion.extent.depth = 1;
10678 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10679 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10680 EndCommandBuffer();
10681
10682 m_errorMonitor->VerifyFound();
10683
10684 vkDestroyImage(m_device->device(), srcImage, NULL);
10685 vkDestroyImage(m_device->device(), dstImage, NULL);
10686 vkFreeMemory(m_device->device(), srcMem, NULL);
10687 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010688}
10689
Karl Schultz6addd812016-02-02 17:17:23 -070010690TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
10691 VkResult err;
10692 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010693
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010694 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010695 m_errorMonitor->SetDesiredFailureMsg(
10696 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010697 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010698
Mike Stroyana3082432015-09-25 13:39:21 -060010699 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010700
10701 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010702 VkImage srcImage;
10703 VkImage dstImage;
10704 VkDeviceMemory srcMem;
10705 VkDeviceMemory destMem;
10706 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010707
10708 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010709 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10710 image_create_info.pNext = NULL;
10711 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10712 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10713 image_create_info.extent.width = 32;
10714 image_create_info.extent.height = 32;
10715 image_create_info.extent.depth = 1;
10716 image_create_info.mipLevels = 1;
10717 image_create_info.arrayLayers = 1;
10718 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10719 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10720 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10721 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010722
Karl Schultz6addd812016-02-02 17:17:23 -070010723 err =
10724 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010725 ASSERT_VK_SUCCESS(err);
10726
Karl Schultzbdb75952016-04-19 11:36:49 -060010727 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
10728
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010729 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070010730 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010731 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
10732 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010733
Karl Schultz6addd812016-02-02 17:17:23 -070010734 err =
10735 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010736 ASSERT_VK_SUCCESS(err);
10737
10738 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010739 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010740 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10741 memAlloc.pNext = NULL;
10742 memAlloc.allocationSize = 0;
10743 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010744
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010745 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010746 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010747 pass =
10748 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010749 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010750 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010751 ASSERT_VK_SUCCESS(err);
10752
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010753 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010754 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010755 pass =
10756 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010757 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010758 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010759 ASSERT_VK_SUCCESS(err);
10760
10761 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10762 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010763 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010764 ASSERT_VK_SUCCESS(err);
10765
10766 BeginCommandBuffer();
10767 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010768 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010769 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010770 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010771 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010772 copyRegion.srcOffset.x = 0;
10773 copyRegion.srcOffset.y = 0;
10774 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010775 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010776 copyRegion.dstSubresource.mipLevel = 0;
10777 copyRegion.dstSubresource.baseArrayLayer = 0;
10778 copyRegion.dstSubresource.layerCount = 0;
10779 copyRegion.dstOffset.x = 0;
10780 copyRegion.dstOffset.y = 0;
10781 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010782 copyRegion.extent.width = 1;
10783 copyRegion.extent.height = 1;
10784 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010785 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10786 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010787 EndCommandBuffer();
10788
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010789 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010790
Chia-I Wuf7458c52015-10-26 21:10:41 +080010791 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010792 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010793 vkFreeMemory(m_device->device(), srcMem, NULL);
10794 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010795}
10796
Karl Schultz6addd812016-02-02 17:17:23 -070010797TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
10798 VkResult err;
10799 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010800
Karl Schultz6addd812016-02-02 17:17:23 -070010801 m_errorMonitor->SetDesiredFailureMsg(
10802 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010803 "vkCmdResolveImage called with source sample count less than 2.");
10804
Mike Stroyana3082432015-09-25 13:39:21 -060010805 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010806
10807 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070010808 VkImage srcImage;
10809 VkImage dstImage;
10810 VkDeviceMemory srcMem;
10811 VkDeviceMemory destMem;
10812 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010813
10814 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010815 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10816 image_create_info.pNext = NULL;
10817 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10818 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10819 image_create_info.extent.width = 32;
10820 image_create_info.extent.height = 1;
10821 image_create_info.extent.depth = 1;
10822 image_create_info.mipLevels = 1;
10823 image_create_info.arrayLayers = 1;
10824 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10825 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10826 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10827 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010828
Karl Schultz6addd812016-02-02 17:17:23 -070010829 err =
10830 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010831 ASSERT_VK_SUCCESS(err);
10832
Karl Schultz6addd812016-02-02 17:17:23 -070010833 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010834
Karl Schultz6addd812016-02-02 17:17:23 -070010835 err =
10836 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010837 ASSERT_VK_SUCCESS(err);
10838
10839 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010840 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010841 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10842 memAlloc.pNext = NULL;
10843 memAlloc.allocationSize = 0;
10844 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010845
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010846 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010847 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010848 pass =
10849 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010850 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010851 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010852 ASSERT_VK_SUCCESS(err);
10853
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010854 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010855 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010856 pass =
10857 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010858 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010859 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010860 ASSERT_VK_SUCCESS(err);
10861
10862 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10863 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010864 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010865 ASSERT_VK_SUCCESS(err);
10866
10867 BeginCommandBuffer();
10868 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070010869 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
10870 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060010871 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010872 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010873 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010874 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010875 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010876 resolveRegion.srcOffset.x = 0;
10877 resolveRegion.srcOffset.y = 0;
10878 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010879 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010880 resolveRegion.dstSubresource.mipLevel = 0;
10881 resolveRegion.dstSubresource.baseArrayLayer = 0;
10882 resolveRegion.dstSubresource.layerCount = 0;
10883 resolveRegion.dstOffset.x = 0;
10884 resolveRegion.dstOffset.y = 0;
10885 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010886 resolveRegion.extent.width = 1;
10887 resolveRegion.extent.height = 1;
10888 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010889 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10890 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010891 EndCommandBuffer();
10892
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010893 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010894
Chia-I Wuf7458c52015-10-26 21:10:41 +080010895 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010896 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010897 vkFreeMemory(m_device->device(), srcMem, NULL);
10898 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010899}
10900
Karl Schultz6addd812016-02-02 17:17:23 -070010901TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
10902 VkResult err;
10903 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010904
Karl Schultz6addd812016-02-02 17:17:23 -070010905 m_errorMonitor->SetDesiredFailureMsg(
10906 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010907 "vkCmdResolveImage called with dest sample count greater than 1.");
10908
Mike Stroyana3082432015-09-25 13:39:21 -060010909 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010910
Chris Forbesa7530692016-05-08 12:35:39 +120010911 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070010912 VkImage srcImage;
10913 VkImage dstImage;
10914 VkDeviceMemory srcMem;
10915 VkDeviceMemory destMem;
10916 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010917
10918 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010919 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10920 image_create_info.pNext = NULL;
10921 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10922 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10923 image_create_info.extent.width = 32;
10924 image_create_info.extent.height = 1;
10925 image_create_info.extent.depth = 1;
10926 image_create_info.mipLevels = 1;
10927 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120010928 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070010929 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10930 // Note: Some implementations expect color attachment usage for any
10931 // multisample surface
10932 image_create_info.usage =
10933 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10934 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010935
Karl Schultz6addd812016-02-02 17:17:23 -070010936 err =
10937 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010938 ASSERT_VK_SUCCESS(err);
10939
Karl Schultz6addd812016-02-02 17:17:23 -070010940 // Note: Some implementations expect color attachment usage for any
10941 // multisample surface
10942 image_create_info.usage =
10943 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010944
Karl Schultz6addd812016-02-02 17:17:23 -070010945 err =
10946 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010947 ASSERT_VK_SUCCESS(err);
10948
10949 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010950 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010951 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10952 memAlloc.pNext = NULL;
10953 memAlloc.allocationSize = 0;
10954 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010955
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010956 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010957 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010958 pass =
10959 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010960 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010961 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010962 ASSERT_VK_SUCCESS(err);
10963
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010964 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010965 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010966 pass =
10967 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010968 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010969 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010970 ASSERT_VK_SUCCESS(err);
10971
10972 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10973 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010974 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010975 ASSERT_VK_SUCCESS(err);
10976
10977 BeginCommandBuffer();
10978 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070010979 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
10980 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060010981 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010982 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010983 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010984 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010985 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010986 resolveRegion.srcOffset.x = 0;
10987 resolveRegion.srcOffset.y = 0;
10988 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010989 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010990 resolveRegion.dstSubresource.mipLevel = 0;
10991 resolveRegion.dstSubresource.baseArrayLayer = 0;
10992 resolveRegion.dstSubresource.layerCount = 0;
10993 resolveRegion.dstOffset.x = 0;
10994 resolveRegion.dstOffset.y = 0;
10995 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010996 resolveRegion.extent.width = 1;
10997 resolveRegion.extent.height = 1;
10998 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010999 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11000 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011001 EndCommandBuffer();
11002
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011003 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011004
Chia-I Wuf7458c52015-10-26 21:10:41 +080011005 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011006 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011007 vkFreeMemory(m_device->device(), srcMem, NULL);
11008 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011009}
11010
Karl Schultz6addd812016-02-02 17:17:23 -070011011TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
11012 VkResult err;
11013 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011014
Karl Schultz6addd812016-02-02 17:17:23 -070011015 m_errorMonitor->SetDesiredFailureMsg(
11016 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011017 "vkCmdResolveImage called with unmatched source and dest formats.");
11018
Mike Stroyana3082432015-09-25 13:39:21 -060011019 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011020
11021 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011022 VkImage srcImage;
11023 VkImage dstImage;
11024 VkDeviceMemory srcMem;
11025 VkDeviceMemory destMem;
11026 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011027
11028 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011029 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11030 image_create_info.pNext = NULL;
11031 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11032 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11033 image_create_info.extent.width = 32;
11034 image_create_info.extent.height = 1;
11035 image_create_info.extent.depth = 1;
11036 image_create_info.mipLevels = 1;
11037 image_create_info.arrayLayers = 1;
11038 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
11039 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11040 // Note: Some implementations expect color attachment usage for any
11041 // multisample surface
11042 image_create_info.usage =
11043 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11044 image_create_info.flags = 0;
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, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011048 ASSERT_VK_SUCCESS(err);
11049
Karl Schultz6addd812016-02-02 17:17:23 -070011050 // Set format to something other than source image
11051 image_create_info.format = VK_FORMAT_R32_SFLOAT;
11052 // Note: Some implementations expect color attachment usage for any
11053 // multisample surface
11054 image_create_info.usage =
11055 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11056 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011057
Karl Schultz6addd812016-02-02 17:17:23 -070011058 err =
11059 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011060 ASSERT_VK_SUCCESS(err);
11061
11062 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011063 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011064 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11065 memAlloc.pNext = NULL;
11066 memAlloc.allocationSize = 0;
11067 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011068
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011069 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011070 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011071 pass =
11072 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011073 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011074 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011075 ASSERT_VK_SUCCESS(err);
11076
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011077 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011078 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011079 pass =
11080 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011081 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011082 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011083 ASSERT_VK_SUCCESS(err);
11084
11085 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11086 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011087 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011088 ASSERT_VK_SUCCESS(err);
11089
11090 BeginCommandBuffer();
11091 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011092 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11093 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011094 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011095 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011096 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011097 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011098 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011099 resolveRegion.srcOffset.x = 0;
11100 resolveRegion.srcOffset.y = 0;
11101 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011102 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011103 resolveRegion.dstSubresource.mipLevel = 0;
11104 resolveRegion.dstSubresource.baseArrayLayer = 0;
11105 resolveRegion.dstSubresource.layerCount = 0;
11106 resolveRegion.dstOffset.x = 0;
11107 resolveRegion.dstOffset.y = 0;
11108 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011109 resolveRegion.extent.width = 1;
11110 resolveRegion.extent.height = 1;
11111 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011112 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11113 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011114 EndCommandBuffer();
11115
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011116 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011117
Chia-I Wuf7458c52015-10-26 21:10:41 +080011118 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011119 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011120 vkFreeMemory(m_device->device(), srcMem, NULL);
11121 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011122}
11123
Karl Schultz6addd812016-02-02 17:17:23 -070011124TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
11125 VkResult err;
11126 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011127
Karl Schultz6addd812016-02-02 17:17:23 -070011128 m_errorMonitor->SetDesiredFailureMsg(
11129 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011130 "vkCmdResolveImage called with unmatched source and dest image types.");
11131
Mike Stroyana3082432015-09-25 13:39:21 -060011132 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011133
11134 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011135 VkImage srcImage;
11136 VkImage dstImage;
11137 VkDeviceMemory srcMem;
11138 VkDeviceMemory destMem;
11139 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011140
11141 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011142 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11143 image_create_info.pNext = NULL;
11144 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11145 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11146 image_create_info.extent.width = 32;
11147 image_create_info.extent.height = 1;
11148 image_create_info.extent.depth = 1;
11149 image_create_info.mipLevels = 1;
11150 image_create_info.arrayLayers = 1;
11151 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
11152 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11153 // Note: Some implementations expect color attachment usage for any
11154 // multisample surface
11155 image_create_info.usage =
11156 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11157 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011158
Karl Schultz6addd812016-02-02 17:17:23 -070011159 err =
11160 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011161 ASSERT_VK_SUCCESS(err);
11162
Karl Schultz6addd812016-02-02 17:17:23 -070011163 image_create_info.imageType = VK_IMAGE_TYPE_1D;
11164 // Note: Some implementations expect color attachment usage for any
11165 // multisample surface
11166 image_create_info.usage =
11167 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11168 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011169
Karl Schultz6addd812016-02-02 17:17:23 -070011170 err =
11171 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011172 ASSERT_VK_SUCCESS(err);
11173
11174 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011175 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011176 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11177 memAlloc.pNext = NULL;
11178 memAlloc.allocationSize = 0;
11179 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011180
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011181 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011182 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011183 pass =
11184 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011185 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011186 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011187 ASSERT_VK_SUCCESS(err);
11188
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011189 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011190 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011191 pass =
11192 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011193 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011194 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011195 ASSERT_VK_SUCCESS(err);
11196
11197 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11198 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011199 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011200 ASSERT_VK_SUCCESS(err);
11201
11202 BeginCommandBuffer();
11203 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011204 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11205 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011206 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011207 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011208 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011209 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011210 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011211 resolveRegion.srcOffset.x = 0;
11212 resolveRegion.srcOffset.y = 0;
11213 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011214 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011215 resolveRegion.dstSubresource.mipLevel = 0;
11216 resolveRegion.dstSubresource.baseArrayLayer = 0;
11217 resolveRegion.dstSubresource.layerCount = 0;
11218 resolveRegion.dstOffset.x = 0;
11219 resolveRegion.dstOffset.y = 0;
11220 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011221 resolveRegion.extent.width = 1;
11222 resolveRegion.extent.height = 1;
11223 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011224 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11225 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011226 EndCommandBuffer();
11227
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011228 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011229
Chia-I Wuf7458c52015-10-26 21:10:41 +080011230 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011231 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011232 vkFreeMemory(m_device->device(), srcMem, NULL);
11233 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011234}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011235
Karl Schultz6addd812016-02-02 17:17:23 -070011236TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011237 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070011238 // to using a DS format, then cause it to hit error due to COLOR_BIT not
11239 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011240 // The image format check comes 2nd in validation so we trigger it first,
11241 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070011242 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011243
Karl Schultz6addd812016-02-02 17:17:23 -070011244 m_errorMonitor->SetDesiredFailureMsg(
11245 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011246 "Combination depth/stencil image formats can have only the ");
11247
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011248 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011249
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011250 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011251 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
11252 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011253
11254 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011255 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11256 ds_pool_ci.pNext = NULL;
11257 ds_pool_ci.maxSets = 1;
11258 ds_pool_ci.poolSizeCount = 1;
11259 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011260
11261 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -070011262 err =
11263 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011264 ASSERT_VK_SUCCESS(err);
11265
11266 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011267 dsl_binding.binding = 0;
11268 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
11269 dsl_binding.descriptorCount = 1;
11270 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11271 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011272
11273 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011274 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11275 ds_layout_ci.pNext = NULL;
11276 ds_layout_ci.bindingCount = 1;
11277 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011278 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070011279 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
11280 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011281 ASSERT_VK_SUCCESS(err);
11282
11283 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011284 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011285 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011286 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011287 alloc_info.descriptorPool = ds_pool;
11288 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070011289 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
11290 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011291 ASSERT_VK_SUCCESS(err);
11292
Karl Schultz6addd812016-02-02 17:17:23 -070011293 VkImage image_bad;
11294 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011295 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060011296 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011297 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070011298 const int32_t tex_width = 32;
11299 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011300
11301 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011302 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11303 image_create_info.pNext = NULL;
11304 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11305 image_create_info.format = tex_format_bad;
11306 image_create_info.extent.width = tex_width;
11307 image_create_info.extent.height = tex_height;
11308 image_create_info.extent.depth = 1;
11309 image_create_info.mipLevels = 1;
11310 image_create_info.arrayLayers = 1;
11311 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11312 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11313 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
11314 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11315 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011316
Karl Schultz6addd812016-02-02 17:17:23 -070011317 err =
11318 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011319 ASSERT_VK_SUCCESS(err);
11320 image_create_info.format = tex_format_good;
Karl Schultz6addd812016-02-02 17:17:23 -070011321 image_create_info.usage =
11322 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11323 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
11324 &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011325 ASSERT_VK_SUCCESS(err);
11326
11327 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011328 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11329 image_view_create_info.image = image_bad;
11330 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11331 image_view_create_info.format = tex_format_bad;
11332 image_view_create_info.subresourceRange.baseArrayLayer = 0;
11333 image_view_create_info.subresourceRange.baseMipLevel = 0;
11334 image_view_create_info.subresourceRange.layerCount = 1;
11335 image_view_create_info.subresourceRange.levelCount = 1;
11336 image_view_create_info.subresourceRange.aspectMask =
11337 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011338
11339 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070011340 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
11341 &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011342
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011343 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011344
Chia-I Wuf7458c52015-10-26 21:10:41 +080011345 vkDestroyImage(m_device->device(), image_bad, NULL);
11346 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011347 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11348 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011349}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060011350
11351TEST_F(VkLayerTest, ClearImageErrors) {
11352 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
11353 "ClearDepthStencilImage with a color image.");
11354
11355 ASSERT_NO_FATAL_FAILURE(InitState());
11356 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11357
11358 // Renderpass is started here so end it as Clear cmds can't be in renderpass
11359 BeginCommandBuffer();
11360 m_commandBuffer->EndRenderPass();
11361
11362 // Color image
11363 VkClearColorValue clear_color;
11364 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
11365 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
11366 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
11367 const int32_t img_width = 32;
11368 const int32_t img_height = 32;
11369 VkImageCreateInfo image_create_info = {};
11370 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11371 image_create_info.pNext = NULL;
11372 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11373 image_create_info.format = color_format;
11374 image_create_info.extent.width = img_width;
11375 image_create_info.extent.height = img_height;
11376 image_create_info.extent.depth = 1;
11377 image_create_info.mipLevels = 1;
11378 image_create_info.arrayLayers = 1;
11379 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11380 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11381 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11382
11383 vk_testing::Image color_image;
11384 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info,
11385 reqs);
11386
11387 const VkImageSubresourceRange color_range =
11388 vk_testing::Image::subresource_range(image_create_info,
11389 VK_IMAGE_ASPECT_COLOR_BIT);
11390
11391 // Depth/Stencil image
11392 VkClearDepthStencilValue clear_value = {0};
11393 reqs = 0; // don't need HOST_VISIBLE DS image
11394 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
11395 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
11396 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
11397 ds_image_create_info.extent.width = 64;
11398 ds_image_create_info.extent.height = 64;
11399 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11400 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11401
11402 vk_testing::Image ds_image;
11403 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info,
11404 reqs);
11405
11406 const VkImageSubresourceRange ds_range =
11407 vk_testing::Image::subresource_range(ds_image_create_info,
11408 VK_IMAGE_ASPECT_DEPTH_BIT);
11409
11410 m_errorMonitor->SetDesiredFailureMsg(
11411 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11412 "vkCmdClearColorImage called with depth/stencil image.");
11413
11414 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
11415 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
11416 &color_range);
11417
11418 m_errorMonitor->VerifyFound();
11419
11420 // Call CmdClearDepthStencilImage with color image
11421 m_errorMonitor->SetDesiredFailureMsg(
11422 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11423 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
11424
11425 vkCmdClearDepthStencilImage(
11426 m_commandBuffer->GetBufferHandle(), color_image.handle(),
11427 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
11428 &ds_range);
11429
11430 m_errorMonitor->VerifyFound();
11431}
Tobin Ehliscde08892015-09-22 10:11:37 -060011432#endif // IMAGE_TESTS
11433
Tony Barbour300a6082015-04-07 13:44:53 -060011434int main(int argc, char **argv) {
11435 int result;
11436
Cody Northrop8e54a402016-03-08 22:25:52 -070011437#ifdef ANDROID
11438 int vulkanSupport = InitVulkan();
11439 if (vulkanSupport == 0)
11440 return 1;
11441#endif
11442
Tony Barbour300a6082015-04-07 13:44:53 -060011443 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060011444 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060011445
11446 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
11447
11448 result = RUN_ALL_TESTS();
11449
Tony Barbour6918cd52015-04-09 12:58:51 -060011450 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060011451 return result;
11452}