blob: dc8f77444a03b1d079de5f0b6f4ea7ecfa50f8cb [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
20 */
Tony Barbour65c48b32015-11-17 10:02:56 -070021
Cody Northrop8e54a402016-03-08 22:25:52 -070022#ifdef ANDROID
23#include "vulkan_wrapper.h"
24#else
David Pinedo9316d3b2015-11-06 12:54:48 -070025#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070026#endif
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -060027#include "test_common.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060028#include "vkrenderframework.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060029#include "vk_layer_config.h"
Jon Ashburn7fa7e222016-02-02 12:08:10 -070030#include "icd-spv.h"
Tony Barbour300a6082015-04-07 13:44:53 -060031
Mark Lobodzinski3780e142015-05-14 15:08:13 -050032#define GLM_FORCE_RADIANS
33#include "glm/glm.hpp"
34#include <glm/gtc/matrix_transform.hpp>
35
Dustin Gravesffa90fa2016-05-06 11:20:38 -060036#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060037#define MEM_TRACKER_TESTS 1
38#define OBJ_TRACKER_TESTS 1
39#define DRAW_STATE_TESTS 1
40#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120041#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060042#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060043#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060044
Mark Lobodzinski3780e142015-05-14 15:08:13 -050045//--------------------------------------------------------------------------------------
46// Mesh and VertexFormat Data
47//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070048struct Vertex {
49 float posX, posY, posZ, posW; // Position data
50 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050051};
52
Karl Schultz6addd812016-02-02 17:17:23 -070053#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050054
55typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070056 BsoFailNone = 0x00000000,
57 BsoFailLineWidth = 0x00000001,
58 BsoFailDepthBias = 0x00000002,
59 BsoFailViewport = 0x00000004,
60 BsoFailScissor = 0x00000008,
61 BsoFailBlend = 0x00000010,
62 BsoFailDepthBounds = 0x00000020,
63 BsoFailStencilReadMask = 0x00000040,
64 BsoFailStencilWriteMask = 0x00000080,
65 BsoFailStencilReference = 0x00000100,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050066} BsoFailSelect;
67
68struct vktriangle_vs_uniform {
69 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070070 float mvp[4][4];
71 float position[3][4];
72 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050073};
74
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050075static const char bindStateVertShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120076 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070077 "vec2 vertices[3];\n"
78 "out gl_PerVertex {\n"
79 " vec4 gl_Position;\n"
80 "};\n"
81 "void main() {\n"
82 " vertices[0] = vec2(-1.0, -1.0);\n"
83 " vertices[1] = vec2( 1.0, -1.0);\n"
84 " vertices[2] = vec2( 0.0, 1.0);\n"
85 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
86 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050087
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050088static const char bindStateFragShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120089 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070090 "\n"
91 "layout(location = 0) out vec4 uFragColor;\n"
92 "void main(){\n"
93 " uFragColor = vec4(0,1,0,1);\n"
94 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050095
Karl Schultz6addd812016-02-02 17:17:23 -070096static VKAPI_ATTR VkBool32 VKAPI_CALL
97myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
98 uint64_t srcObject, size_t location, int32_t msgCode,
99 const char *pLayerPrefix, const char *pMsg, void *pUserData);
Tony Barbour300a6082015-04-07 13:44:53 -0600100
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600101// ********************************************************
102// ErrorMonitor Usage:
103//
104// Call SetDesiredFailureMsg with a string to be compared against all
105// encountered log messages. Passing NULL will match all log messages.
106// logMsg will return true for skipCall only if msg is matched or NULL.
107//
108// Call DesiredMsgFound to determine if the desired failure message
109// was encountered.
110
Tony Barbour300a6082015-04-07 13:44:53 -0600111class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700112 public:
113 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600114 test_platform_thread_create_mutex(&m_mutex);
115 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700116 m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700117 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600118 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600119 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600120
Dustin Graves48458142016-04-29 16:11:55 -0600121 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
122
Karl Schultz6addd812016-02-02 17:17:23 -0700123 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200124 // also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600125 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600126 m_failureMsg.clear();
127 m_otherMsgs.clear();
128 m_desiredMsg = msgString;
Karl Schultz6addd812016-02-02 17:17:23 -0700129 m_msgFound = VK_FALSE;
130 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600131 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600132 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600133
Karl Schultz6addd812016-02-02 17:17:23 -0700134 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600135 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600136 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600137 if (m_bailout != NULL) {
138 *m_bailout = true;
139 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600140 string errorString(msgString);
141 if (msgFlags & m_msgFlags) {
142 if (errorString.find(m_desiredMsg) != string::npos) {
Chris Forbesc7b8ad72016-04-04 18:50:38 +1200143 if (m_msgFound) { /* if multiple matches, don't lose all but the last! */
144 m_otherMsgs.push_back(m_failureMsg);
145 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600146 m_failureMsg = errorString;
Karl Schultz6addd812016-02-02 17:17:23 -0700147 m_msgFound = VK_TRUE;
148 result = VK_TRUE;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600149 } else {
150 m_otherMsgs.push_back(errorString);
151 }
152 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600153 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600154 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600155 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600156
Karl Schultz6addd812016-02-02 17:17:23 -0700157 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600158
Karl Schultz6addd812016-02-02 17:17:23 -0700159 string GetFailureMsg(void) { return m_failureMsg; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600160
Karl Schultz6addd812016-02-02 17:17:23 -0700161 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600162
Karl Schultz6addd812016-02-02 17:17:23 -0700163 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600164
Karl Schultz6addd812016-02-02 17:17:23 -0700165 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 vector<string> otherMsgs = GetOtherFailureMsgs();
167 cout << "Other error messages logged for this test were:" << endl;
168 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
169 cout << " " << *iter << endl;
170 }
171 }
172
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200173 /* helpers */
174
175 void ExpectSuccess() {
176 // match anything
177 SetDesiredFailureMsg(~0u, "");
178 }
179
180 void VerifyFound() {
181 // Not seeing the desired message is a failure. /Before/ throwing, dump
182 // any other messages.
183 if (!DesiredMsgFound()) {
184 DumpFailureMsgs();
185 FAIL() << "Did not receive expected error '" << m_desiredMsg << "'";
186 }
187 }
188
189 void VerifyNotFound() {
190 // ExpectSuccess() configured us to match anything. Any error is a
191 // failure.
192 if (DesiredMsgFound()) {
193 DumpFailureMsgs();
194 FAIL() << "Expected to succeed but got error: " << GetFailureMsg();
195 }
196 }
197
Karl Schultz6addd812016-02-02 17:17:23 -0700198 private:
199 VkFlags m_msgFlags;
200 string m_desiredMsg;
201 string m_failureMsg;
202 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600203 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700204 bool *m_bailout;
205 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600206};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500207
Karl Schultz6addd812016-02-02 17:17:23 -0700208static VKAPI_ATTR VkBool32 VKAPI_CALL
209myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
210 uint64_t srcObject, size_t location, int32_t msgCode,
211 const char *pLayerPrefix, const char *pMsg, void *pUserData) {
212 if (msgFlags &
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700213 (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
Karl Schultz6addd812016-02-02 17:17:23 -0700214 VK_DEBUG_REPORT_ERROR_BIT_EXT)) {
Tony Barbour0b4d9562015-04-09 10:48:04 -0600215 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600216 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600217 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600218 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600219}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500220
Karl Schultz6addd812016-02-02 17:17:23 -0700221class VkLayerTest : public VkRenderFramework {
222 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800223 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
224 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700225 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText,
226 BsoFailSelect failMask);
227 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
228 VkPipelineObj &pipelineobj,
229 VkDescriptorSetObj &descriptorSet,
230 BsoFailSelect failMask);
231 void GenericDrawPreparation(VkPipelineObj &pipelineobj,
232 VkDescriptorSetObj &descriptorSet,
233 BsoFailSelect failMask) {
234 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet,
235 failMask);
236 }
Tony Barbour300a6082015-04-07 13:44:53 -0600237
Tony Barbourfe3351b2015-07-28 10:17:20 -0600238 /* Convenience functions that use built-in command buffer */
Karl Schultz6addd812016-02-02 17:17:23 -0700239 VkResult BeginCommandBuffer() {
240 return BeginCommandBuffer(*m_commandBuffer);
241 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800242 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Karl Schultz6addd812016-02-02 17:17:23 -0700243 void Draw(uint32_t vertexCount, uint32_t instanceCount,
244 uint32_t firstVertex, uint32_t firstInstance) {
245 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex,
246 firstInstance);
247 }
248 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount,
249 uint32_t firstIndex, int32_t vertexOffset,
250 uint32_t firstInstance) {
251 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex,
252 vertexOffset, firstInstance);
253 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800254 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
Karl Schultz6addd812016-02-02 17:17:23 -0700255 void QueueCommandBuffer(const VkFence &fence) {
256 m_commandBuffer->QueueCommandBuffer(fence);
257 }
258 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer,
259 VkDeviceSize offset, uint32_t binding) {
260 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
261 }
262 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
263 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
264 }
265
266 protected:
267 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600268 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600269
270 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600271 std::vector<const char *> instance_layer_names;
272 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600273 std::vector<const char *> instance_extension_names;
274 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600275
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700276 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600277 /*
278 * Since CreateDbgMsgCallback is an instance level extension call
279 * any extension / layer that utilizes that feature also needs
280 * to be enabled at create instance time.
281 */
Karl Schultz6addd812016-02-02 17:17:23 -0700282 // Use Threading layer first to protect others from
283 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700284 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600285 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800286 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700287 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800288 instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
289 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600290 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700291 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600292
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700293 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600294 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800295 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700296 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800297 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
298 device_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600299 device_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700300 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Tony Barbour300a6082015-04-07 13:44:53 -0600301
Ian Elliott2c1daf52016-05-12 09:41:46 -0600302 if (m_enableWSI) {
303 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
304 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
305#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
306#if defined(VK_USE_PLATFORM_ANDROID_KHR)
307 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
308#endif // VK_USE_PLATFORM_ANDROID_KHR
309#if defined(VK_USE_PLATFORM_MIR_KHR)
310 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
311#endif // VK_USE_PLATFORM_MIR_KHR
312#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
313 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
314#endif // VK_USE_PLATFORM_WAYLAND_KHR
315#if defined(VK_USE_PLATFORM_WIN32_KHR)
316 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
317#endif // VK_USE_PLATFORM_WIN32_KHR
318#endif // NEED_TO_TEST_THIS_ON_PLATFORM
319#if defined(VK_USE_PLATFORM_XCB_KHR)
320 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
321#elif defined(VK_USE_PLATFORM_XLIB_KHR)
322 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
323#endif // VK_USE_PLATFORM_XLIB_KHR
324 }
325
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600326 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600327 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800328 this->app_info.pApplicationName = "layer_tests";
329 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600330 this->app_info.pEngineName = "unittest";
331 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600332 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600333
Tony Barbour15524c32015-04-29 17:34:29 -0600334 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600335 InitFramework(instance_layer_names, device_layer_names,
336 instance_extension_names, device_extension_names,
337 myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600338 }
339
340 virtual void TearDown() {
341 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600342 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600343 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600344 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600345
346 VkLayerTest() {
347 m_enableWSI = false;
348 }
Tony Barbour300a6082015-04-07 13:44:53 -0600349};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500350
Karl Schultz6addd812016-02-02 17:17:23 -0700351VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600352 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600353
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800354 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600355
356 /*
357 * For render test all drawing happens in a single render pass
358 * on a single command buffer.
359 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200360 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800361 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600362 }
363
364 return result;
365}
366
Karl Schultz6addd812016-02-02 17:17:23 -0700367VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600368 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600369
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200370 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800371 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200372 }
Tony Barbour300a6082015-04-07 13:44:53 -0600373
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800374 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600375
376 return result;
377}
378
Karl Schultz6addd812016-02-02 17:17:23 -0700379void VkLayerTest::VKTriangleTest(const char *vertShaderText,
380 const char *fragShaderText,
381 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500382 // Create identity matrix
383 int i;
384 struct vktriangle_vs_uniform data;
385
386 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700387 glm::mat4 View = glm::mat4(1.0f);
388 glm::mat4 Model = glm::mat4(1.0f);
389 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500390 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700391 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500392
393 memcpy(&data.mvp, &MVP[0][0], matrixSize);
394
Karl Schultz6addd812016-02-02 17:17:23 -0700395 static const Vertex tri_data[] = {
396 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)},
397 {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)},
398 {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500399 };
400
Karl Schultz6addd812016-02-02 17:17:23 -0700401 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500402 data.position[i][0] = tri_data[i].posX;
403 data.position[i][1] = tri_data[i].posY;
404 data.position[i][2] = tri_data[i].posZ;
405 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700406 data.color[i][0] = tri_data[i].r;
407 data.color[i][1] = tri_data[i].g;
408 data.color[i][2] = tri_data[i].b;
409 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500410 }
411
412 ASSERT_NO_FATAL_FAILURE(InitState());
413 ASSERT_NO_FATAL_FAILURE(InitViewport());
414
Karl Schultz6addd812016-02-02 17:17:23 -0700415 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float),
416 (const void *)&data);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500417
Karl Schultz6addd812016-02-02 17:17:23 -0700418 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
419 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
420 this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500421
422 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800423 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500424 pipelineobj.AddShader(&vs);
425 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600426 if (failMask & BsoFailLineWidth) {
427 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600428 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
429 ia_state.sType =
430 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
431 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
432 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600433 }
434 if (failMask & BsoFailDepthBias) {
435 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600436 VkPipelineRasterizationStateCreateInfo rs_state = {};
437 rs_state.sType =
438 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
439 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600440 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600441 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600442 }
Karl Schultz6addd812016-02-02 17:17:23 -0700443 // Viewport and scissors must stay in synch or other errors will occur than
444 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600445 if (failMask & BsoFailViewport) {
446 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600447 m_viewports.clear();
448 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600449 }
450 if (failMask & BsoFailScissor) {
451 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600452 m_scissors.clear();
453 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600454 }
455 if (failMask & BsoFailBlend) {
456 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600457 VkPipelineColorBlendAttachmentState att_state = {};
458 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
459 att_state.blendEnable = VK_TRUE;
460 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600461 }
462 if (failMask & BsoFailDepthBounds) {
463 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
464 }
465 if (failMask & BsoFailStencilReadMask) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
467 }
468 if (failMask & BsoFailStencilWriteMask) {
469 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
470 }
471 if (failMask & BsoFailStencilReference) {
472 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
473 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500474
475 VkDescriptorSetObj descriptorSet(m_device);
Karl Schultz6addd812016-02-02 17:17:23 -0700476 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
477 constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500478
479 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600480 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500481
Tony Barbourfe3351b2015-07-28 10:17:20 -0600482 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500483
484 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600485 Draw(3, 1, 0, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500486
487 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600488 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500489
Tony Barbourfe3351b2015-07-28 10:17:20 -0600490 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500491}
492
Karl Schultz6addd812016-02-02 17:17:23 -0700493void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
494 VkPipelineObj &pipelineobj,
495 VkDescriptorSetObj &descriptorSet,
496 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500497 if (m_depthStencil->Initialized()) {
Karl Schultz6addd812016-02-02 17:17:23 -0700498 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
499 m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500 } else {
Karl Schultz6addd812016-02-02 17:17:23 -0700501 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
502 m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503 }
504
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800505 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700506 // Make sure depthWriteEnable is set so that Depth fail test will work
507 // correctly
508 // Make sure stencilTestEnable is set so that Stencil fail test will work
509 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600510 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800511 stencil.failOp = VK_STENCIL_OP_KEEP;
512 stencil.passOp = VK_STENCIL_OP_KEEP;
513 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
514 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600515
516 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
517 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600518 ds_ci.pNext = NULL;
519 ds_ci.depthTestEnable = VK_FALSE;
520 ds_ci.depthWriteEnable = VK_TRUE;
521 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
522 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600523 if (failMask & BsoFailDepthBounds) {
524 ds_ci.depthBoundsTestEnable = VK_TRUE;
525 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600526 ds_ci.stencilTestEnable = VK_TRUE;
527 ds_ci.front = stencil;
528 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600529
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600530 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600531 pipelineobj.SetViewport(m_viewports);
532 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800533 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700534 VkResult err = pipelineobj.CreateVKPipeline(
535 descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600536 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800537 commandBuffer->BindPipeline(pipelineobj);
538 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500539}
540
Ian Elliott2c1daf52016-05-12 09:41:46 -0600541class VkWsiEnabledLayerTest : public VkLayerTest {
542 public:
543protected:
544 VkWsiEnabledLayerTest() {
545 m_enableWSI = true;
546 }
547};
548
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500549// ********************************************************************************************************************
550// ********************************************************************************************************************
551// ********************************************************************************************************************
552// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600553#if PARAMETER_VALIDATION_TESTS
554TEST_F(VkLayerTest, RequiredParameter) {
555 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
556 "pointer, array, and array count parameters");
557
558 ASSERT_NO_FATAL_FAILURE(InitState());
559
560 m_errorMonitor->SetDesiredFailureMsg(
561 VK_DEBUG_REPORT_ERROR_BIT_EXT,
562 "required parameter pFeatures specified as NULL");
563 // Specify NULL for a pointer to a handle
564 // Expected to trigger an error with
565 // parameter_validation::validate_required_pointer
566 vkGetPhysicalDeviceFeatures(gpu(), NULL);
567 m_errorMonitor->VerifyFound();
568
569 m_errorMonitor->SetDesiredFailureMsg(
570 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600571 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600572 // Specify NULL for pointer to array count
573 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600574 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600575 m_errorMonitor->VerifyFound();
576
577 m_errorMonitor->SetDesiredFailureMsg(
578 VK_DEBUG_REPORT_ERROR_BIT_EXT,
579 "parameter viewportCount must be greater than 0");
580 // Specify 0 for a required array count
581 // Expected to trigger an error with parameter_validation::validate_array
582 VkViewport view_port = {};
583 m_commandBuffer->SetViewport(0, 0, &view_port);
584 m_errorMonitor->VerifyFound();
585
586 m_errorMonitor->SetDesiredFailureMsg(
587 VK_DEBUG_REPORT_ERROR_BIT_EXT,
588 "required parameter pViewports specified as NULL");
589 // Specify NULL for a required array
590 // Expected to trigger an error with parameter_validation::validate_array
591 m_commandBuffer->SetViewport(0, 1, NULL);
592 m_errorMonitor->VerifyFound();
593
594 m_errorMonitor->SetDesiredFailureMsg(
595 VK_DEBUG_REPORT_ERROR_BIT_EXT,
596 "required parameter memory specified as VK_NULL_HANDLE");
597 // Specify VK_NULL_HANDLE for a required handle
598 // Expected to trigger an error with
599 // parameter_validation::validate_required_handle
600 vkUnmapMemory(device(), VK_NULL_HANDLE);
601 m_errorMonitor->VerifyFound();
602
603 m_errorMonitor->SetDesiredFailureMsg(
604 VK_DEBUG_REPORT_ERROR_BIT_EXT,
605 "required parameter pFences[0] specified as VK_NULL_HANDLE");
606 // Specify VK_NULL_HANDLE for a required handle array entry
607 // Expected to trigger an error with
608 // parameter_validation::validate_required_handle_array
609 VkFence fence = VK_NULL_HANDLE;
610 vkResetFences(device(), 1, &fence);
611 m_errorMonitor->VerifyFound();
612
613 m_errorMonitor->SetDesiredFailureMsg(
614 VK_DEBUG_REPORT_ERROR_BIT_EXT,
615 "required parameter pAllocateInfo specified as NULL");
616 // Specify NULL for a required struct pointer
617 // Expected to trigger an error with
618 // parameter_validation::validate_struct_type
619 VkDeviceMemory memory = VK_NULL_HANDLE;
620 vkAllocateMemory(device(), NULL, NULL, &memory);
621 m_errorMonitor->VerifyFound();
622
623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
624 "value of faceMask must not be 0");
625 // Specify 0 for a required VkFlags parameter
626 // Expected to trigger an error with parameter_validation::validate_flags
627 m_commandBuffer->SetStencilReference(0, 0);
628 m_errorMonitor->VerifyFound();
629
630 m_errorMonitor->SetDesiredFailureMsg(
631 VK_DEBUG_REPORT_ERROR_BIT_EXT,
632 "value of pSubmits[i].pWaitDstStageMask[0] must not be 0");
633 // Specify 0 for a required VkFlags array entry
634 // Expected to trigger an error with
635 // parameter_validation::validate_flags_array
636 VkSemaphore semaphore = VK_NULL_HANDLE;
637 VkPipelineStageFlags stageFlags = 0;
638 VkSubmitInfo submitInfo = {};
639 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
640 submitInfo.waitSemaphoreCount = 1;
641 submitInfo.pWaitSemaphores = &semaphore;
642 submitInfo.pWaitDstStageMask = &stageFlags;
643 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
644 m_errorMonitor->VerifyFound();
645}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600646
Dustin Gravesfce74c02016-05-10 11:42:58 -0600647TEST_F(VkLayerTest, ReservedParameter) {
648 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
649
650 ASSERT_NO_FATAL_FAILURE(InitState());
651
652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
653 " must be 0");
654 // Specify 0 for a reserved VkFlags parameter
655 // Expected to trigger an error with
656 // parameter_validation::validate_reserved_flags
657 VkEvent event_handle = VK_NULL_HANDLE;
658 VkEventCreateInfo event_info = {};
659 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
660 event_info.flags = 1;
661 vkCreateEvent(device(), &event_info, NULL, &event_handle);
662 m_errorMonitor->VerifyFound();
663}
664
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600665TEST_F(VkLayerTest, InvalidStructSType) {
666 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
667 "structure's sType field");
668
669 ASSERT_NO_FATAL_FAILURE(InitState());
670
671 m_errorMonitor->SetDesiredFailureMsg(
672 VK_DEBUG_REPORT_ERROR_BIT_EXT,
673 "parameter pAllocateInfo->sType must be");
674 // Zero struct memory, effectively setting sType to
675 // VK_STRUCTURE_TYPE_APPLICATION_INFO
676 // Expected to trigger an error with
677 // parameter_validation::validate_struct_type
678 VkMemoryAllocateInfo alloc_info = {};
679 VkDeviceMemory memory = VK_NULL_HANDLE;
680 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
681 m_errorMonitor->VerifyFound();
682
683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
684 "parameter pSubmits[0].sType must be");
685 // Zero struct memory, effectively setting sType to
686 // VK_STRUCTURE_TYPE_APPLICATION_INFO
687 // Expected to trigger an error with
688 // parameter_validation::validate_struct_type_array
689 VkSubmitInfo submit_info = {};
690 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
691 m_errorMonitor->VerifyFound();
692}
693
694TEST_F(VkLayerTest, InvalidStructPNext) {
695 TEST_DESCRIPTION(
696 "Specify an invalid value for a Vulkan structure's pNext field");
697
698 ASSERT_NO_FATAL_FAILURE(InitState());
699
700 m_errorMonitor->SetDesiredFailureMsg(
701 VK_DEBUG_REPORT_ERROR_BIT_EXT,
702 "value of pAllocateInfo->pNext must be NULL");
703 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
704 // NULL
705 // Expected to trigger an error with
706 // parameter_validation::validate_struct_pnext
707 VkDeviceMemory memory = VK_NULL_HANDLE;
708 // Zero-initialization will provide the correct sType
709 VkApplicationInfo app_info = {};
Dustin Graves47b6cba2016-05-10 17:34:38 -0600710 VkMemoryAllocateInfo memory_alloc_info = {};
711 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
712 memory_alloc_info.pNext = &app_info;
713 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600714 m_errorMonitor->VerifyFound();
715
Dustin Graves47b6cba2016-05-10 17:34:38 -0600716 m_errorMonitor->SetDesiredFailureMsg(
717 VK_DEBUG_REPORT_ERROR_BIT_EXT,
718 " chain includes a structure with unexpected VkStructureType ");
719 // Set VkGraphicsPipelineCreateInfo::VkPipelineRasterizationStateCreateInfo::pNext to an invalid structure, when pNext is allowed to be a non-NULL value
720 // Expected to trigger an error with
721 // parameter_validation::validate_struct_pnext
722 VkDescriptorPoolSize ds_type_count = {};
723 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
724 ds_type_count.descriptorCount = 1;
725
726 VkDescriptorPoolCreateInfo ds_pool_ci = {};
727 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
728 ds_pool_ci.pNext = NULL;
729 ds_pool_ci.maxSets = 1;
730 ds_pool_ci.poolSizeCount = 1;
731 ds_pool_ci.pPoolSizes = &ds_type_count;
732
733 VkDescriptorPool ds_pool;
734 VkResult err =
735 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
736 ASSERT_VK_SUCCESS(err);
737
738 VkDescriptorSetLayoutBinding dsl_binding = {};
739 dsl_binding.binding = 0;
740 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
741 dsl_binding.descriptorCount = 1;
742 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
743 dsl_binding.pImmutableSamplers = NULL;
744
745 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
746 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
747 ds_layout_ci.pNext = NULL;
748 ds_layout_ci.bindingCount = 1;
749 ds_layout_ci.pBindings = &dsl_binding;
750
751 VkDescriptorSetLayout ds_layout;
752 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
753 &ds_layout);
754 ASSERT_VK_SUCCESS(err);
755
756 VkDescriptorSet descriptorSet;
757 VkDescriptorSetAllocateInfo ds_alloc_info = {};
758 ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
759 ds_alloc_info.descriptorSetCount = 1;
760 ds_alloc_info.descriptorPool = ds_pool;
761 ds_alloc_info.pSetLayouts = &ds_layout;
762 err = vkAllocateDescriptorSets(m_device->device(), &ds_alloc_info,
763 &descriptorSet);
764 ASSERT_VK_SUCCESS(err);
765
766 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
767 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
768 pipeline_layout_ci.setLayoutCount = 1;
769 pipeline_layout_ci.pSetLayouts = &ds_layout;
770
771 VkPipelineLayout pipeline_layout;
772 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
773 &pipeline_layout);
774 ASSERT_VK_SUCCESS(err);
775
776 VkViewport vp = {}; // Just need dummy vp to point to
777 VkRect2D sc = {}; // dummy scissor to point to
778
779 VkPipelineViewportStateCreateInfo vp_state_ci = {};
780 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
781 vp_state_ci.scissorCount = 1;
782 vp_state_ci.pScissors = &sc;
783 vp_state_ci.viewportCount = 1;
784 vp_state_ci.pViewports = &vp;
785
786 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
787 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
788 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
789 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
790 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
791 rs_state_ci.depthClampEnable = VK_FALSE;
792 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
793 rs_state_ci.depthBiasEnable = VK_FALSE;
794
795 VkGraphicsPipelineCreateInfo gp_ci = {};
796 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
797 gp_ci.pViewportState = &vp_state_ci;
798 gp_ci.pRasterizationState = &rs_state_ci;
799 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
800 gp_ci.layout = pipeline_layout;
801 gp_ci.renderPass = renderPass();
802
803 VkPipelineCacheCreateInfo pc_ci = {};
804 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
805 pc_ci.initialDataSize = 0;
806 pc_ci.pInitialData = 0;
807
808 VkPipeline pipeline;
809 VkPipelineCache pipelineCache;
810
811 err =
812 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
813 ASSERT_VK_SUCCESS(err);
814
815 // Set VkPipelineRasterizationStateCreateInfo::pNext to an invalid value
816 VkApplicationInfo invalid_pnext_struct = {};
817 rs_state_ci.pNext = &invalid_pnext_struct;
818
819 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
820 &gp_ci, NULL, &pipeline);
821 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600822}
Dustin Graves5d33d532016-05-09 16:21:12 -0600823
824TEST_F(VkLayerTest, UnrecognizedValue) {
825 TEST_DESCRIPTION(
826 "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
827
828 ASSERT_NO_FATAL_FAILURE(InitState());
829
830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
831 "does not fall within the begin..end "
832 "range of the core VkFormat "
833 "enumeration tokens");
834 // Specify an invalid VkFormat value
835 // Expected to trigger an error with
836 // parameter_validation::validate_ranged_enum
837 VkFormatProperties format_properties;
838 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000),
839 &format_properties);
840 m_errorMonitor->VerifyFound();
841
842 m_errorMonitor->SetDesiredFailureMsg(
843 VK_DEBUG_REPORT_ERROR_BIT_EXT,
844 "contains flag bits that are not recognized members of");
845 // Specify an invalid VkFlags bitmask value
846 // Expected to trigger an error with parameter_validation::validate_flags
847 VkImageFormatProperties image_format_properties;
848 vkGetPhysicalDeviceImageFormatProperties(
849 gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D,
850 VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0,
851 &image_format_properties);
852 m_errorMonitor->VerifyFound();
853
854 m_errorMonitor->SetDesiredFailureMsg(
855 VK_DEBUG_REPORT_ERROR_BIT_EXT,
856 "contains flag bits that are not recognized members of");
857 // Specify an invalid VkFlags array entry
858 // Expected to trigger an error with
859 // parameter_validation::validate_flags_array
860 VkSemaphore semaphore = VK_NULL_HANDLE;
861 VkPipelineStageFlags stage_flags =
862 static_cast<VkPipelineStageFlags>(1 << 25);
863 VkSubmitInfo submit_info = {};
864 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
865 submit_info.waitSemaphoreCount = 1;
866 submit_info.pWaitSemaphores = &semaphore;
867 submit_info.pWaitDstStageMask = &stage_flags;
868 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
869 m_errorMonitor->VerifyFound();
870
871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
872 "is neither VK_TRUE nor VK_FALSE");
873 // Specify an invalid VkBool32 value
874 // Expected to trigger a warning with
875 // parameter_validation::validate_bool32
876 VkSampler sampler = VK_NULL_HANDLE;
877 VkSamplerCreateInfo sampler_info = {};
878 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
879 sampler_info.pNext = NULL;
880 sampler_info.magFilter = VK_FILTER_NEAREST;
881 sampler_info.minFilter = VK_FILTER_NEAREST;
882 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
883 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
884 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
885 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
886 sampler_info.mipLodBias = 1.0;
887 sampler_info.maxAnisotropy = 1;
888 sampler_info.compareEnable = VK_FALSE;
889 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
890 sampler_info.minLod = 1.0;
891 sampler_info.maxLod = 1.0;
892 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
893 sampler_info.unnormalizedCoordinates = VK_FALSE;
894 // Not VK_TRUE or VK_FALSE
895 sampler_info.anisotropyEnable = 3;
896 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
897 m_errorMonitor->VerifyFound();
898}
Dustin Gravesfce74c02016-05-10 11:42:58 -0600899
900TEST_F(VkLayerTest, FailedReturnValue) {
901 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
902
903 ASSERT_NO_FATAL_FAILURE(InitState());
904
Dustin Graves13c1e2b2016-05-16 15:31:02 -0600905 // Find an unsupported image format
906 VkFormat unsupported = VK_FORMAT_UNDEFINED;
907 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
908 VkFormat format = static_cast<VkFormat>(f);
909 VkFormatProperties fProps = m_device->format_properties(format);
910 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
911 fProps.optimalTilingFeatures == 0) {
912 unsupported = format;
913 break;
914 }
915 }
916
917 if (unsupported != VK_FORMAT_UNDEFINED) {
918 m_errorMonitor->SetDesiredFailureMsg(
919 VK_DEBUG_REPORT_WARNING_BIT_EXT,
920 "the requested format is not supported on this device");
921 // Specify an unsupported VkFormat value to generate a
922 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
923 // Expected to trigger a warning from
924 // parameter_validation::validate_result
925 VkImageFormatProperties image_format_properties;
926 VkResult err = vkGetPhysicalDeviceImageFormatProperties(
927 gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
928 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
929 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
930 m_errorMonitor->VerifyFound();
931 }
Dustin Gravesfce74c02016-05-10 11:42:58 -0600932}
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600933#endif // PARAMETER_VALIDATION_TESTS
934
Tobin Ehlis0788f522015-05-26 16:11:58 -0600935#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -0700936#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800937TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500938{
939 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500940 VkFenceCreateInfo fenceInfo = {};
941 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
942 fenceInfo.pNext = NULL;
943 fenceInfo.flags = 0;
944
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600946
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500947 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -0600948
949 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
950 vk_testing::Buffer buffer;
951 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500952
Tony Barbourfe3351b2015-07-28 10:17:20 -0600953 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800954 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600955 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500956
957 testFence.init(*m_device, fenceInfo);
958
959 // Bypass framework since it does the waits automatically
960 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600961 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800962 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
963 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800964 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600965 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -0700966 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800967 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800968 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800969 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600970 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600971
972 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500973 ASSERT_VK_SUCCESS( err );
974
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500975 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800976 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500977
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200978 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500979}
980
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800981TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500982{
983 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500984 VkFenceCreateInfo fenceInfo = {};
985 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
986 fenceInfo.pNext = NULL;
987 fenceInfo.flags = 0;
988
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600990
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500991 ASSERT_NO_FATAL_FAILURE(InitState());
992 ASSERT_NO_FATAL_FAILURE(InitViewport());
993 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
994
Tony Barbourfe3351b2015-07-28 10:17:20 -0600995 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800996 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600997 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500998
999 testFence.init(*m_device, fenceInfo);
1000
1001 // Bypass framework since it does the waits automatically
1002 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001003 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001004 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1005 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001006 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001007 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001008 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001009 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001010 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001011 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001012 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001013
1014 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001015 ASSERT_VK_SUCCESS( err );
1016
Jon Ashburnf19916e2016-01-11 13:12:43 -07001017 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001018 VkCommandBufferBeginInfo info = {};
1019 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1020 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001021 info.renderPass = VK_NULL_HANDLE;
1022 info.subpass = 0;
1023 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001024 info.occlusionQueryEnable = VK_FALSE;
1025 info.queryFlags = 0;
1026 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001027
1028 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001029 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001030
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001031 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001032}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001033#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001034
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001035// This is a positive test. No failures are expected.
1036TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1037 VkResult err;
1038 bool pass;
1039
1040 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1041 "the buffer, create an image, and bind the same memory to "
1042 "it");
1043
1044 m_errorMonitor->ExpectSuccess();
1045
1046 ASSERT_NO_FATAL_FAILURE(InitState());
1047
1048 VkBuffer buffer;
1049 VkImage image;
1050 VkDeviceMemory mem;
1051 VkMemoryRequirements mem_reqs;
1052
1053 VkBufferCreateInfo buf_info = {};
1054 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1055 buf_info.pNext = NULL;
1056 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1057 buf_info.size = 256;
1058 buf_info.queueFamilyIndexCount = 0;
1059 buf_info.pQueueFamilyIndices = NULL;
1060 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1061 buf_info.flags = 0;
1062 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1063 ASSERT_VK_SUCCESS(err);
1064
1065 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1066
1067 VkMemoryAllocateInfo alloc_info = {};
1068 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1069 alloc_info.pNext = NULL;
1070 alloc_info.memoryTypeIndex = 0;
1071
1072 // Ensure memory is big enough for both bindings
1073 alloc_info.allocationSize = 0x10000;
1074
1075 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1076 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1077 if (!pass) {
1078 vkDestroyBuffer(m_device->device(), buffer, NULL);
1079 return;
1080 }
1081
1082 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1083 ASSERT_VK_SUCCESS(err);
1084
1085 uint8_t *pData;
1086 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1087 (void **)&pData);
1088 ASSERT_VK_SUCCESS(err);
1089
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001090 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001091
1092 vkUnmapMemory(m_device->device(), mem);
1093
1094 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1095 ASSERT_VK_SUCCESS(err);
1096
1097 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1098 // memory. In fact, it was never used by the GPU.
1099 // Just be be sure, wait for idle.
1100 vkDestroyBuffer(m_device->device(), buffer, NULL);
1101 vkDeviceWaitIdle(m_device->device());
1102
1103 VkImageCreateInfo image_create_info = {};
1104 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1105 image_create_info.pNext = NULL;
1106 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1107 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1108 image_create_info.extent.width = 64;
1109 image_create_info.extent.height = 64;
1110 image_create_info.extent.depth = 1;
1111 image_create_info.mipLevels = 1;
1112 image_create_info.arrayLayers = 1;
1113 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1114 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1115 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1116 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1117 image_create_info.queueFamilyIndexCount = 0;
1118 image_create_info.pQueueFamilyIndices = NULL;
1119 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1120 image_create_info.flags = 0;
1121
1122 VkMemoryAllocateInfo mem_alloc = {};
1123 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1124 mem_alloc.pNext = NULL;
1125 mem_alloc.allocationSize = 0;
1126 mem_alloc.memoryTypeIndex = 0;
1127
1128 /* Create a mappable image. It will be the texture if linear images are ok
1129 * to be textures or it will be the staging image if they are not.
1130 */
1131 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1132 ASSERT_VK_SUCCESS(err);
1133
1134 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1135
1136 mem_alloc.allocationSize = mem_reqs.size;
1137
1138 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc,
1139 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1140 if (!pass) {
1141 vkDestroyImage(m_device->device(), image, NULL);
1142 return;
1143 }
1144
Tobin Ehlis077ded32016-05-12 17:39:13 -06001145 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001146 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1147 ASSERT_VK_SUCCESS(err);
1148
1149 m_errorMonitor->VerifyNotFound();
1150
1151 vkDestroyBuffer(m_device->device(), buffer, NULL);
1152 vkDestroyImage(m_device->device(), image, NULL);
1153}
1154
Tobin Ehlisf11be982016-05-11 13:52:53 -06001155TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1156 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1157 "buffer and image to memory such that they will alias.");
1158 VkResult err;
1159 bool pass;
1160 ASSERT_NO_FATAL_FAILURE(InitState());
1161
Tobin Ehlis077ded32016-05-12 17:39:13 -06001162 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001163 VkImage image;
1164 VkDeviceMemory mem; // buffer will be bound first
1165 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001166 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001167
1168 VkBufferCreateInfo buf_info = {};
1169 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1170 buf_info.pNext = NULL;
1171 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1172 buf_info.size = 256;
1173 buf_info.queueFamilyIndexCount = 0;
1174 buf_info.pQueueFamilyIndices = NULL;
1175 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1176 buf_info.flags = 0;
1177 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1178 ASSERT_VK_SUCCESS(err);
1179
Tobin Ehlis077ded32016-05-12 17:39:13 -06001180 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001181
1182 VkImageCreateInfo image_create_info = {};
1183 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1184 image_create_info.pNext = NULL;
1185 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1186 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1187 image_create_info.extent.width = 64;
1188 image_create_info.extent.height = 64;
1189 image_create_info.extent.depth = 1;
1190 image_create_info.mipLevels = 1;
1191 image_create_info.arrayLayers = 1;
1192 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1193 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1194 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1195 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1196 image_create_info.queueFamilyIndexCount = 0;
1197 image_create_info.pQueueFamilyIndices = NULL;
1198 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1199 image_create_info.flags = 0;
1200
Tobin Ehlisf11be982016-05-11 13:52:53 -06001201 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1202 ASSERT_VK_SUCCESS(err);
1203
Tobin Ehlis077ded32016-05-12 17:39:13 -06001204 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1205
1206 VkMemoryAllocateInfo alloc_info = {};
1207 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1208 alloc_info.pNext = NULL;
1209 alloc_info.memoryTypeIndex = 0;
1210 // Ensure memory is big enough for both bindings
1211 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
1212 pass = m_device->phy().set_memory_type(
1213 buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info,
1214 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001215 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001216 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001217 vkDestroyImage(m_device->device(), image, NULL);
1218 return;
1219 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001220 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1221 ASSERT_VK_SUCCESS(err);
1222 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1223 ASSERT_VK_SUCCESS(err);
1224
Tobin Ehlisf11be982016-05-11 13:52:53 -06001225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1226 " is aliased with buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001227 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001228 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1229 m_errorMonitor->VerifyFound();
1230
1231 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001232 // aliasing buffer2
1233 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1234 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001235 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1236 ASSERT_VK_SUCCESS(err);
1237 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1238 ASSERT_VK_SUCCESS(err);
1239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1240 " is aliased with image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001241 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001242 m_errorMonitor->VerifyFound();
1243
1244 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001245 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001246 vkDestroyImage(m_device->device(), image, NULL);
1247 vkFreeMemory(m_device->device(), mem, NULL);
1248 vkFreeMemory(m_device->device(), mem_img, NULL);
1249}
1250
Tobin Ehlis35372522016-05-12 08:32:31 -06001251TEST_F(VkLayerTest, InvalidMemoryMapping) {
1252 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1253 VkResult err;
1254 bool pass;
1255 ASSERT_NO_FATAL_FAILURE(InitState());
1256
1257 VkBuffer buffer;
1258 VkDeviceMemory mem;
1259 VkMemoryRequirements mem_reqs;
1260
1261 VkBufferCreateInfo buf_info = {};
1262 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1263 buf_info.pNext = NULL;
1264 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1265 buf_info.size = 256;
1266 buf_info.queueFamilyIndexCount = 0;
1267 buf_info.pQueueFamilyIndices = NULL;
1268 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1269 buf_info.flags = 0;
1270 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1271 ASSERT_VK_SUCCESS(err);
1272
1273 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1274 VkMemoryAllocateInfo alloc_info = {};
1275 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1276 alloc_info.pNext = NULL;
1277 alloc_info.memoryTypeIndex = 0;
1278
1279 // Ensure memory is big enough for both bindings
1280 static const VkDeviceSize allocation_size = 0x10000;
1281 alloc_info.allocationSize = allocation_size;
1282 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1283 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1284 if (!pass) {
1285 vkDestroyBuffer(m_device->device(), buffer, NULL);
1286 return;
1287 }
1288 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1289 ASSERT_VK_SUCCESS(err);
1290
1291 uint8_t *pData;
1292 // Attempt to map memory size 0 is invalid
1293 m_errorMonitor->SetDesiredFailureMsg(
1294 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1295 "VkMapMemory: Attempting to map memory range of size zero");
1296 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1297 m_errorMonitor->VerifyFound();
1298 // Map memory twice
1299 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1300 (void **)&pData);
1301 ASSERT_VK_SUCCESS(err);
1302 m_errorMonitor->SetDesiredFailureMsg(
1303 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1304 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1305 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1306 (void **)&pData);
1307 m_errorMonitor->VerifyFound();
1308
1309 // Unmap the memory to avoid re-map error
1310 vkUnmapMemory(m_device->device(), mem);
1311 // overstep allocation with VK_WHOLE_SIZE
1312 m_errorMonitor->SetDesiredFailureMsg(
1313 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1314 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1315 err = vkMapMemory(m_device->device(), mem, allocation_size + 1,
1316 VK_WHOLE_SIZE, 0, (void **)&pData);
1317 m_errorMonitor->VerifyFound();
1318 // overstep allocation w/o VK_WHOLE_SIZE
1319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1320 " oversteps total array size 0x");
1321 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0,
1322 (void **)&pData);
1323 m_errorMonitor->VerifyFound();
1324 // Now error due to unmapping memory that's not mapped
1325 m_errorMonitor->SetDesiredFailureMsg(
1326 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1327 "Unmapping Memory without memory being mapped: ");
1328 vkUnmapMemory(m_device->device(), mem);
1329 m_errorMonitor->VerifyFound();
1330 // Now map memory and cause errors due to flushing invalid ranges
1331 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0,
1332 (void **)&pData);
1333 ASSERT_VK_SUCCESS(err);
1334 VkMappedMemoryRange mmr = {};
1335 mmr.memory = mem;
1336 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
1337 m_errorMonitor->SetDesiredFailureMsg(
1338 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1339 ") is less than Memory Object's offset (");
1340 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1341 m_errorMonitor->VerifyFound();
1342 // Now flush range that oversteps mapped range
1343 vkUnmapMemory(m_device->device(), mem);
1344 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1345 ASSERT_VK_SUCCESS(err);
1346 mmr.offset = 16;
1347 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
1348 m_errorMonitor->SetDesiredFailureMsg(
1349 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1350 ") exceeds the Memory Object's upper-bound (");
1351 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1352 m_errorMonitor->VerifyFound();
1353
1354 pass =
1355 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1356 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1357 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
1358 if (!pass) {
1359 vkFreeMemory(m_device->device(), mem, NULL);
1360 vkDestroyBuffer(m_device->device(), buffer, NULL);
1361 return;
1362 }
1363 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1364 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1365
1366 vkDestroyBuffer(m_device->device(), buffer, NULL);
1367 vkFreeMemory(m_device->device(), mem, NULL);
1368}
1369
Ian Elliott1c32c772016-04-28 14:47:13 -06001370TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1371 VkResult err;
1372 bool pass;
1373
Ian Elliott489eec02016-05-05 14:12:44 -06001374// FIXME: After we turn on this code for non-Linux platforms, uncomment the
1375// following declaration (which is temporarily being moved below):
1376// VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001377 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1378 VkSwapchainCreateInfoKHR swapchain_create_info = {};
1379 uint32_t swapchain_image_count = 0;
1380// VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1381 uint32_t image_index = 0;
1382// VkPresentInfoKHR present_info = {};
1383
1384 ASSERT_NO_FATAL_FAILURE(InitState());
1385
Ian Elliott3f06ce52016-04-29 14:46:21 -06001386#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1387#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1388 // Use the functions from the VK_KHR_android_surface extension without
1389 // enabling that extension:
1390
1391 // Create a surface:
1392 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001393 m_errorMonitor->SetDesiredFailureMsg(
1394 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1395 "extension was not enabled for this");
1396 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL,
1397 &surface);
1398 pass = (err != VK_SUCCESS);
1399 ASSERT_TRUE(pass);
1400 m_errorMonitor->VerifyFound();
1401#endif // VK_USE_PLATFORM_ANDROID_KHR
1402
1403
1404#if defined(VK_USE_PLATFORM_MIR_KHR)
1405 // Use the functions from the VK_KHR_mir_surface extension without enabling
1406 // that extension:
1407
1408 // Create a surface:
1409 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001410 m_errorMonitor->SetDesiredFailureMsg(
1411 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1412 "extension was not enabled for this");
1413 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1414 pass = (err != VK_SUCCESS);
1415 ASSERT_TRUE(pass);
1416 m_errorMonitor->VerifyFound();
1417
1418 // Tell whether an mir_connection supports presentation:
1419 MirConnection *mir_connection = NULL;
1420 m_errorMonitor->SetDesiredFailureMsg(
1421 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1422 "extension was not enabled for this");
1423 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection,
1424 visual_id);
1425 m_errorMonitor->VerifyFound();
1426#endif // VK_USE_PLATFORM_MIR_KHR
1427
1428
1429#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1430 // Use the functions from the VK_KHR_wayland_surface extension without
1431 // enabling that extension:
1432
1433 // Create a surface:
1434 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001435 m_errorMonitor->SetDesiredFailureMsg(
1436 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1437 "extension was not enabled for this");
1438 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL,
1439 &surface);
1440 pass = (err != VK_SUCCESS);
1441 ASSERT_TRUE(pass);
1442 m_errorMonitor->VerifyFound();
1443
1444 // Tell whether an wayland_display supports presentation:
1445 struct wl_display wayland_display = {};
1446 m_errorMonitor->SetDesiredFailureMsg(
1447 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1448 "extension was not enabled for this");
1449 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0,
1450 &wayland_display);
1451 m_errorMonitor->VerifyFound();
1452#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001453#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001454
1455
1456#if defined(VK_USE_PLATFORM_WIN32_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001457// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1458// TO NON-LINUX PLATFORMS:
1459VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001460 // Use the functions from the VK_KHR_win32_surface extension without
1461 // enabling that extension:
1462
1463 // Create a surface:
1464 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001465 m_errorMonitor->SetDesiredFailureMsg(
1466 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1467 "extension was not enabled for this");
1468 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL,
1469 &surface);
1470 pass = (err != VK_SUCCESS);
1471 ASSERT_TRUE(pass);
1472 m_errorMonitor->VerifyFound();
1473
1474 // Tell whether win32 supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001475 m_errorMonitor->SetDesiredFailureMsg(
1476 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1477 "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001478 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001479 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001480// Set this (for now, until all platforms are supported and tested):
1481#define NEED_TO_TEST_THIS_ON_PLATFORM
1482#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001483
1484
Ian Elliott1c32c772016-04-28 14:47:13 -06001485#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001486// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1487// TO NON-LINUX PLATFORMS:
1488VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001489 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1490 // that extension:
1491
1492 // Create a surface:
1493 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001494 m_errorMonitor->SetDesiredFailureMsg(
1495 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1496 "extension was not enabled for this");
1497 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1498 pass = (err != VK_SUCCESS);
1499 ASSERT_TRUE(pass);
1500 m_errorMonitor->VerifyFound();
1501
1502 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001503 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001504 xcb_visualid_t visual_id = 0;
1505 m_errorMonitor->SetDesiredFailureMsg(
1506 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1507 "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001508 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection,
Ian Elliott1c32c772016-04-28 14:47:13 -06001509 visual_id);
1510 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001511// Set this (for now, until all platforms are supported and tested):
1512#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001513#endif // VK_USE_PLATFORM_XCB_KHR
1514
1515
Ian Elliott12630812016-04-29 14:35:43 -06001516#if defined(VK_USE_PLATFORM_XLIB_KHR)
1517 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1518 // that extension:
1519
1520 // Create a surface:
1521 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Ian Elliott12630812016-04-29 14:35:43 -06001522 m_errorMonitor->SetDesiredFailureMsg(
1523 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1524 "extension was not enabled for this");
1525 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1526 pass = (err != VK_SUCCESS);
1527 ASSERT_TRUE(pass);
1528 m_errorMonitor->VerifyFound();
1529
1530 // Tell whether an Xlib VisualID supports presentation:
1531 Display *dpy = NULL;
1532 VisualID visual = 0;
1533 m_errorMonitor->SetDesiredFailureMsg(
1534 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1535 "extension was not enabled for this");
1536 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1537 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001538// Set this (for now, until all platforms are supported and tested):
1539#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001540#endif // VK_USE_PLATFORM_XLIB_KHR
1541
1542
Ian Elliott1c32c772016-04-28 14:47:13 -06001543 // Use the functions from the VK_KHR_surface extension without enabling
1544 // that extension:
1545
Ian Elliott489eec02016-05-05 14:12:44 -06001546#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001547 // Destroy a surface:
1548 m_errorMonitor->SetDesiredFailureMsg(
1549 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1550 "extension was not enabled for this");
1551 vkDestroySurfaceKHR(instance(), surface, NULL);
1552 m_errorMonitor->VerifyFound();
1553
1554 // Check if surface supports presentation:
1555 VkBool32 supported = false;
1556 m_errorMonitor->SetDesiredFailureMsg(
1557 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1558 "extension was not enabled for this");
1559 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1560 pass = (err != VK_SUCCESS);
1561 ASSERT_TRUE(pass);
1562 m_errorMonitor->VerifyFound();
1563
1564 // Check surface capabilities:
1565 VkSurfaceCapabilitiesKHR capabilities = {};
1566 m_errorMonitor->SetDesiredFailureMsg(
1567 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1568 "extension was not enabled for this");
1569 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1570 &capabilities);
1571 pass = (err != VK_SUCCESS);
1572 ASSERT_TRUE(pass);
1573 m_errorMonitor->VerifyFound();
1574
1575 // Check surface formats:
1576 uint32_t format_count = 0;
1577 VkSurfaceFormatKHR *formats = NULL;
1578 m_errorMonitor->SetDesiredFailureMsg(
1579 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1580 "extension was not enabled for this");
1581 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1582 &format_count, formats);
1583 pass = (err != VK_SUCCESS);
1584 ASSERT_TRUE(pass);
1585 m_errorMonitor->VerifyFound();
1586
1587 // Check surface present modes:
1588 uint32_t present_mode_count = 0;
1589 VkSurfaceFormatKHR *present_modes = NULL;
1590 m_errorMonitor->SetDesiredFailureMsg(
1591 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1592 "extension was not enabled for this");
1593 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1594 &present_mode_count, present_modes);
1595 pass = (err != VK_SUCCESS);
1596 ASSERT_TRUE(pass);
1597 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001598#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001599
1600
1601 // Use the functions from the VK_KHR_swapchain extension without enabling
1602 // that extension:
1603
1604 // Create a swapchain:
1605 m_errorMonitor->SetDesiredFailureMsg(
1606 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1607 "extension was not enabled for this");
1608 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1609 swapchain_create_info.pNext = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001610 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info,
1611 NULL, &swapchain);
1612 pass = (err != VK_SUCCESS);
1613 ASSERT_TRUE(pass);
1614 m_errorMonitor->VerifyFound();
1615
1616 // Get the images from the swapchain:
1617 m_errorMonitor->SetDesiredFailureMsg(
1618 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1619 "extension was not enabled for this");
1620 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain,
1621 &swapchain_image_count, NULL);
1622 pass = (err != VK_SUCCESS);
1623 ASSERT_TRUE(pass);
1624 m_errorMonitor->VerifyFound();
1625
1626 // Try to acquire an image:
1627 m_errorMonitor->SetDesiredFailureMsg(
1628 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1629 "extension was not enabled for this");
1630 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0,
1631 VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index);
1632 pass = (err != VK_SUCCESS);
1633 ASSERT_TRUE(pass);
1634 m_errorMonitor->VerifyFound();
1635
1636 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001637 //
1638 // NOTE: Currently can't test this because a real swapchain is needed (as
1639 // opposed to the fake one we created) in order for the layer to lookup the
1640 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001641
1642 // Destroy the swapchain:
1643 m_errorMonitor->SetDesiredFailureMsg(
1644 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1645 "extension was not enabled for this");
1646 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1647 m_errorMonitor->VerifyFound();
1648}
1649
Ian Elliott2c1daf52016-05-12 09:41:46 -06001650TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06001651
Dustin Graves6c6d8982016-05-17 10:09:21 -06001652#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06001653 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001654
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001655 VkResult err;
1656 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06001657 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1658 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001659 // uint32_t swapchain_image_count = 0;
1660 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1661 // uint32_t image_index = 0;
1662 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06001663
1664 ASSERT_NO_FATAL_FAILURE(InitState());
1665
1666 // Use the create function from one of the VK_KHR_*_surface extension in
1667 // order to create a surface, testing all known errors in the process,
1668 // before successfully creating a surface:
1669 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1671 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001672 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
1673 pass = (err != VK_SUCCESS);
1674 ASSERT_TRUE(pass);
1675 m_errorMonitor->VerifyFound();
1676
1677 // Next, try to create a surface with the wrong
1678 // VkXcbSurfaceCreateInfoKHR::sType:
1679 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
1680 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1682 "called with the wrong value for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001683 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1684 pass = (err != VK_SUCCESS);
1685 ASSERT_TRUE(pass);
1686 m_errorMonitor->VerifyFound();
1687
Ian Elliott2c1daf52016-05-12 09:41:46 -06001688 // Create a native window, and then correctly create a surface:
1689 xcb_connection_t *connection;
1690 xcb_screen_t *screen;
1691 xcb_window_t xcb_window;
1692 xcb_intern_atom_reply_t *atom_wm_delete_window;
1693
1694 const xcb_setup_t *setup;
1695 xcb_screen_iterator_t iter;
1696 int scr;
1697 uint32_t value_mask, value_list[32];
1698 int width = 1;
1699 int height = 1;
1700
1701 connection = xcb_connect(NULL, &scr);
1702 ASSERT_TRUE(connection != NULL);
1703 setup = xcb_get_setup(connection);
1704 iter = xcb_setup_roots_iterator(setup);
1705 while (scr-- > 0)
1706 xcb_screen_next(&iter);
1707 screen = iter.data;
1708
1709 xcb_window = xcb_generate_id(connection);
1710
1711 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
1712 value_list[0] = screen->black_pixel;
1713 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE |
1714 XCB_EVENT_MASK_STRUCTURE_NOTIFY;
1715
1716 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window,
1717 screen->root, 0, 0, width, height, 0,
1718 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual,
1719 value_mask, value_list);
1720
1721 /* Magic code that will send notification when window is destroyed */
1722 xcb_intern_atom_cookie_t cookie =
1723 xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
1724 xcb_intern_atom_reply_t *reply =
1725 xcb_intern_atom_reply(connection, cookie, 0);
1726
1727 xcb_intern_atom_cookie_t cookie2 =
1728 xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001729 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001730 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window,
1731 (*reply).atom, 4, 32, 1,
1732 &(*atom_wm_delete_window).atom);
1733 free(reply);
1734
1735 xcb_map_window(connection, xcb_window);
1736
1737 // Force the x/y coordinates to 100,100 results are identical in consecutive
1738 // runs
1739 const uint32_t coords[] = {100, 100};
1740 xcb_configure_window(connection, xcb_window,
1741 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
1742
Ian Elliott2c1daf52016-05-12 09:41:46 -06001743 // Finally, try to correctly create a surface:
1744 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
1745 xcb_create_info.pNext = NULL;
1746 xcb_create_info.flags = 0;
1747 xcb_create_info.connection = connection;
1748 xcb_create_info.window = xcb_window;
1749 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1750 pass = (err == VK_SUCCESS);
1751 ASSERT_TRUE(pass);
1752
Ian Elliott2c1daf52016-05-12 09:41:46 -06001753 // Check if surface supports presentation:
1754
1755 // 1st, do so without having queried the queue families:
1756 VkBool32 supported = false;
1757 // TODO: Get the following error to come out:
1758 m_errorMonitor->SetDesiredFailureMsg(
1759 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1760 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
1761 "function");
1762 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1763 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001764 // ASSERT_TRUE(pass);
1765 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06001766
1767 // Next, query a queue family index that's too large:
1768 m_errorMonitor->SetDesiredFailureMsg(
1769 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1770 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001771 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface,
1772 &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001773 pass = (err != VK_SUCCESS);
1774 ASSERT_TRUE(pass);
1775 m_errorMonitor->VerifyFound();
1776
1777 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001778 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
1779 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06001780 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1781 pass = (err == VK_SUCCESS);
1782 ASSERT_TRUE(pass);
1783
Ian Elliott2c1daf52016-05-12 09:41:46 -06001784 // Before proceeding, try to create a swapchain without having called
1785 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
1786 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1787 swapchain_create_info.pNext = NULL;
1788 swapchain_create_info.flags = 0;
1789 m_errorMonitor->SetDesiredFailureMsg(
1790 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1791 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001792 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1793 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001794 pass = (err != VK_SUCCESS);
1795 ASSERT_TRUE(pass);
1796 m_errorMonitor->VerifyFound();
1797
Ian Elliott2c1daf52016-05-12 09:41:46 -06001798 // Get the surface capabilities:
1799 VkSurfaceCapabilitiesKHR surface_capabilities;
1800
1801 // Do so correctly (only error logged by this entrypoint is if the
1802 // extension isn't enabled):
1803 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1804 &surface_capabilities);
1805 pass = (err == VK_SUCCESS);
1806 ASSERT_TRUE(pass);
1807
Ian Elliott2c1daf52016-05-12 09:41:46 -06001808 // Get the surface formats:
1809 uint32_t surface_format_count;
1810
1811 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1813 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001814 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
1815 pass = (err == VK_SUCCESS);
1816 ASSERT_TRUE(pass);
1817 m_errorMonitor->VerifyFound();
1818
1819 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
1820 // correctly done a 1st try (to get the count):
1821 m_errorMonitor->SetDesiredFailureMsg(
1822 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1823 "but no prior positive value has been seen for");
1824 surface_format_count = 0;
1825 vkGetPhysicalDeviceSurfaceFormatsKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001826 gpu(), surface, &surface_format_count,
1827 (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001828 pass = (err == VK_SUCCESS);
1829 ASSERT_TRUE(pass);
1830 m_errorMonitor->VerifyFound();
1831
1832 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001833 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1834 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001835 pass = (err == VK_SUCCESS);
1836 ASSERT_TRUE(pass);
1837
1838 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001839 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(
1840 surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001841
1842 // Next, do a 2nd try with surface_format_count being set too high:
1843 surface_format_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1845 "that is greater than the value");
1846 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001847 surface_formats);
1848 pass = (err == VK_SUCCESS);
1849 ASSERT_TRUE(pass);
1850 m_errorMonitor->VerifyFound();
1851
1852 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001853 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1854 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001855 pass = (err == VK_SUCCESS);
1856 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001857 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001858 surface_formats);
1859 pass = (err == VK_SUCCESS);
1860 ASSERT_TRUE(pass);
1861
Ian Elliott2c1daf52016-05-12 09:41:46 -06001862 // Get the surface present modes:
1863 uint32_t surface_present_mode_count;
1864
1865 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1867 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001868 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
1869 pass = (err == VK_SUCCESS);
1870 ASSERT_TRUE(pass);
1871 m_errorMonitor->VerifyFound();
1872
1873 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
1874 // correctly done a 1st try (to get the count):
1875 m_errorMonitor->SetDesiredFailureMsg(
1876 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1877 "but no prior positive value has been seen for");
1878 surface_present_mode_count = 0;
1879 vkGetPhysicalDeviceSurfacePresentModesKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001880 gpu(), surface, &surface_present_mode_count,
1881 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001882 pass = (err == VK_SUCCESS);
1883 ASSERT_TRUE(pass);
1884 m_errorMonitor->VerifyFound();
1885
1886 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001887 vkGetPhysicalDeviceSurfacePresentModesKHR(
1888 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001889 pass = (err == VK_SUCCESS);
1890 ASSERT_TRUE(pass);
1891
1892 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001893 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(
1894 surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001895
1896 // Next, do a 2nd try with surface_format_count being set too high:
1897 surface_present_mode_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1899 "that is greater than the value");
1900 vkGetPhysicalDeviceSurfacePresentModesKHR(
1901 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001902 pass = (err == VK_SUCCESS);
1903 ASSERT_TRUE(pass);
1904 m_errorMonitor->VerifyFound();
1905
1906 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001907 vkGetPhysicalDeviceSurfacePresentModesKHR(
1908 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001909 pass = (err == VK_SUCCESS);
1910 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001911 vkGetPhysicalDeviceSurfacePresentModesKHR(
1912 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001913 pass = (err == VK_SUCCESS);
1914 ASSERT_TRUE(pass);
1915
Ian Elliott2c1daf52016-05-12 09:41:46 -06001916 // Create a swapchain:
1917
1918 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1920 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001921 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
1922 pass = (err != VK_SUCCESS);
1923 ASSERT_TRUE(pass);
1924 m_errorMonitor->VerifyFound();
1925
1926 // Next, call with a non-NULL swapchain_create_info, that has the wrong
1927 // sType:
1928 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1930 "called with the wrong value for");
1931 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1932 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001933 pass = (err != VK_SUCCESS);
1934 ASSERT_TRUE(pass);
1935 m_errorMonitor->VerifyFound();
1936
1937 // Next, call with a NULL swapchain pointer:
1938 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1939 swapchain_create_info.pNext = NULL;
1940 swapchain_create_info.flags = 0;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1942 "called with NULL pointer");
1943 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1944 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001945 pass = (err != VK_SUCCESS);
1946 ASSERT_TRUE(pass);
1947 m_errorMonitor->VerifyFound();
1948
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001949 // TODO: Enhance swapchain layer so that
1950 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06001951
1952 // Next, call with a queue family index that's too large:
1953 uint32_t queueFamilyIndex[2] = {100000, 0};
1954 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
1955 swapchain_create_info.queueFamilyIndexCount = 2;
1956 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
1957 m_errorMonitor->SetDesiredFailureMsg(
1958 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1959 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001960 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1961 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001962 pass = (err != VK_SUCCESS);
1963 ASSERT_TRUE(pass);
1964 m_errorMonitor->VerifyFound();
1965
1966 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
1967 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
1968 swapchain_create_info.queueFamilyIndexCount = 1;
1969 m_errorMonitor->SetDesiredFailureMsg(
1970 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1971 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
1972 "pCreateInfo->pQueueFamilyIndices).");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001973 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1974 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001975 pass = (err != VK_SUCCESS);
1976 ASSERT_TRUE(pass);
1977 m_errorMonitor->VerifyFound();
1978
1979 // Next, call with an invalid imageSharingMode:
1980 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
1981 swapchain_create_info.queueFamilyIndexCount = 1;
1982 m_errorMonitor->SetDesiredFailureMsg(
1983 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1984 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001985 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1986 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001987 pass = (err != VK_SUCCESS);
1988 ASSERT_TRUE(pass);
1989 m_errorMonitor->VerifyFound();
1990 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001991 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
1992 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06001993 swapchain_create_info.queueFamilyIndexCount = 0;
1994 queueFamilyIndex[0] = 0;
1995 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
1996
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001997 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06001998 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001999 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002000 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002001 // Destroy the swapchain:
2002
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002003 // TODOs:
2004 //
2005 // - Try destroying the device without first destroying the swapchain
2006 //
2007 // - Try destroying the device without first destroying the surface
2008 //
2009 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002010
2011 // Destroy the surface:
2012 vkDestroySurfaceKHR(instance(), surface, NULL);
2013
Ian Elliott2c1daf52016-05-12 09:41:46 -06002014 // Tear down the window:
2015 xcb_destroy_window(connection, xcb_window);
2016 xcb_disconnect(connection);
2017
2018#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002019 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002020#endif // VK_USE_PLATFORM_XCB_KHR
2021}
2022
Karl Schultz6addd812016-02-02 17:17:23 -07002023TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2024 VkResult err;
2025 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002026
Karl Schultz6addd812016-02-02 17:17:23 -07002027 m_errorMonitor->SetDesiredFailureMsg(
2028 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002029 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
2030
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002031 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002032
2033 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002034 VkImage image;
2035 VkDeviceMemory mem;
2036 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002037
Karl Schultz6addd812016-02-02 17:17:23 -07002038 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2039 const int32_t tex_width = 32;
2040 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002041
Tony Barboureb254902015-07-15 12:50:33 -06002042 VkImageCreateInfo image_create_info = {};
2043 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002044 image_create_info.pNext = NULL;
2045 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2046 image_create_info.format = tex_format;
2047 image_create_info.extent.width = tex_width;
2048 image_create_info.extent.height = tex_height;
2049 image_create_info.extent.depth = 1;
2050 image_create_info.mipLevels = 1;
2051 image_create_info.arrayLayers = 1;
2052 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2053 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2054 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2055 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002056
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002057 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002058 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002059 mem_alloc.pNext = NULL;
2060 mem_alloc.allocationSize = 0;
2061 // Introduce failure, do NOT set memProps to
2062 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
2063 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002064
Chia-I Wuf7458c52015-10-26 21:10:41 +08002065 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002066 ASSERT_VK_SUCCESS(err);
2067
Karl Schultz6addd812016-02-02 17:17:23 -07002068 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002069
Mark Lobodzinski23065352015-05-29 09:32:35 -05002070 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002071
Karl Schultz6addd812016-02-02 17:17:23 -07002072 pass =
2073 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0,
2074 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
2075 if (!pass) { // If we can't find any unmappable memory this test doesn't
2076 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002077 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002078 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002079 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002080
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002081 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002082 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002083 ASSERT_VK_SUCCESS(err);
2084
2085 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002086 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002087 ASSERT_VK_SUCCESS(err);
2088
2089 // Map memory as if to initialize the image
2090 void *mappedAddress = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07002091 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0,
2092 &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002093
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002094 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002095
Chia-I Wuf7458c52015-10-26 21:10:41 +08002096 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002097}
2098
Karl Schultz6addd812016-02-02 17:17:23 -07002099TEST_F(VkLayerTest, RebindMemory) {
2100 VkResult err;
2101 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002102
Karl Schultz6addd812016-02-02 17:17:23 -07002103 m_errorMonitor->SetDesiredFailureMsg(
2104 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002105 "which has already been bound to mem object");
2106
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002107 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002108
2109 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002110 VkImage image;
2111 VkDeviceMemory mem1;
2112 VkDeviceMemory mem2;
2113 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002114
Karl Schultz6addd812016-02-02 17:17:23 -07002115 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2116 const int32_t tex_width = 32;
2117 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002118
Tony Barboureb254902015-07-15 12:50:33 -06002119 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002120 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2121 image_create_info.pNext = NULL;
2122 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2123 image_create_info.format = tex_format;
2124 image_create_info.extent.width = tex_width;
2125 image_create_info.extent.height = tex_height;
2126 image_create_info.extent.depth = 1;
2127 image_create_info.mipLevels = 1;
2128 image_create_info.arrayLayers = 1;
2129 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2130 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2131 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2132 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002133
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002134 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002135 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2136 mem_alloc.pNext = NULL;
2137 mem_alloc.allocationSize = 0;
2138 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002139
Karl Schultz6addd812016-02-02 17:17:23 -07002140 // Introduce failure, do NOT set memProps to
2141 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002142 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002143 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002144 ASSERT_VK_SUCCESS(err);
2145
Karl Schultz6addd812016-02-02 17:17:23 -07002146 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002147
2148 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002149 pass =
2150 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002151 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002152
2153 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002154 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002155 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002156 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002157 ASSERT_VK_SUCCESS(err);
2158
2159 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002160 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002161 ASSERT_VK_SUCCESS(err);
2162
Karl Schultz6addd812016-02-02 17:17:23 -07002163 // Introduce validation failure, try to bind a different memory object to
2164 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002165 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002166
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002167 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002168
Chia-I Wuf7458c52015-10-26 21:10:41 +08002169 vkDestroyImage(m_device->device(), image, NULL);
2170 vkFreeMemory(m_device->device(), mem1, NULL);
2171 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002172}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002173
Karl Schultz6addd812016-02-02 17:17:23 -07002174TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002175 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002176
Karl Schultz6addd812016-02-02 17:17:23 -07002177 m_errorMonitor->SetDesiredFailureMsg(
2178 VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2179 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002180
2181 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002182 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2183 fenceInfo.pNext = NULL;
2184 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002185
Tony Barbour300a6082015-04-07 13:44:53 -06002186 ASSERT_NO_FATAL_FAILURE(InitState());
2187 ASSERT_NO_FATAL_FAILURE(InitViewport());
2188 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2189
Tony Barbourfe3351b2015-07-28 10:17:20 -06002190 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002191 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
2192 m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002193 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002194
2195 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002196
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002197 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002198 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2199 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002200 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002201 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002202 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002203 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002204 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002205 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002206 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002207
2208 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002209 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002210
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002211 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002212}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002213// This is a positive test. We used to expect error in this case but spec now
2214// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002215TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002216 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002217 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002218 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002219 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2220 fenceInfo.pNext = NULL;
2221
Tony Barbour0b4d9562015-04-09 10:48:04 -06002222 ASSERT_NO_FATAL_FAILURE(InitState());
2223 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002224 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002225 VkResult result = vkResetFences(m_device->device(), 1, fences);
2226 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002227
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002228 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002229}
Tobin Ehlis41376e12015-07-03 08:45:14 -06002230
2231TEST_F(VkLayerTest, InvalidUsageBits)
2232{
Tony Barbourf92621a2016-05-02 14:28:12 -06002233 TEST_DESCRIPTION(
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002234 "Specify wrong usage for image then create conflicting view of image "
Tony Barbourf92621a2016-05-02 14:28:12 -06002235 "Initialize buffer with wrong usage then perform copy expecting errors "
2236 "from both the image and the buffer (2 calls)");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002238 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002239
2240 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002241 VkImageObj image(m_device);
2242 // Initialize image with USAGE_INPUT_ATTACHMENT
2243 image.init(128, 128, VK_FORMAT_D32_SFLOAT_S8_UINT,
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002244 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
2245 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002246
Tony Barbourf92621a2016-05-02 14:28:12 -06002247 VkImageView dsv;
2248 VkImageViewCreateInfo dsvci = {};
2249 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2250 dsvci.image = image.handle();
2251 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2252 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2253 dsvci.subresourceRange.layerCount = 1;
2254 dsvci.subresourceRange.baseMipLevel = 0;
2255 dsvci.subresourceRange.levelCount = 1;
2256 dsvci.subresourceRange.aspectMask =
2257 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002258
Tony Barbourf92621a2016-05-02 14:28:12 -06002259 // Create a view with depth / stencil aspect for image with different usage
2260 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002261
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002262 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002263
2264 // Initialize buffer with TRANSFER_DST usage
2265 vk_testing::Buffer buffer;
2266 VkMemoryPropertyFlags reqs = 0;
2267 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2268 VkBufferImageCopy region = {};
2269 region.bufferRowLength = 128;
2270 region.bufferImageHeight = 128;
2271 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2272 region.imageSubresource.layerCount = 1;
2273 region.imageExtent.height = 16;
2274 region.imageExtent.width = 16;
2275 region.imageExtent.depth = 1;
2276
2277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2278 "Invalid usage flag for buffer ");
2279 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2280 // TRANSFER_DST
2281 BeginCommandBuffer();
2282 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2283 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2284 1, &region);
2285 m_errorMonitor->VerifyFound();
2286
2287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2288 "Invalid usage flag for image ");
2289 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2290 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2291 1, &region);
2292 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002293}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002294#endif // MEM_TRACKER_TESTS
2295
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002296#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002297
2298TEST_F(VkLayerTest, LeakAnObject) {
2299 VkResult err;
2300
2301 TEST_DESCRIPTION(
2302 "Create a fence and destroy its device without first destroying the fence.");
2303
2304 // Note that we have to create a new device since destroying the
2305 // framework's device causes Teardown() to fail and just calling Teardown
2306 // will destroy the errorMonitor.
2307
2308 m_errorMonitor->SetDesiredFailureMsg(
2309 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2310 "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object");
2311
2312 ASSERT_NO_FATAL_FAILURE(InitState());
2313
2314 const std::vector<VkQueueFamilyProperties> queue_props =
2315 m_device->queue_props;
2316 std::vector<VkDeviceQueueCreateInfo> queue_info;
2317 queue_info.reserve(queue_props.size());
2318 std::vector<std::vector<float>> queue_priorities;
2319 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2320 VkDeviceQueueCreateInfo qi = {};
2321 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2322 qi.pNext = NULL;
2323 qi.queueFamilyIndex = i;
2324 qi.queueCount = queue_props[i].queueCount;
2325 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2326 qi.pQueuePriorities = queue_priorities[i].data();
2327 queue_info.push_back(qi);
2328 }
2329
2330 std::vector<const char *> device_layer_names;
2331 std::vector<const char *> device_extension_names;
2332 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
2333 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
2334 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
2335 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
2336 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
2337 device_layer_names.push_back("VK_LAYER_LUNARG_image");
2338 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
2339
2340 // The sacrificial device object
2341 VkDevice testDevice;
2342 VkDeviceCreateInfo device_create_info = {};
2343 auto features = m_device->phy().features();
2344 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2345 device_create_info.pNext = NULL;
2346 device_create_info.queueCreateInfoCount = queue_info.size();
2347 device_create_info.pQueueCreateInfos = queue_info.data();
2348 device_create_info.enabledLayerCount = device_layer_names.size();
2349 device_create_info.ppEnabledLayerNames = device_layer_names.data();
2350 device_create_info.pEnabledFeatures = &features;
2351 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2352 ASSERT_VK_SUCCESS(err);
2353
2354 VkFence fence;
2355 VkFenceCreateInfo fence_create_info = {};
2356 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2357 fence_create_info.pNext = NULL;
2358 fence_create_info.flags = 0;
2359 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2360 ASSERT_VK_SUCCESS(err);
2361
2362 // Induce failure by not calling vkDestroyFence
2363 vkDestroyDevice(testDevice, NULL);
2364 m_errorMonitor->VerifyFound();
2365}
2366
2367TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2368
2369 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2370 "attempt to delete them from another.");
2371
2372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2373 "FreeCommandBuffers is attempting to free Command Buffer");
2374
2375 VkCommandPool command_pool_one;
2376 VkCommandPool command_pool_two;
2377
2378 VkCommandPoolCreateInfo pool_create_info{};
2379 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2380 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2381 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2382
2383 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2384 &command_pool_one);
2385
2386 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2387 &command_pool_two);
2388
2389 VkCommandBuffer command_buffer[9];
2390 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2391 command_buffer_allocate_info.sType =
2392 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2393 command_buffer_allocate_info.commandPool = command_pool_one;
2394 command_buffer_allocate_info.commandBufferCount = 9;
2395 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2396 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2397 command_buffer);
2398
2399 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4,
2400 &command_buffer[3]);
2401
2402 m_errorMonitor->VerifyFound();
2403
2404 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2405 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2406}
2407
2408TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2409 VkResult err;
2410
2411 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
2412 "attempt to delete them from another.");
2413
2414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2415 "FreeDescriptorSets is attempting to free descriptorSet");
2416
2417 ASSERT_NO_FATAL_FAILURE(InitState());
2418 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2419
2420 VkDescriptorPoolSize ds_type_count = {};
2421 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2422 ds_type_count.descriptorCount = 1;
2423
2424 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2425 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2426 ds_pool_ci.pNext = NULL;
2427 ds_pool_ci.flags = 0;
2428 ds_pool_ci.maxSets = 1;
2429 ds_pool_ci.poolSizeCount = 1;
2430 ds_pool_ci.pPoolSizes = &ds_type_count;
2431
2432 VkDescriptorPool ds_pool_one;
2433 err =
2434 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
2435 ASSERT_VK_SUCCESS(err);
2436
2437 // Create a second descriptor pool
2438 VkDescriptorPool ds_pool_two;
2439 err =
2440 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
2441 ASSERT_VK_SUCCESS(err);
2442
2443 VkDescriptorSetLayoutBinding dsl_binding = {};
2444 dsl_binding.binding = 0;
2445 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2446 dsl_binding.descriptorCount = 1;
2447 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2448 dsl_binding.pImmutableSamplers = NULL;
2449
2450 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2451 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2452 ds_layout_ci.pNext = NULL;
2453 ds_layout_ci.bindingCount = 1;
2454 ds_layout_ci.pBindings = &dsl_binding;
2455
2456 VkDescriptorSetLayout ds_layout;
2457 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2458 &ds_layout);
2459 ASSERT_VK_SUCCESS(err);
2460
2461 VkDescriptorSet descriptorSet;
2462 VkDescriptorSetAllocateInfo alloc_info = {};
2463 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2464 alloc_info.descriptorSetCount = 1;
2465 alloc_info.descriptorPool = ds_pool_one;
2466 alloc_info.pSetLayouts = &ds_layout;
2467 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2468 &descriptorSet);
2469 ASSERT_VK_SUCCESS(err);
2470
2471 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2472
2473 m_errorMonitor->VerifyFound();
2474
2475 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2476 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2477 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2478}
2479
2480TEST_F(VkLayerTest, CreateUnknownObject) {
2481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2482 "Invalid VkImage Object ");
2483
2484 TEST_DESCRIPTION(
2485 "Pass an invalid image object handle into a Vulkan API call.");
2486
2487 ASSERT_NO_FATAL_FAILURE(InitState());
2488
2489 // Pass bogus handle into GetImageMemoryRequirements
2490 VkMemoryRequirements mem_reqs;
2491 uint64_t fakeImageHandle = 0xCADECADE;
2492 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2493
2494 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2495
2496 m_errorMonitor->VerifyFound();
2497}
2498
Karl Schultz6addd812016-02-02 17:17:23 -07002499TEST_F(VkLayerTest, PipelineNotBound) {
2500 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002501
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002502 TEST_DESCRIPTION(
2503 "Pass in an invalid pipeline object handle into a Vulkan API call.");
2504
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002506 "Invalid VkPipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002507
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002508 ASSERT_NO_FATAL_FAILURE(InitState());
2509 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002510
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002511 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002512 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2513 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002514
2515 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002516 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2517 ds_pool_ci.pNext = NULL;
2518 ds_pool_ci.maxSets = 1;
2519 ds_pool_ci.poolSizeCount = 1;
2520 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002521
2522 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002523 err =
2524 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002525 ASSERT_VK_SUCCESS(err);
2526
2527 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002528 dsl_binding.binding = 0;
2529 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2530 dsl_binding.descriptorCount = 1;
2531 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2532 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002533
2534 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002535 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2536 ds_layout_ci.pNext = NULL;
2537 ds_layout_ci.bindingCount = 1;
2538 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002539
2540 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002541 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2542 &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002543 ASSERT_VK_SUCCESS(err);
2544
2545 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002546 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002547 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002548 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002549 alloc_info.descriptorPool = ds_pool;
2550 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002551 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2552 &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002553 ASSERT_VK_SUCCESS(err);
2554
2555 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002556 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2557 pipeline_layout_ci.pNext = NULL;
2558 pipeline_layout_ci.setLayoutCount = 1;
2559 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002560
2561 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002562 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2563 &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002564 ASSERT_VK_SUCCESS(err);
2565
Mark Youngad779052016-01-06 14:26:04 -07002566 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002567
2568 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002569 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
2570 VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002571
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002572 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002573
Chia-I Wuf7458c52015-10-26 21:10:41 +08002574 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2575 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2576 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002577}
2578
Karl Schultz6addd812016-02-02 17:17:23 -07002579TEST_F(VkLayerTest, BindInvalidMemory) {
2580 VkResult err;
2581 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002582
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002584 "Invalid VkDeviceMemory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002585
Tobin Ehlisec598302015-09-15 15:02:17 -06002586 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002587
2588 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002589 VkImage image;
2590 VkDeviceMemory mem;
2591 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002592
Karl Schultz6addd812016-02-02 17:17:23 -07002593 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2594 const int32_t tex_width = 32;
2595 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002596
2597 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002598 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2599 image_create_info.pNext = NULL;
2600 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2601 image_create_info.format = tex_format;
2602 image_create_info.extent.width = tex_width;
2603 image_create_info.extent.height = tex_height;
2604 image_create_info.extent.depth = 1;
2605 image_create_info.mipLevels = 1;
2606 image_create_info.arrayLayers = 1;
2607 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2608 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2609 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2610 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002611
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002612 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002613 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2614 mem_alloc.pNext = NULL;
2615 mem_alloc.allocationSize = 0;
2616 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002617
Chia-I Wuf7458c52015-10-26 21:10:41 +08002618 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002619 ASSERT_VK_SUCCESS(err);
2620
Karl Schultz6addd812016-02-02 17:17:23 -07002621 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002622
2623 mem_alloc.allocationSize = mem_reqs.size;
2624
Karl Schultz6addd812016-02-02 17:17:23 -07002625 pass =
2626 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002627 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002628
2629 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002630 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002631 ASSERT_VK_SUCCESS(err);
2632
2633 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002634 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002635
2636 // Try to bind free memory that has been freed
2637 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2638 // This may very well return an error.
2639 (void)err;
2640
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002641 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002642
Chia-I Wuf7458c52015-10-26 21:10:41 +08002643 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002644}
2645
Karl Schultz6addd812016-02-02 17:17:23 -07002646TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2647 VkResult err;
2648 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002649
Karl Schultz6addd812016-02-02 17:17:23 -07002650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2651 "Invalid VkImage Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002652
Tobin Ehlisec598302015-09-15 15:02:17 -06002653 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002654
Karl Schultz6addd812016-02-02 17:17:23 -07002655 // Create an image object, allocate memory, destroy the object and then try
2656 // to bind it
2657 VkImage image;
2658 VkDeviceMemory mem;
2659 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002660
Karl Schultz6addd812016-02-02 17:17:23 -07002661 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2662 const int32_t tex_width = 32;
2663 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002664
2665 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002666 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2667 image_create_info.pNext = NULL;
2668 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2669 image_create_info.format = tex_format;
2670 image_create_info.extent.width = tex_width;
2671 image_create_info.extent.height = tex_height;
2672 image_create_info.extent.depth = 1;
2673 image_create_info.mipLevels = 1;
2674 image_create_info.arrayLayers = 1;
2675 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2676 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2677 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2678 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002679
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002680 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002681 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2682 mem_alloc.pNext = NULL;
2683 mem_alloc.allocationSize = 0;
2684 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002685
Chia-I Wuf7458c52015-10-26 21:10:41 +08002686 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002687 ASSERT_VK_SUCCESS(err);
2688
Karl Schultz6addd812016-02-02 17:17:23 -07002689 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002690
2691 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002692 pass =
2693 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002694 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002695
2696 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002697 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002698 ASSERT_VK_SUCCESS(err);
2699
2700 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002701 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002702 ASSERT_VK_SUCCESS(err);
2703
2704 // Now Try to bind memory to this destroyed object
2705 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2706 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002707 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002708
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002709 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002710
Chia-I Wuf7458c52015-10-26 21:10:41 +08002711 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002712}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002713
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002714#endif // OBJ_TRACKER_TESTS
2715
Tobin Ehlis0788f522015-05-26 16:11:58 -06002716#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002717
2718// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05002719TEST_F(VkLayerTest, WaitEventThenSet) {
2720 TEST_DESCRIPTION(
2721 "Wait on a event then set it after the wait has been submitted.");
2722
2723 if ((m_device->queue_props.empty()) ||
2724 (m_device->queue_props[0].queueCount < 2))
2725 return;
2726
2727 m_errorMonitor->ExpectSuccess();
2728
2729 VkEvent event;
2730 VkEventCreateInfo event_create_info{};
2731 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2732 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
2733
2734 VkCommandPool command_pool;
2735 VkCommandPoolCreateInfo pool_create_info{};
2736 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2737 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2738 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2739 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2740 &command_pool);
2741
2742 VkCommandBuffer command_buffer;
2743 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2744 command_buffer_allocate_info.sType =
2745 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2746 command_buffer_allocate_info.commandPool = command_pool;
2747 command_buffer_allocate_info.commandBufferCount = 1;
2748 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2749 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2750 &command_buffer);
2751
2752 VkQueue queue = VK_NULL_HANDLE;
2753 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2754 1, &queue);
2755
2756 {
2757 VkCommandBufferBeginInfo begin_info{};
2758 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2759 vkBeginCommandBuffer(command_buffer, &begin_info);
2760
2761 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT,
2762 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
2763 nullptr, 0, nullptr);
2764 vkCmdResetEvent(command_buffer, event,
2765 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
2766 vkEndCommandBuffer(command_buffer);
2767 }
2768 {
2769 VkSubmitInfo submit_info{};
2770 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2771 submit_info.commandBufferCount = 1;
2772 submit_info.pCommandBuffers = &command_buffer;
2773 submit_info.signalSemaphoreCount = 0;
2774 submit_info.pSignalSemaphores = nullptr;
2775 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2776 }
2777 { vkSetEvent(m_device->device(), event); }
2778
2779 vkQueueWaitIdle(queue);
2780
2781 vkDestroyEvent(m_device->device(), event, nullptr);
2782 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
2783 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2784
2785 m_errorMonitor->VerifyNotFound();
2786}
Michael Lentine5627e692016-05-20 17:45:02 -05002787// This is a positive test. No errors should be generated.
2788TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
2789 TEST_DESCRIPTION(
2790 "Issue a query and copy from it on a second command buffer.");
2791
2792 if ((m_device->queue_props.empty()) ||
2793 (m_device->queue_props[0].queueCount < 2))
2794 return;
2795
2796 m_errorMonitor->ExpectSuccess();
2797
2798 VkQueryPool query_pool;
2799 VkQueryPoolCreateInfo query_pool_create_info{};
2800 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
2801 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
2802 query_pool_create_info.queryCount = 1;
2803 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr,
2804 &query_pool);
2805
2806 VkCommandPool command_pool;
2807 VkCommandPoolCreateInfo pool_create_info{};
2808 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2809 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2810 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2811 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2812 &command_pool);
2813
2814 VkCommandBuffer command_buffer[2];
2815 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2816 command_buffer_allocate_info.sType =
2817 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2818 command_buffer_allocate_info.commandPool = command_pool;
2819 command_buffer_allocate_info.commandBufferCount = 2;
2820 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2821 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2822 command_buffer);
2823
2824 VkQueue queue = VK_NULL_HANDLE;
2825 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2826 1, &queue);
2827
2828 uint32_t qfi = 0;
2829 VkBufferCreateInfo buff_create_info = {};
2830 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2831 buff_create_info.size = 1024;
2832 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
2833 buff_create_info.queueFamilyIndexCount = 1;
2834 buff_create_info.pQueueFamilyIndices = &qfi;
2835
2836 VkResult err;
2837 VkBuffer buffer;
2838 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
2839 ASSERT_VK_SUCCESS(err);
2840 VkMemoryAllocateInfo mem_alloc = {};
2841 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2842 mem_alloc.pNext = NULL;
2843 mem_alloc.allocationSize = 1024;
2844 mem_alloc.memoryTypeIndex = 0;
2845
2846 VkMemoryRequirements memReqs;
2847 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
2848 bool pass =
2849 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
2850 if (!pass) {
2851 vkDestroyBuffer(m_device->device(), buffer, NULL);
2852 return;
2853 }
2854
2855 VkDeviceMemory mem;
2856 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2857 ASSERT_VK_SUCCESS(err);
2858 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
2859 ASSERT_VK_SUCCESS(err);
2860
2861 {
2862 VkCommandBufferBeginInfo begin_info{};
2863 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2864 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2865
2866 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
2867 vkCmdWriteTimestamp(command_buffer[0],
2868 VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
2869
2870 vkEndCommandBuffer(command_buffer[0]);
2871
2872 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2873
2874 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer,
2875 0, 0, 0);
2876
2877 vkEndCommandBuffer(command_buffer[1]);
2878 }
2879 {
2880 VkSubmitInfo submit_info{};
2881 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2882 submit_info.commandBufferCount = 2;
2883 submit_info.pCommandBuffers = command_buffer;
2884 submit_info.signalSemaphoreCount = 0;
2885 submit_info.pSignalSemaphores = nullptr;
2886 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2887 }
2888
2889 vkQueueWaitIdle(queue);
2890
2891 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
2892 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
2893 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2894
2895 m_errorMonitor->VerifyNotFound();
2896}
Michael Lentine860b0fe2016-05-20 10:14:00 -05002897
2898TEST_F(VkLayerTest, ResetEventThenSet) {
2899 TEST_DESCRIPTION(
2900 "Reset an event then set it after the reset has been submitted.");
2901
2902 if ((m_device->queue_props.empty()) ||
2903 (m_device->queue_props[0].queueCount < 2))
2904 return;
2905
2906 m_errorMonitor->ExpectSuccess();
2907
2908 VkEvent event;
2909 VkEventCreateInfo event_create_info{};
2910 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2911 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
2912
2913 VkCommandPool command_pool;
2914 VkCommandPoolCreateInfo pool_create_info{};
2915 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2916 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2917 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2918 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2919 &command_pool);
2920
2921 VkCommandBuffer command_buffer;
2922 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2923 command_buffer_allocate_info.sType =
2924 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2925 command_buffer_allocate_info.commandPool = command_pool;
2926 command_buffer_allocate_info.commandBufferCount = 1;
2927 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2928 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2929 &command_buffer);
2930
2931 VkQueue queue = VK_NULL_HANDLE;
2932 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2933 1, &queue);
2934
2935 {
2936 VkCommandBufferBeginInfo begin_info{};
2937 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2938 vkBeginCommandBuffer(command_buffer, &begin_info);
2939
2940 vkCmdResetEvent(command_buffer, event,
2941 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
2942 vkCmdWaitEvents(command_buffer, 1, &event,
2943 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2944 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
2945 nullptr, 0, nullptr);
2946 vkEndCommandBuffer(command_buffer);
2947 }
2948 {
2949 VkSubmitInfo submit_info{};
2950 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2951 submit_info.commandBufferCount = 1;
2952 submit_info.pCommandBuffers = &command_buffer;
2953 submit_info.signalSemaphoreCount = 0;
2954 submit_info.pSignalSemaphores = nullptr;
2955 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2956 }
2957 {
2958 m_errorMonitor->SetDesiredFailureMsg(
2959 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event "
2960 "0x1 that is already in use by a "
2961 "command buffer.");
2962 vkSetEvent(m_device->device(), event);
2963 m_errorMonitor->VerifyFound();
2964 }
2965
2966 vkQueueWaitIdle(queue);
2967
2968 vkDestroyEvent(m_device->device(), event, nullptr);
2969 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
2970 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2971}
2972
2973// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002974TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
2975
2976 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
2977 "submitted on separate queues followed by a QueueWaitIdle.");
2978
Dustin Graves48458142016-04-29 16:11:55 -06002979 if ((m_device->queue_props.empty()) ||
2980 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06002981 return;
2982
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002983 m_errorMonitor->ExpectSuccess();
2984
2985 VkSemaphore semaphore;
2986 VkSemaphoreCreateInfo semaphore_create_info{};
2987 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
2988 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
2989 &semaphore);
2990
2991 VkCommandPool command_pool;
2992 VkCommandPoolCreateInfo pool_create_info{};
2993 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2994 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2995 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2996 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2997 &command_pool);
2998
2999 VkCommandBuffer command_buffer[2];
3000 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3001 command_buffer_allocate_info.sType =
3002 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3003 command_buffer_allocate_info.commandPool = command_pool;
3004 command_buffer_allocate_info.commandBufferCount = 2;
3005 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3006 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3007 command_buffer);
3008
3009 VkQueue queue = VK_NULL_HANDLE;
3010 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3011 1, &queue);
3012
3013 {
3014 VkCommandBufferBeginInfo begin_info{};
3015 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3016 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3017
3018 vkCmdPipelineBarrier(command_buffer[0],
3019 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3020 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3021 0, nullptr, 0, nullptr);
3022
3023 VkViewport viewport{};
3024 viewport.maxDepth = 1.0f;
3025 viewport.minDepth = 0.0f;
3026 viewport.width = 512;
3027 viewport.height = 512;
3028 viewport.x = 0;
3029 viewport.y = 0;
3030 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3031 vkEndCommandBuffer(command_buffer[0]);
3032 }
3033 {
3034 VkCommandBufferBeginInfo begin_info{};
3035 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3036 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3037
3038 VkViewport viewport{};
3039 viewport.maxDepth = 1.0f;
3040 viewport.minDepth = 0.0f;
3041 viewport.width = 512;
3042 viewport.height = 512;
3043 viewport.x = 0;
3044 viewport.y = 0;
3045 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3046 vkEndCommandBuffer(command_buffer[1]);
3047 }
3048 {
3049 VkSubmitInfo submit_info{};
3050 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3051 submit_info.commandBufferCount = 1;
3052 submit_info.pCommandBuffers = &command_buffer[0];
3053 submit_info.signalSemaphoreCount = 1;
3054 submit_info.pSignalSemaphores = &semaphore;
3055 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3056 }
3057 {
3058 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3059 VkSubmitInfo submit_info{};
3060 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3061 submit_info.commandBufferCount = 1;
3062 submit_info.pCommandBuffers = &command_buffer[1];
3063 submit_info.waitSemaphoreCount = 1;
3064 submit_info.pWaitSemaphores = &semaphore;
3065 submit_info.pWaitDstStageMask = flags;
3066 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3067 }
3068
3069 vkQueueWaitIdle(m_device->m_queue);
3070
3071 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3072 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3073 &command_buffer[0]);
3074 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3075
3076 m_errorMonitor->VerifyNotFound();
3077}
3078
3079// This is a positive test. No errors should be generated.
3080TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
3081
3082 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3083 "submitted on separate queues, the second having a fence"
3084 "followed by a QueueWaitIdle.");
3085
Dustin Graves48458142016-04-29 16:11:55 -06003086 if ((m_device->queue_props.empty()) ||
3087 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003088 return;
3089
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003090 m_errorMonitor->ExpectSuccess();
3091
3092 VkFence fence;
3093 VkFenceCreateInfo fence_create_info{};
3094 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3095 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3096
3097 VkSemaphore semaphore;
3098 VkSemaphoreCreateInfo semaphore_create_info{};
3099 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3100 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3101 &semaphore);
3102
3103 VkCommandPool command_pool;
3104 VkCommandPoolCreateInfo pool_create_info{};
3105 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3106 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3107 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3108 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3109 &command_pool);
3110
3111 VkCommandBuffer command_buffer[2];
3112 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3113 command_buffer_allocate_info.sType =
3114 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3115 command_buffer_allocate_info.commandPool = command_pool;
3116 command_buffer_allocate_info.commandBufferCount = 2;
3117 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3118 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3119 command_buffer);
3120
3121 VkQueue queue = VK_NULL_HANDLE;
3122 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3123 1, &queue);
3124
3125 {
3126 VkCommandBufferBeginInfo begin_info{};
3127 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3128 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3129
3130 vkCmdPipelineBarrier(command_buffer[0],
3131 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3132 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3133 0, nullptr, 0, nullptr);
3134
3135 VkViewport viewport{};
3136 viewport.maxDepth = 1.0f;
3137 viewport.minDepth = 0.0f;
3138 viewport.width = 512;
3139 viewport.height = 512;
3140 viewport.x = 0;
3141 viewport.y = 0;
3142 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3143 vkEndCommandBuffer(command_buffer[0]);
3144 }
3145 {
3146 VkCommandBufferBeginInfo begin_info{};
3147 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3148 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3149
3150 VkViewport viewport{};
3151 viewport.maxDepth = 1.0f;
3152 viewport.minDepth = 0.0f;
3153 viewport.width = 512;
3154 viewport.height = 512;
3155 viewport.x = 0;
3156 viewport.y = 0;
3157 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3158 vkEndCommandBuffer(command_buffer[1]);
3159 }
3160 {
3161 VkSubmitInfo submit_info{};
3162 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3163 submit_info.commandBufferCount = 1;
3164 submit_info.pCommandBuffers = &command_buffer[0];
3165 submit_info.signalSemaphoreCount = 1;
3166 submit_info.pSignalSemaphores = &semaphore;
3167 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3168 }
3169 {
3170 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3171 VkSubmitInfo submit_info{};
3172 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3173 submit_info.commandBufferCount = 1;
3174 submit_info.pCommandBuffers = &command_buffer[1];
3175 submit_info.waitSemaphoreCount = 1;
3176 submit_info.pWaitSemaphores = &semaphore;
3177 submit_info.pWaitDstStageMask = flags;
3178 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3179 }
3180
3181 vkQueueWaitIdle(m_device->m_queue);
3182
3183 vkDestroyFence(m_device->device(), fence, nullptr);
3184 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3185 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3186 &command_buffer[0]);
3187 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3188
3189 m_errorMonitor->VerifyNotFound();
3190}
3191
3192// This is a positive test. No errors should be generated.
3193TEST_F(VkLayerTest,
3194 TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
3195
3196 TEST_DESCRIPTION(
3197 "Two command buffers, each in a separate QueueSubmit call "
3198 "submitted on separate queues, the second having a fence"
3199 "followed by two consecutive WaitForFences calls on the same fence.");
3200
Dustin Graves48458142016-04-29 16:11:55 -06003201 if ((m_device->queue_props.empty()) ||
3202 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003203 return;
3204
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003205 m_errorMonitor->ExpectSuccess();
3206
3207 VkFence fence;
3208 VkFenceCreateInfo fence_create_info{};
3209 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3210 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3211
3212 VkSemaphore semaphore;
3213 VkSemaphoreCreateInfo semaphore_create_info{};
3214 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3215 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3216 &semaphore);
3217
3218 VkCommandPool command_pool;
3219 VkCommandPoolCreateInfo pool_create_info{};
3220 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3221 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3222 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3223 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3224 &command_pool);
3225
3226 VkCommandBuffer command_buffer[2];
3227 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3228 command_buffer_allocate_info.sType =
3229 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3230 command_buffer_allocate_info.commandPool = command_pool;
3231 command_buffer_allocate_info.commandBufferCount = 2;
3232 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3233 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3234 command_buffer);
3235
3236 VkQueue queue = VK_NULL_HANDLE;
3237 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3238 1, &queue);
3239
3240 {
3241 VkCommandBufferBeginInfo begin_info{};
3242 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3243 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3244
3245 vkCmdPipelineBarrier(command_buffer[0],
3246 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3247 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3248 0, nullptr, 0, nullptr);
3249
3250 VkViewport viewport{};
3251 viewport.maxDepth = 1.0f;
3252 viewport.minDepth = 0.0f;
3253 viewport.width = 512;
3254 viewport.height = 512;
3255 viewport.x = 0;
3256 viewport.y = 0;
3257 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3258 vkEndCommandBuffer(command_buffer[0]);
3259 }
3260 {
3261 VkCommandBufferBeginInfo begin_info{};
3262 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3263 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3264
3265 VkViewport viewport{};
3266 viewport.maxDepth = 1.0f;
3267 viewport.minDepth = 0.0f;
3268 viewport.width = 512;
3269 viewport.height = 512;
3270 viewport.x = 0;
3271 viewport.y = 0;
3272 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3273 vkEndCommandBuffer(command_buffer[1]);
3274 }
3275 {
3276 VkSubmitInfo submit_info{};
3277 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3278 submit_info.commandBufferCount = 1;
3279 submit_info.pCommandBuffers = &command_buffer[0];
3280 submit_info.signalSemaphoreCount = 1;
3281 submit_info.pSignalSemaphores = &semaphore;
3282 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3283 }
3284 {
3285 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3286 VkSubmitInfo submit_info{};
3287 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3288 submit_info.commandBufferCount = 1;
3289 submit_info.pCommandBuffers = &command_buffer[1];
3290 submit_info.waitSemaphoreCount = 1;
3291 submit_info.pWaitSemaphores = &semaphore;
3292 submit_info.pWaitDstStageMask = flags;
3293 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3294 }
3295
3296 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3297 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3298
3299 vkDestroyFence(m_device->device(), fence, nullptr);
3300 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3301 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3302 &command_buffer[0]);
3303 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3304
3305 m_errorMonitor->VerifyNotFound();
3306}
3307
3308// This is a positive test. No errors should be generated.
3309TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
3310
3311 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3312 "submitted on separate queues, the second having a fence, "
3313 "followed by a WaitForFences call.");
3314
Dustin Graves48458142016-04-29 16:11:55 -06003315 if ((m_device->queue_props.empty()) ||
3316 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003317 return;
3318
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003319 m_errorMonitor->ExpectSuccess();
3320
3321 VkFence fence;
3322 VkFenceCreateInfo fence_create_info{};
3323 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3324 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3325
3326 VkSemaphore semaphore;
3327 VkSemaphoreCreateInfo semaphore_create_info{};
3328 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3329 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3330 &semaphore);
3331
3332 VkCommandPool command_pool;
3333 VkCommandPoolCreateInfo pool_create_info{};
3334 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3335 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3336 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3337 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3338 &command_pool);
3339
3340 VkCommandBuffer command_buffer[2];
3341 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3342 command_buffer_allocate_info.sType =
3343 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3344 command_buffer_allocate_info.commandPool = command_pool;
3345 command_buffer_allocate_info.commandBufferCount = 2;
3346 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3347 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3348 command_buffer);
3349
3350 VkQueue queue = VK_NULL_HANDLE;
3351 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3352 1, &queue);
3353
3354
3355 {
3356 VkCommandBufferBeginInfo begin_info{};
3357 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3358 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3359
3360 vkCmdPipelineBarrier(command_buffer[0],
3361 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3362 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3363 0, nullptr, 0, nullptr);
3364
3365 VkViewport viewport{};
3366 viewport.maxDepth = 1.0f;
3367 viewport.minDepth = 0.0f;
3368 viewport.width = 512;
3369 viewport.height = 512;
3370 viewport.x = 0;
3371 viewport.y = 0;
3372 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3373 vkEndCommandBuffer(command_buffer[0]);
3374 }
3375 {
3376 VkCommandBufferBeginInfo begin_info{};
3377 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3378 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3379
3380 VkViewport viewport{};
3381 viewport.maxDepth = 1.0f;
3382 viewport.minDepth = 0.0f;
3383 viewport.width = 512;
3384 viewport.height = 512;
3385 viewport.x = 0;
3386 viewport.y = 0;
3387 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3388 vkEndCommandBuffer(command_buffer[1]);
3389 }
3390 {
3391 VkSubmitInfo submit_info{};
3392 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3393 submit_info.commandBufferCount = 1;
3394 submit_info.pCommandBuffers = &command_buffer[0];
3395 submit_info.signalSemaphoreCount = 1;
3396 submit_info.pSignalSemaphores = &semaphore;
3397 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3398 }
3399 {
3400 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3401 VkSubmitInfo submit_info{};
3402 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3403 submit_info.commandBufferCount = 1;
3404 submit_info.pCommandBuffers = &command_buffer[1];
3405 submit_info.waitSemaphoreCount = 1;
3406 submit_info.pWaitSemaphores = &semaphore;
3407 submit_info.pWaitDstStageMask = flags;
3408 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3409 }
3410
3411 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3412
3413 vkDestroyFence(m_device->device(), fence, nullptr);
3414 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3415 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3416 &command_buffer[0]);
3417 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3418
3419 m_errorMonitor->VerifyNotFound();
3420}
3421
3422// This is a positive test. No errors should be generated.
3423TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
3424
3425 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3426 "on the same queue, sharing a signal/wait semaphore, the "
3427 "second having a fence, "
3428 "followed by a WaitForFences call.");
3429
3430 m_errorMonitor->ExpectSuccess();
3431
3432 VkFence fence;
3433 VkFenceCreateInfo fence_create_info{};
3434 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3435 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3436
3437 VkSemaphore semaphore;
3438 VkSemaphoreCreateInfo semaphore_create_info{};
3439 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3440 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3441 &semaphore);
3442
3443 VkCommandPool command_pool;
3444 VkCommandPoolCreateInfo pool_create_info{};
3445 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3446 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3447 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3448 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3449 &command_pool);
3450
3451 VkCommandBuffer command_buffer[2];
3452 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3453 command_buffer_allocate_info.sType =
3454 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3455 command_buffer_allocate_info.commandPool = command_pool;
3456 command_buffer_allocate_info.commandBufferCount = 2;
3457 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3458 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3459 command_buffer);
3460
3461 {
3462 VkCommandBufferBeginInfo begin_info{};
3463 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3464 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3465
3466 vkCmdPipelineBarrier(command_buffer[0],
3467 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3468 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3469 0, nullptr, 0, nullptr);
3470
3471 VkViewport viewport{};
3472 viewport.maxDepth = 1.0f;
3473 viewport.minDepth = 0.0f;
3474 viewport.width = 512;
3475 viewport.height = 512;
3476 viewport.x = 0;
3477 viewport.y = 0;
3478 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3479 vkEndCommandBuffer(command_buffer[0]);
3480 }
3481 {
3482 VkCommandBufferBeginInfo begin_info{};
3483 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3484 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3485
3486 VkViewport viewport{};
3487 viewport.maxDepth = 1.0f;
3488 viewport.minDepth = 0.0f;
3489 viewport.width = 512;
3490 viewport.height = 512;
3491 viewport.x = 0;
3492 viewport.y = 0;
3493 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3494 vkEndCommandBuffer(command_buffer[1]);
3495 }
3496 {
3497 VkSubmitInfo submit_info{};
3498 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3499 submit_info.commandBufferCount = 1;
3500 submit_info.pCommandBuffers = &command_buffer[0];
3501 submit_info.signalSemaphoreCount = 1;
3502 submit_info.pSignalSemaphores = &semaphore;
3503 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3504 }
3505 {
3506 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3507 VkSubmitInfo submit_info{};
3508 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3509 submit_info.commandBufferCount = 1;
3510 submit_info.pCommandBuffers = &command_buffer[1];
3511 submit_info.waitSemaphoreCount = 1;
3512 submit_info.pWaitSemaphores = &semaphore;
3513 submit_info.pWaitDstStageMask = flags;
3514 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3515 }
3516
3517 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3518
3519 vkDestroyFence(m_device->device(), fence, nullptr);
3520 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3521 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3522 &command_buffer[0]);
3523 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3524
3525 m_errorMonitor->VerifyNotFound();
3526}
3527
3528// This is a positive test. No errors should be generated.
3529TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
3530
3531 TEST_DESCRIPTION(
3532 "Two command buffers, each in a separate QueueSubmit call "
3533 "on the same queue, no fences, followed by a third QueueSubmit with NO "
3534 "SubmitInfos but with a fence, followed by a WaitForFences call.");
3535
3536 m_errorMonitor->ExpectSuccess();
3537
3538 VkFence fence;
3539 VkFenceCreateInfo fence_create_info{};
3540 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3541 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3542
3543 VkCommandPool command_pool;
3544 VkCommandPoolCreateInfo pool_create_info{};
3545 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3546 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3547 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3548 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3549 &command_pool);
3550
3551 VkCommandBuffer command_buffer[2];
3552 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3553 command_buffer_allocate_info.sType =
3554 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3555 command_buffer_allocate_info.commandPool = command_pool;
3556 command_buffer_allocate_info.commandBufferCount = 2;
3557 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3558 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3559 command_buffer);
3560
3561 {
3562 VkCommandBufferBeginInfo begin_info{};
3563 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3564 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3565
3566 vkCmdPipelineBarrier(command_buffer[0],
3567 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3568 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3569 0, nullptr, 0, nullptr);
3570
3571 VkViewport viewport{};
3572 viewport.maxDepth = 1.0f;
3573 viewport.minDepth = 0.0f;
3574 viewport.width = 512;
3575 viewport.height = 512;
3576 viewport.x = 0;
3577 viewport.y = 0;
3578 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3579 vkEndCommandBuffer(command_buffer[0]);
3580 }
3581 {
3582 VkCommandBufferBeginInfo begin_info{};
3583 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3584 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3585
3586 VkViewport viewport{};
3587 viewport.maxDepth = 1.0f;
3588 viewport.minDepth = 0.0f;
3589 viewport.width = 512;
3590 viewport.height = 512;
3591 viewport.x = 0;
3592 viewport.y = 0;
3593 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3594 vkEndCommandBuffer(command_buffer[1]);
3595 }
3596 {
3597 VkSubmitInfo submit_info{};
3598 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3599 submit_info.commandBufferCount = 1;
3600 submit_info.pCommandBuffers = &command_buffer[0];
3601 submit_info.signalSemaphoreCount = 0;
3602 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
3603 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3604 }
3605 {
3606 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3607 VkSubmitInfo submit_info{};
3608 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3609 submit_info.commandBufferCount = 1;
3610 submit_info.pCommandBuffers = &command_buffer[1];
3611 submit_info.waitSemaphoreCount = 0;
3612 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
3613 submit_info.pWaitDstStageMask = flags;
3614 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3615 }
3616
3617 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
3618
3619 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3620
3621 vkDestroyFence(m_device->device(), fence, nullptr);
3622 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3623 &command_buffer[0]);
3624 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3625
3626 m_errorMonitor->VerifyNotFound();
3627}
3628
3629// This is a positive test. No errors should be generated.
3630TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
3631
3632 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3633 "on the same queue, the second having a fence, followed "
3634 "by a WaitForFences call.");
3635
3636 m_errorMonitor->ExpectSuccess();
3637
3638 VkFence fence;
3639 VkFenceCreateInfo fence_create_info{};
3640 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3641 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3642
3643 VkCommandPool command_pool;
3644 VkCommandPoolCreateInfo pool_create_info{};
3645 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3646 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3647 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3648 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3649 &command_pool);
3650
3651 VkCommandBuffer command_buffer[2];
3652 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3653 command_buffer_allocate_info.sType =
3654 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3655 command_buffer_allocate_info.commandPool = command_pool;
3656 command_buffer_allocate_info.commandBufferCount = 2;
3657 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3658 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3659 command_buffer);
3660
3661 {
3662 VkCommandBufferBeginInfo begin_info{};
3663 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3664 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3665
3666 vkCmdPipelineBarrier(command_buffer[0],
3667 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3668 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3669 0, nullptr, 0, nullptr);
3670
3671 VkViewport viewport{};
3672 viewport.maxDepth = 1.0f;
3673 viewport.minDepth = 0.0f;
3674 viewport.width = 512;
3675 viewport.height = 512;
3676 viewport.x = 0;
3677 viewport.y = 0;
3678 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3679 vkEndCommandBuffer(command_buffer[0]);
3680 }
3681 {
3682 VkCommandBufferBeginInfo begin_info{};
3683 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3684 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3685
3686 VkViewport viewport{};
3687 viewport.maxDepth = 1.0f;
3688 viewport.minDepth = 0.0f;
3689 viewport.width = 512;
3690 viewport.height = 512;
3691 viewport.x = 0;
3692 viewport.y = 0;
3693 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3694 vkEndCommandBuffer(command_buffer[1]);
3695 }
3696 {
3697 VkSubmitInfo submit_info{};
3698 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3699 submit_info.commandBufferCount = 1;
3700 submit_info.pCommandBuffers = &command_buffer[0];
3701 submit_info.signalSemaphoreCount = 0;
3702 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
3703 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3704 }
3705 {
3706 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3707 VkSubmitInfo submit_info{};
3708 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3709 submit_info.commandBufferCount = 1;
3710 submit_info.pCommandBuffers = &command_buffer[1];
3711 submit_info.waitSemaphoreCount = 0;
3712 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
3713 submit_info.pWaitDstStageMask = flags;
3714 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3715 }
3716
3717 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3718
3719 vkDestroyFence(m_device->device(), fence, nullptr);
3720 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3721 &command_buffer[0]);
3722 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3723
3724 m_errorMonitor->VerifyNotFound();
3725}
3726
3727// This is a positive test. No errors should be generated.
3728TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
3729
3730 TEST_DESCRIPTION(
3731 "Two command buffers each in a separate SubmitInfo sent in a single "
3732 "QueueSubmit call followed by a WaitForFences call.");
3733
3734 m_errorMonitor->ExpectSuccess();
3735
3736 VkFence fence;
3737 VkFenceCreateInfo fence_create_info{};
3738 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3739 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3740
3741 VkSemaphore semaphore;
3742 VkSemaphoreCreateInfo semaphore_create_info{};
3743 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3744 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3745 &semaphore);
3746
3747 VkCommandPool command_pool;
3748 VkCommandPoolCreateInfo pool_create_info{};
3749 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3750 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3751 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3752 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3753 &command_pool);
3754
3755 VkCommandBuffer command_buffer[2];
3756 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3757 command_buffer_allocate_info.sType =
3758 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3759 command_buffer_allocate_info.commandPool = command_pool;
3760 command_buffer_allocate_info.commandBufferCount = 2;
3761 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3762 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3763 command_buffer);
3764
3765 {
3766 VkCommandBufferBeginInfo begin_info{};
3767 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3768 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3769
3770 vkCmdPipelineBarrier(command_buffer[0],
3771 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3772 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3773 0, nullptr, 0, nullptr);
3774
3775 VkViewport viewport{};
3776 viewport.maxDepth = 1.0f;
3777 viewport.minDepth = 0.0f;
3778 viewport.width = 512;
3779 viewport.height = 512;
3780 viewport.x = 0;
3781 viewport.y = 0;
3782 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3783 vkEndCommandBuffer(command_buffer[0]);
3784 }
3785 {
3786 VkCommandBufferBeginInfo begin_info{};
3787 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3788 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3789
3790 VkViewport viewport{};
3791 viewport.maxDepth = 1.0f;
3792 viewport.minDepth = 0.0f;
3793 viewport.width = 512;
3794 viewport.height = 512;
3795 viewport.x = 0;
3796 viewport.y = 0;
3797 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3798 vkEndCommandBuffer(command_buffer[1]);
3799 }
3800 {
3801 VkSubmitInfo submit_info[2];
3802 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3803
3804 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3805 submit_info[0].pNext = NULL;
3806 submit_info[0].commandBufferCount = 1;
3807 submit_info[0].pCommandBuffers = &command_buffer[0];
3808 submit_info[0].signalSemaphoreCount = 1;
3809 submit_info[0].pSignalSemaphores = &semaphore;
3810 submit_info[0].waitSemaphoreCount = 0;
3811 submit_info[0].pWaitSemaphores = NULL;
3812 submit_info[0].pWaitDstStageMask = 0;
3813
3814 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3815 submit_info[1].pNext = NULL;
3816 submit_info[1].commandBufferCount = 1;
3817 submit_info[1].pCommandBuffers = &command_buffer[1];
3818 submit_info[1].waitSemaphoreCount = 1;
3819 submit_info[1].pWaitSemaphores = &semaphore;
3820 submit_info[1].pWaitDstStageMask = flags;
3821 submit_info[1].signalSemaphoreCount = 0;
3822 submit_info[1].pSignalSemaphores = NULL;
3823 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
3824 }
3825
3826 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3827
3828 vkDestroyFence(m_device->device(), fence, nullptr);
3829 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3830 &command_buffer[0]);
3831 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3832
3833 m_errorMonitor->VerifyNotFound();
3834}
3835
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003836TEST_F(VkLayerTest, DynamicStatesNotBound) {
3837 TEST_DESCRIPTION(
3838 "Run a series of simple draw calls to validate all the different "
3839 "failure cases that can occur when dynamic state is required but not "
3840 "correctly bound."
3841 "Here are the different dynamic state cases verified by this test:\n"
3842 "-Line Width\n-Depth Bias\n-Viewport State\n-Scissor State\n-Blend "
3843 "State\n-Depth Bounds\n-Stencil Read Mask\n-Stencil Write "
3844 "Mask\n-Stencil Reference");
3845
3846 // Dynamic line width
Karl Schultz6addd812016-02-02 17:17:23 -07003847 m_errorMonitor->SetDesiredFailureMsg(
3848 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003849 "Dynamic line width state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003850 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3851 BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003852 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003853 // Dynamic depth bias
Karl Schultz6addd812016-02-02 17:17:23 -07003854 m_errorMonitor->SetDesiredFailureMsg(
3855 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003856 "Dynamic depth bias state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003857 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3858 BsoFailDepthBias);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003859 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003860 // Dynamic viewport state
Karl Schultz6addd812016-02-02 17:17:23 -07003861 m_errorMonitor->SetDesiredFailureMsg(
3862 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003863 "Dynamic viewport state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003864 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3865 BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003866 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003867 // Dynamic scissor state
Karl Schultz6addd812016-02-02 17:17:23 -07003868 m_errorMonitor->SetDesiredFailureMsg(
3869 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003870 "Dynamic scissor state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003871 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3872 BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003873 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003874 // Dynamic blend state
Karl Schultz6addd812016-02-02 17:17:23 -07003875 m_errorMonitor->SetDesiredFailureMsg(
3876 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003877 "Dynamic depth bounds state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003878 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3879 BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003880 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003881 // Dynamic stencil read mask
Karl Schultz6addd812016-02-02 17:17:23 -07003882 m_errorMonitor->SetDesiredFailureMsg(
3883 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003884 "Dynamic stencil read mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003885 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3886 BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003887 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003888 // Dynamic stencil write mask
Karl Schultz6addd812016-02-02 17:17:23 -07003889 m_errorMonitor->SetDesiredFailureMsg(
3890 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003891 "Dynamic stencil write mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003892 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3893 BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003894 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003895 // Dynamic stencil reference
Karl Schultz6addd812016-02-02 17:17:23 -07003896 m_errorMonitor->SetDesiredFailureMsg(
3897 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003898 "Dynamic stencil reference state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003899 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3900 BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003901 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003902}
3903
Karl Schultz6addd812016-02-02 17:17:23 -07003904TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003905 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003906
Karl Schultz6addd812016-02-02 17:17:23 -07003907 m_errorMonitor->SetDesiredFailureMsg(
3908 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3909 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3910 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003911
3912 VkFenceCreateInfo fenceInfo = {};
3913 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3914 fenceInfo.pNext = NULL;
3915 fenceInfo.flags = 0;
3916
3917 ASSERT_NO_FATAL_FAILURE(InitState());
3918 ASSERT_NO_FATAL_FAILURE(InitViewport());
3919 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3920
Karl Schultz6addd812016-02-02 17:17:23 -07003921 // We luck out b/c by default the framework creates CB w/ the
3922 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003923 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07003924 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
3925 m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003926 EndCommandBuffer();
3927
3928 testFence.init(*m_device, fenceInfo);
3929
3930 // Bypass framework since it does the waits automatically
3931 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003932 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003933 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3934 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003935 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003936 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003937 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003938 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003939 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003940 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003941 submit_info.pSignalSemaphores = NULL;
3942
Karl Schultz6addd812016-02-02 17:17:23 -07003943 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
3944 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003945
Karl Schultz6addd812016-02-02 17:17:23 -07003946 // Cause validation error by re-submitting cmd buffer that should only be
3947 // submitted once
3948 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003949
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003950 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003951}
3952
Karl Schultz6addd812016-02-02 17:17:23 -07003953TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003954 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07003955 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003956
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07003958 "Unable to allocate 1 descriptors of "
3959 "type "
3960 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003961
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003962 ASSERT_NO_FATAL_FAILURE(InitState());
3963 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003964
Karl Schultz6addd812016-02-02 17:17:23 -07003965 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3966 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003967 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003968 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3969 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003970
3971 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003972 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3973 ds_pool_ci.pNext = NULL;
3974 ds_pool_ci.flags = 0;
3975 ds_pool_ci.maxSets = 1;
3976 ds_pool_ci.poolSizeCount = 1;
3977 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003978
3979 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07003980 err =
3981 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003982 ASSERT_VK_SUCCESS(err);
3983
3984 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003985 dsl_binding.binding = 0;
3986 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3987 dsl_binding.descriptorCount = 1;
3988 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3989 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003990
3991 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003992 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3993 ds_layout_ci.pNext = NULL;
3994 ds_layout_ci.bindingCount = 1;
3995 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003996
3997 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003998 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3999 &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004000 ASSERT_VK_SUCCESS(err);
4001
4002 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004003 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004004 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004005 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004006 alloc_info.descriptorPool = ds_pool;
4007 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004008 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4009 &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004010
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004011 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004012
Chia-I Wuf7458c52015-10-26 21:10:41 +08004013 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4014 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004015}
4016
Karl Schultz6addd812016-02-02 17:17:23 -07004017TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4018 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004019
Karl Schultz6addd812016-02-02 17:17:23 -07004020 m_errorMonitor->SetDesiredFailureMsg(
4021 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4022 "It is invalid to call vkFreeDescriptorSets() with a pool created "
4023 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004024
Tobin Ehlise735c692015-10-08 13:13:50 -06004025 ASSERT_NO_FATAL_FAILURE(InitState());
4026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004027
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004028 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004029 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4030 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004031
4032 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004033 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4034 ds_pool_ci.pNext = NULL;
4035 ds_pool_ci.maxSets = 1;
4036 ds_pool_ci.poolSizeCount = 1;
4037 ds_pool_ci.flags = 0;
4038 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4039 // app can only call vkResetDescriptorPool on this pool.;
4040 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004041
4042 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004043 err =
4044 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004045 ASSERT_VK_SUCCESS(err);
4046
4047 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004048 dsl_binding.binding = 0;
4049 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4050 dsl_binding.descriptorCount = 1;
4051 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4052 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004053
4054 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004055 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4056 ds_layout_ci.pNext = NULL;
4057 ds_layout_ci.bindingCount = 1;
4058 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004059
4060 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004061 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4062 &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004063 ASSERT_VK_SUCCESS(err);
4064
4065 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004066 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004067 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004068 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004069 alloc_info.descriptorPool = ds_pool;
4070 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004071 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4072 &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004073 ASSERT_VK_SUCCESS(err);
4074
4075 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004076 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004077
Chia-I Wuf7458c52015-10-26 21:10:41 +08004078 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4079 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004080}
4081
Karl Schultz6addd812016-02-02 17:17:23 -07004082TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004083 // Attempt to clear Descriptor Pool with bad object.
4084 // ObjectTracker should catch this.
4085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4086 "Invalid VkDescriptorPool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004087 uint64_t fake_pool_handle = 0xbaad6001;
4088 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4089 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004090 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004091}
4092
Karl Schultz6addd812016-02-02 17:17:23 -07004093TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004094 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4095 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004096 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004097 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004098
4099 uint64_t fake_set_handle = 0xbaad6001;
4100 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004101 VkResult err;
4102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4103 "Invalid VkDescriptorSet Object 0xbaad6001");
4104
4105 ASSERT_NO_FATAL_FAILURE(InitState());
4106
4107 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4108 layout_bindings[0].binding = 0;
4109 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4110 layout_bindings[0].descriptorCount = 1;
4111 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4112 layout_bindings[0].pImmutableSamplers = NULL;
4113
4114 VkDescriptorSetLayout descriptor_set_layout;
4115 VkDescriptorSetLayoutCreateInfo dslci = {};
4116 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4117 dslci.pNext = NULL;
4118 dslci.bindingCount = 1;
4119 dslci.pBindings = layout_bindings;
4120 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004121 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004122
4123 VkPipelineLayout pipeline_layout;
4124 VkPipelineLayoutCreateInfo plci = {};
4125 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4126 plci.pNext = NULL;
4127 plci.setLayoutCount = 1;
4128 plci.pSetLayouts = &descriptor_set_layout;
4129 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004130 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004131
4132 BeginCommandBuffer();
4133 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004134 pipeline_layout, 0, 1, &bad_set, 0, NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004135 m_errorMonitor->VerifyFound();
4136 EndCommandBuffer();
4137 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4138 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004139}
4140
Karl Schultz6addd812016-02-02 17:17:23 -07004141TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004142 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4143 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004144 uint64_t fake_layout_handle = 0xbaad6001;
4145 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4147 "Invalid VkDescriptorSetLayout Object 0xbaad6001");
4148
4149 VkPipelineLayout pipeline_layout;
4150 VkPipelineLayoutCreateInfo plci = {};
4151 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4152 plci.pNext = NULL;
4153 plci.setLayoutCount = 1;
4154 plci.pSetLayouts = &bad_layout;
4155 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4156
4157 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004158}
4159
Karl Schultz6addd812016-02-02 17:17:23 -07004160TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004161 // Attempt to bind an invalid Pipeline to a valid Command Buffer
4162 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004163 // Create a valid cmd buffer
4164 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004165 uint64_t fake_pipeline_handle = 0xbaad6001;
4166 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4168 "Invalid VkPipeline Object 0xbaad6001");
4169 ASSERT_NO_FATAL_FAILURE(InitState());
4170 BeginCommandBuffer();
4171 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4172 VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
4173 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004174
4175 // Now issue a draw call with no pipeline bound
4176 m_errorMonitor->SetDesiredFailureMsg(
4177 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4178 "At Draw/Dispatch time no valid VkPipeline is bound!");
4179 ASSERT_NO_FATAL_FAILURE(InitState());
4180 BeginCommandBuffer();
4181 Draw(1, 0, 0, 0);
4182 m_errorMonitor->VerifyFound();
4183 // Finally same check once more but with Dispatch/Compute
4184 m_errorMonitor->SetDesiredFailureMsg(
4185 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4186 "At Draw/Dispatch time no valid VkPipeline is bound!");
4187 ASSERT_NO_FATAL_FAILURE(InitState());
4188 BeginCommandBuffer();
4189 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
4190 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004191}
4192
Karl Schultz6addd812016-02-02 17:17:23 -07004193TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
4194 // Create and update CommandBuffer then call QueueSubmit w/o calling End on
4195 // CommandBuffer
4196 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004197
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07004198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004199 " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004200
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004201 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06004202 ASSERT_NO_FATAL_FAILURE(InitViewport());
4203 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004204 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004205 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4206 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004207
4208 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004209 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4210 ds_pool_ci.pNext = NULL;
4211 ds_pool_ci.maxSets = 1;
4212 ds_pool_ci.poolSizeCount = 1;
4213 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06004214
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004215 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004216 err =
4217 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004218 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004219
Tony Barboureb254902015-07-15 12:50:33 -06004220 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004221 dsl_binding.binding = 0;
4222 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4223 dsl_binding.descriptorCount = 1;
4224 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4225 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004226
Tony Barboureb254902015-07-15 12:50:33 -06004227 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004228 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4229 ds_layout_ci.pNext = NULL;
4230 ds_layout_ci.bindingCount = 1;
4231 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004232 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004233 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4234 &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004235 ASSERT_VK_SUCCESS(err);
4236
4237 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004238 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004239 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004240 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004241 alloc_info.descriptorPool = ds_pool;
4242 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004243 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4244 &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004245 ASSERT_VK_SUCCESS(err);
4246
Tony Barboureb254902015-07-15 12:50:33 -06004247 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004248 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4249 pipeline_layout_ci.pNext = NULL;
4250 pipeline_layout_ci.setLayoutCount = 1;
4251 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004252
4253 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004254 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4255 &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004256 ASSERT_VK_SUCCESS(err);
4257
Karl Schultz6addd812016-02-02 17:17:23 -07004258 VkShaderObj vs(m_device, bindStateVertShaderText,
4259 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06004260 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07004261 // on more devices
4262 VkShaderObj fs(m_device, bindStateFragShaderText,
4263 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004264
Tony Barbourc95e4ac2015-08-04 17:05:26 -06004265 VkPipelineObj pipe(m_device);
4266 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06004267 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06004268 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06004269 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004270
4271 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004272 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4273 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4274 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4275 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4276 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004277
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004278 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06004279
Chia-I Wuf7458c52015-10-26 21:10:41 +08004280 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4281 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4282 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004283}
4284
Karl Schultz6addd812016-02-02 17:17:23 -07004285TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004286 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07004287 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004288
Karl Schultz6addd812016-02-02 17:17:23 -07004289 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004290 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
4291 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004292
4293 ASSERT_NO_FATAL_FAILURE(InitState());
4294 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004295 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
4296 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004297
4298 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004299 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4300 ds_pool_ci.pNext = NULL;
4301 ds_pool_ci.maxSets = 1;
4302 ds_pool_ci.poolSizeCount = 1;
4303 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004304
4305 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004306 err =
4307 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004308 ASSERT_VK_SUCCESS(err);
4309
4310 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004311 dsl_binding.binding = 0;
4312 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
4313 dsl_binding.descriptorCount = 1;
4314 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4315 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004316
4317 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004318 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4319 ds_layout_ci.pNext = NULL;
4320 ds_layout_ci.bindingCount = 1;
4321 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004322 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004323 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4324 &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004325 ASSERT_VK_SUCCESS(err);
4326
4327 VkDescriptorSet descriptorSet;
4328 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004329 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004330 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004331 alloc_info.descriptorPool = ds_pool;
4332 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004333 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4334 &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004335 ASSERT_VK_SUCCESS(err);
4336
Karl Schultz6addd812016-02-02 17:17:23 -07004337 VkBufferView view =
4338 (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004339 VkWriteDescriptorSet descriptor_write;
4340 memset(&descriptor_write, 0, sizeof(descriptor_write));
4341 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4342 descriptor_write.dstSet = descriptorSet;
4343 descriptor_write.dstBinding = 0;
4344 descriptor_write.descriptorCount = 1;
4345 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
4346 descriptor_write.pTexelBufferView = &view;
4347
4348 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4349
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004350 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004351
4352 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4353 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4354}
4355
Karl Schultz6addd812016-02-02 17:17:23 -07004356TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
4357 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
4358 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07004359 // 1. No dynamicOffset supplied
4360 // 2. Too many dynamicOffsets supplied
4361 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07004362 VkResult err;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004364 " requires 1 dynamicOffsets, but only "
4365 "0 dynamicOffsets are left in "
4366 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004367
4368 ASSERT_NO_FATAL_FAILURE(InitState());
4369 ASSERT_NO_FATAL_FAILURE(InitViewport());
4370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4371
4372 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004373 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
4374 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004375
4376 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004377 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4378 ds_pool_ci.pNext = NULL;
4379 ds_pool_ci.maxSets = 1;
4380 ds_pool_ci.poolSizeCount = 1;
4381 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004382
4383 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004384 err =
4385 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004386 ASSERT_VK_SUCCESS(err);
4387
4388 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004389 dsl_binding.binding = 0;
4390 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
4391 dsl_binding.descriptorCount = 1;
4392 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4393 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004394
4395 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004396 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4397 ds_layout_ci.pNext = NULL;
4398 ds_layout_ci.bindingCount = 1;
4399 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004400 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004401 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4402 &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004403 ASSERT_VK_SUCCESS(err);
4404
4405 VkDescriptorSet descriptorSet;
4406 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004407 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004408 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004409 alloc_info.descriptorPool = ds_pool;
4410 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004411 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4412 &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004413 ASSERT_VK_SUCCESS(err);
4414
4415 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004416 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4417 pipeline_layout_ci.pNext = NULL;
4418 pipeline_layout_ci.setLayoutCount = 1;
4419 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004420
4421 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004422 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4423 &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004424 ASSERT_VK_SUCCESS(err);
4425
4426 // Create a buffer to update the descriptor with
4427 uint32_t qfi = 0;
4428 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004429 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4430 buffCI.size = 1024;
4431 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4432 buffCI.queueFamilyIndexCount = 1;
4433 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004434
4435 VkBuffer dyub;
4436 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4437 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004438 // Allocate memory and bind to buffer so we can make it to the appropriate
4439 // error
4440 VkMemoryAllocateInfo mem_alloc = {};
4441 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4442 mem_alloc.pNext = NULL;
4443 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12004444 mem_alloc.memoryTypeIndex = 0;
4445
4446 VkMemoryRequirements memReqs;
4447 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
4448 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc,
4449 0);
4450 if (!pass) {
4451 vkDestroyBuffer(m_device->device(), dyub, NULL);
4452 return;
4453 }
4454
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004455 VkDeviceMemory mem;
4456 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4457 ASSERT_VK_SUCCESS(err);
4458 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4459 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004460 // Correctly update descriptor to avoid "NOT_UPDATED" error
4461 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004462 buffInfo.buffer = dyub;
4463 buffInfo.offset = 0;
4464 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004465
4466 VkWriteDescriptorSet descriptor_write;
4467 memset(&descriptor_write, 0, sizeof(descriptor_write));
4468 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4469 descriptor_write.dstSet = descriptorSet;
4470 descriptor_write.dstBinding = 0;
4471 descriptor_write.descriptorCount = 1;
4472 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
4473 descriptor_write.pBufferInfo = &buffInfo;
4474
4475 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4476
4477 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004478 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4479 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4480 1, &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004481 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07004482 uint32_t pDynOff[2] = {512, 756};
4483 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Karl Schultz6addd812016-02-02 17:17:23 -07004484 m_errorMonitor->SetDesiredFailureMsg(
4485 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07004486 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
Karl Schultz6addd812016-02-02 17:17:23 -07004487 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4488 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4489 1, &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12004490 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07004491 // Finally cause error due to dynamicOffset being too big
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4493 " dynamic offset 512 combined with "
4494 "offset 0 and range 1024 that "
4495 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07004496 // Create PSO to be used for draw-time errors below
4497 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12004498 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07004499 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07004500 "out gl_PerVertex { \n"
4501 " vec4 gl_Position;\n"
4502 "};\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07004503 "void main(){\n"
4504 " gl_Position = vec4(1);\n"
4505 "}\n";
4506 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12004507 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07004508 "\n"
4509 "layout(location=0) out vec4 x;\n"
4510 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4511 "void main(){\n"
4512 " x = vec4(bar.y);\n"
4513 "}\n";
4514 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4515 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4516 VkPipelineObj pipe(m_device);
4517 pipe.AddShader(&vs);
4518 pipe.AddShader(&fs);
4519 pipe.AddColorAttachment();
4520 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4521
Karl Schultz6addd812016-02-02 17:17:23 -07004522 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4523 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4524 // This update should succeed, but offset size of 512 will overstep buffer
4525 // /w range 1024 & size 1024
4526 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4527 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4528 1, &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004529 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004530 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004531
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004532 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06004533 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004534
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004535 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4536 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4537}
4538
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004539TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004540 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004541 ASSERT_NO_FATAL_FAILURE(InitState());
4542 ASSERT_NO_FATAL_FAILURE(InitViewport());
4543 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4544
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004545 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004546 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004547 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4548 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4549 pipeline_layout_ci.pushConstantRangeCount = 1;
4550 pipeline_layout_ci.pPushConstantRanges = &pc_range;
4551
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004552 //
4553 // Check for invalid push constant ranges in pipeline layouts.
4554 //
4555 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06004556 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004557 char const *msg;
4558 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004559
Karl Schultzc81037d2016-05-12 08:11:23 -06004560 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
4561 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
4562 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
4563 "vkCreatePipelineLayout() call has push constants index 0 with "
4564 "size 0."},
4565 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
4566 "vkCreatePipelineLayout() call has push constants index 0 with "
4567 "size 1."},
4568 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
4569 "vkCreatePipelineLayout() call has push constants index 0 with "
4570 "size 1."},
4571 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
4572 "vkCreatePipelineLayout() call has push constants index 0 with "
4573 "size 0."},
4574 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
4575 "vkCreatePipelineLayout() call has push constants index 0 with "
4576 "offset 1. Offset must"},
4577 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
4578 "vkCreatePipelineLayout() call has push constants index 0 "
4579 "with offset "},
4580 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
4581 "vkCreatePipelineLayout() call has push constants "
4582 "index 0 with offset "},
4583 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
4584 "vkCreatePipelineLayout() call has push constants index 0 "
4585 "with offset "},
4586 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
4587 "vkCreatePipelineLayout() call has push "
4588 "constants index 0 with offset "},
4589 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
4590 "vkCreatePipelineLayout() call has push "
4591 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004592 }};
4593
4594 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06004595 for (const auto &iter : range_tests) {
4596 pc_range = iter.range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4598 iter.msg);
4599 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
4600 NULL, &pipeline_layout);
4601 m_errorMonitor->VerifyFound();
4602 if (VK_SUCCESS == err) {
4603 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4604 }
4605 }
4606
4607 // Check for invalid stage flag
4608 pc_range.offset = 0;
4609 pc_range.size = 16;
4610 pc_range.stageFlags = 0;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004611 m_errorMonitor->SetDesiredFailureMsg(
4612 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004613 "vkCreatePipelineLayout() call has no stageFlags set.");
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004614 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4615 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004616 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004617 if (VK_SUCCESS == err) {
4618 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4619 }
4620
4621 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06004622 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004623 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06004624 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004625 char const *msg;
4626 };
4627
Karl Schultzc81037d2016-05-12 08:11:23 -06004628 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004629 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4630 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4631 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4632 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4633 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4634 "vkCreatePipelineLayout() call has push constants with overlapping "
4635 "ranges: 0:[0, 4), 1:[0, 4)"},
4636 {
4637 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4638 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4639 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4640 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
4641 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
4642 "vkCreatePipelineLayout() call has push constants with "
4643 "overlapping "
4644 "ranges: 3:[12, 20), 4:[16, 20)",
4645 },
4646 {
4647 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4648 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
4649 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4650 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4651 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4652 "vkCreatePipelineLayout() call has push constants with "
4653 "overlapping "
4654 "ranges: 0:[16, 20), 1:[12, 20)",
4655 },
4656 {
4657 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4658 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4659 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4660 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
4661 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4662 "vkCreatePipelineLayout() call has push constants with "
4663 "overlapping "
4664 "ranges: 0:[16, 20), 3:[12, 20)",
4665 },
4666 {
4667 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4668 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
4669 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
4670 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
4671 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
4672 "vkCreatePipelineLayout() call has push constants with "
4673 "overlapping "
4674 "ranges: 0:[16, 20), 2:[4, 100)",
4675 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004676
Karl Schultzc81037d2016-05-12 08:11:23 -06004677 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004678 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06004679 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
4680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004681 iter.msg);
4682 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
4683 NULL, &pipeline_layout);
4684 m_errorMonitor->VerifyFound();
4685 if (VK_SUCCESS == err) {
4686 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4687 }
4688 }
4689
4690 // Run some positive tests to make sure overlap checking in the layer is OK
Karl Schultzc81037d2016-05-12 08:11:23 -06004691 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos =
4692 {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4693 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4694 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4695 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
4696 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
4697 ""},
4698 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
4699 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
4700 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
4701 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
4702 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4703 ""}}};
4704 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004705 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
4706 m_errorMonitor->ExpectSuccess();
4707 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
4708 NULL, &pipeline_layout);
4709 m_errorMonitor->VerifyNotFound();
4710 if (VK_SUCCESS == err) {
4711 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4712 }
4713 }
4714
4715 //
4716 // CmdPushConstants tests
4717 //
Karl Schultzc81037d2016-05-12 08:11:23 -06004718 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004719
4720 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzc81037d2016-05-12 08:11:23 -06004721 const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{
4722 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
4723 "vkCmdPushConstants() call has push constants with size 0. Size "
4724 "must be greater than zero and a multiple of 4."},
4725 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
4726 "vkCmdPushConstants() call has push constants with size 1. Size "
4727 "must be greater than zero and a multiple of 4."},
4728 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
4729 "vkCmdPushConstants() call has push constants with size 1. Size "
4730 "must be greater than zero and a multiple of 4."},
4731 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
4732 "vkCmdPushConstants() call has push constants with offset 1. "
4733 "Offset must be a multiple of 4."},
4734 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
4735 "vkCmdPushConstants() call has push constants with offset 1. "
4736 "Offset must be a multiple of 4."},
4737 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
4738 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
4739 "0x1 not within flag-matching ranges in pipeline layout"},
4740 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
4741 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
4742 "0x1 not within flag-matching ranges in pipeline layout"},
4743 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
4744 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
4745 "0x1 not within flag-matching ranges in pipeline layout"},
4746 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
4747 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
4748 "0x1 not within flag-matching ranges in pipeline layout"},
4749 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
4750 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
4751 "any of the ranges in pipeline layout"},
4752 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
4753 0, 16},
4754 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
4755 "any of the ranges in pipeline layout"},
4756 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004757 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004758 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004759 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004760 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004761 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004762 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004763 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004764 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004765 "vkCmdPushConstants() call has push constants with offset "},
4766 }};
4767
4768 // Two ranges for testing robustness
Karl Schultzc81037d2016-05-12 08:11:23 -06004769 const VkPushConstantRange pc_range2[] = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004770 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06004771 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004772 };
Karl Schultzc81037d2016-05-12 08:11:23 -06004773 pipeline_layout_ci.pushConstantRangeCount =
4774 sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004775 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004776 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4777 &pipeline_layout);
4778 ASSERT_VK_SUCCESS(err);
4779 BeginCommandBuffer();
Karl Schultzc81037d2016-05-12 08:11:23 -06004780 for (const auto &iter : cmd_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4782 iter.msg);
4783 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
Karl Schultzc81037d2016-05-12 08:11:23 -06004784 iter.range.stageFlags, iter.range.offset,
4785 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004786 m_errorMonitor->VerifyFound();
4787 }
4788
4789 // Check for invalid stage flag
4790 m_errorMonitor->SetDesiredFailureMsg(
4791 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4792 "vkCmdPushConstants() call has no stageFlags set.");
4793 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0,
Karl Schultzc81037d2016-05-12 08:11:23 -06004794 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004795 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06004796 EndCommandBuffer();
4797 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
4798 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004799
Karl Schultzc81037d2016-05-12 08:11:23 -06004800 // overlapping range tests with cmd
4801 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
4802 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
4803 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
4804 "0x1 not within flag-matching ranges in pipeline layout"},
4805 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4806 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
4807 "0x1 not within flag-matching ranges in pipeline layout"},
4808 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
4809 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
4810 "0x1 not within flag-matching ranges in pipeline layout"},
4811 }};
4812 const VkPushConstantRange pc_range3[] = {
4813 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
4814 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
4815 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4816 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
4817 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
4818 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
4819 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
4820 };
4821 pipeline_layout_ci.pushConstantRangeCount =
4822 sizeof(pc_range3) / sizeof(VkPushConstantRange);
4823 pipeline_layout_ci.pPushConstantRanges = pc_range3;
4824 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4825 &pipeline_layout);
4826 ASSERT_VK_SUCCESS(err);
4827 BeginCommandBuffer();
4828 for (const auto &iter : cmd_overlap_tests) {
4829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4830 iter.msg);
4831 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
4832 iter.range.stageFlags, iter.range.offset,
4833 iter.range.size, dummy_values);
4834 m_errorMonitor->VerifyFound();
4835 }
4836 EndCommandBuffer();
4837 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
4838 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4839
4840 // positive overlapping range tests with cmd
4841 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
4842 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
4843 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
4844 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
4845 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
4846 }};
4847 const VkPushConstantRange pc_range4[] = {
4848 {VK_SHADER_STAGE_VERTEX_BIT, 0, 64},
4849 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
4850 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
4851 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4852 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
4853 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
4854 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
4855 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
4856 };
4857 pipeline_layout_ci.pushConstantRangeCount =
4858 sizeof(pc_range4) / sizeof(VkPushConstantRange);
4859 pipeline_layout_ci.pPushConstantRanges = pc_range4;
4860 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4861 &pipeline_layout);
4862 ASSERT_VK_SUCCESS(err);
4863 BeginCommandBuffer();
4864 for (const auto &iter : cmd_overlap_tests_pos) {
4865 m_errorMonitor->ExpectSuccess();
4866 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
4867 iter.range.stageFlags, iter.range.offset,
4868 iter.range.size, dummy_values);
4869 m_errorMonitor->VerifyNotFound();
4870 }
4871 EndCommandBuffer();
4872 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004873 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4874}
4875
Karl Schultz6addd812016-02-02 17:17:23 -07004876TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07004877 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07004878 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07004879
4880 ASSERT_NO_FATAL_FAILURE(InitState());
4881 ASSERT_NO_FATAL_FAILURE(InitViewport());
4882 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4883
4884 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
4885 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004886 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4887 ds_type_count[0].descriptorCount = 10;
4888 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
4889 ds_type_count[1].descriptorCount = 2;
4890 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
4891 ds_type_count[2].descriptorCount = 2;
4892 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
4893 ds_type_count[3].descriptorCount = 5;
4894 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
4895 // type
4896 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4897 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4898 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07004899
4900 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004901 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4902 ds_pool_ci.pNext = NULL;
4903 ds_pool_ci.maxSets = 5;
4904 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
4905 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07004906
4907 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004908 err =
4909 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07004910 ASSERT_VK_SUCCESS(err);
4911
4912 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
4913 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004914 dsl_binding[0].binding = 0;
4915 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4916 dsl_binding[0].descriptorCount = 5;
4917 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4918 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07004919
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004920 // Create layout identical to set0 layout but w/ different stageFlags
4921 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004922 dsl_fs_stage_only.binding = 0;
4923 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4924 dsl_fs_stage_only.descriptorCount = 5;
4925 dsl_fs_stage_only.stageFlags =
4926 VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
4927 // bind time
4928 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07004929 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004930 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4931 ds_layout_ci.pNext = NULL;
4932 ds_layout_ci.bindingCount = 1;
4933 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07004934 static const uint32_t NUM_LAYOUTS = 4;
4935 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004936 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004937 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
4938 // layout for error case
4939 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4940 &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07004941 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004942 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Karl Schultz6addd812016-02-02 17:17:23 -07004943 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4944 &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004945 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07004946 dsl_binding[0].binding = 0;
4947 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004948 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07004949 dsl_binding[1].binding = 1;
4950 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
4951 dsl_binding[1].descriptorCount = 2;
4952 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
4953 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004954 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07004955 ds_layout_ci.bindingCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07004956 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4957 &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07004958 ASSERT_VK_SUCCESS(err);
4959 dsl_binding[0].binding = 0;
4960 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004961 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07004962 ds_layout_ci.bindingCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07004963 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4964 &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07004965 ASSERT_VK_SUCCESS(err);
4966 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004967 dsl_binding[0].descriptorCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07004968 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4969 &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07004970 ASSERT_VK_SUCCESS(err);
4971
4972 static const uint32_t NUM_SETS = 4;
4973 VkDescriptorSet descriptorSet[NUM_SETS] = {};
4974 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004975 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004976 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07004977 alloc_info.descriptorPool = ds_pool;
4978 alloc_info.pSetLayouts = ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004979 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4980 descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07004981 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004982 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07004983 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004984 alloc_info.pSetLayouts = &ds_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07004985 err =
4986 vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004987 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07004988
4989 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004990 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4991 pipeline_layout_ci.pNext = NULL;
4992 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
4993 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07004994
4995 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004996 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4997 &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07004998 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004999 // Create pipelineLayout with only one setLayout
5000 pipeline_layout_ci.setLayoutCount = 1;
5001 VkPipelineLayout single_pipe_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005002 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5003 &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005004 ASSERT_VK_SUCCESS(err);
5005 // Create pipelineLayout with 2 descriptor setLayout at index 0
5006 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
5007 VkPipelineLayout pipe_layout_one_desc;
Karl Schultz6addd812016-02-02 17:17:23 -07005008 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5009 &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005010 ASSERT_VK_SUCCESS(err);
5011 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
5012 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
5013 VkPipelineLayout pipe_layout_five_samp;
Karl Schultz6addd812016-02-02 17:17:23 -07005014 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5015 &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005016 ASSERT_VK_SUCCESS(err);
5017 // Create pipelineLayout with UB type, but stageFlags for FS only
5018 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
5019 VkPipelineLayout pipe_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005020 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5021 &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005022 ASSERT_VK_SUCCESS(err);
5023 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
5024 VkDescriptorSetLayout pl_bad_s0[2] = {};
5025 pl_bad_s0[0] = ds_layout_fs_only;
5026 pl_bad_s0[1] = ds_layout[1];
5027 pipeline_layout_ci.setLayoutCount = 2;
5028 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
5029 VkPipelineLayout pipe_layout_bad_set0;
Karl Schultz6addd812016-02-02 17:17:23 -07005030 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5031 &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005032 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005033
5034 // Create a buffer to update the descriptor with
5035 uint32_t qfi = 0;
5036 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005037 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5038 buffCI.size = 1024;
5039 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5040 buffCI.queueFamilyIndexCount = 1;
5041 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005042
5043 VkBuffer dyub;
5044 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5045 ASSERT_VK_SUCCESS(err);
5046 // Correctly update descriptor to avoid "NOT_UPDATED" error
5047 static const uint32_t NUM_BUFFS = 5;
5048 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005049 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005050 buffInfo[i].buffer = dyub;
5051 buffInfo[i].offset = 0;
5052 buffInfo[i].range = 1024;
5053 }
Karl Schultz6addd812016-02-02 17:17:23 -07005054 VkImage image;
5055 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5056 const int32_t tex_width = 32;
5057 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005058 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005059 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5060 image_create_info.pNext = NULL;
5061 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5062 image_create_info.format = tex_format;
5063 image_create_info.extent.width = tex_width;
5064 image_create_info.extent.height = tex_height;
5065 image_create_info.extent.depth = 1;
5066 image_create_info.mipLevels = 1;
5067 image_create_info.arrayLayers = 1;
5068 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5069 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5070 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5071 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005072 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5073 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005074
Karl Schultz6addd812016-02-02 17:17:23 -07005075 VkMemoryRequirements memReqs;
5076 VkDeviceMemory imageMem;
5077 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005078 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005079 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5080 memAlloc.pNext = NULL;
5081 memAlloc.allocationSize = 0;
5082 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005083 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
5084 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07005085 pass =
5086 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005087 ASSERT_TRUE(pass);
5088 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
5089 ASSERT_VK_SUCCESS(err);
5090 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
5091 ASSERT_VK_SUCCESS(err);
5092
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005093 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005094 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5095 image_view_create_info.image = image;
5096 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5097 image_view_create_info.format = tex_format;
5098 image_view_create_info.subresourceRange.layerCount = 1;
5099 image_view_create_info.subresourceRange.baseMipLevel = 0;
5100 image_view_create_info.subresourceRange.levelCount = 1;
5101 image_view_create_info.subresourceRange.aspectMask =
5102 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005103
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005104 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07005105 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
5106 &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005107 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005108 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005109 imageInfo[0].imageView = view;
5110 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5111 imageInfo[1].imageView = view;
5112 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005113 imageInfo[2].imageView = view;
5114 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5115 imageInfo[3].imageView = view;
5116 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005117
5118 static const uint32_t NUM_SET_UPDATES = 3;
5119 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
5120 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5121 descriptor_write[0].dstSet = descriptorSet[0];
5122 descriptor_write[0].dstBinding = 0;
5123 descriptor_write[0].descriptorCount = 5;
5124 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5125 descriptor_write[0].pBufferInfo = buffInfo;
5126 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5127 descriptor_write[1].dstSet = descriptorSet[1];
5128 descriptor_write[1].dstBinding = 0;
5129 descriptor_write[1].descriptorCount = 2;
5130 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5131 descriptor_write[1].pImageInfo = imageInfo;
5132 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5133 descriptor_write[2].dstSet = descriptorSet[1];
5134 descriptor_write[2].dstBinding = 1;
5135 descriptor_write[2].descriptorCount = 2;
5136 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005137 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005138
5139 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005140
Tobin Ehlis88452832015-12-03 09:40:56 -07005141 // Create PSO to be used for draw-time errors below
5142 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005143 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005144 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005145 "out gl_PerVertex {\n"
5146 " vec4 gl_Position;\n"
5147 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005148 "void main(){\n"
5149 " gl_Position = vec4(1);\n"
5150 "}\n";
5151 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005152 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005153 "\n"
5154 "layout(location=0) out vec4 x;\n"
5155 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5156 "void main(){\n"
5157 " x = vec4(bar.y);\n"
5158 "}\n";
5159 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5160 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005161 VkPipelineObj pipe(m_device);
5162 pipe.AddShader(&vs);
5163 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07005164 pipe.AddColorAttachment();
5165 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07005166
5167 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07005168
Karl Schultz6addd812016-02-02 17:17:23 -07005169 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5170 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5171 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
5172 // of PSO
5173 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
5174 // cmd_pipeline.c
5175 // due to the fact that cmd_alloc_dset_data() has not been called in
5176 // cmd_bind_graphics_pipeline()
5177 // TODO : Want to cause various binding incompatibility issues here to test
5178 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07005179 // First cause various verify_layout_compatibility() fails
5180 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005181 // verify_set_layout_compatibility fail cases:
5182 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultz6addd812016-02-02 17:17:23 -07005183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5184 " due to: invalid VkPipelineLayout ");
5185 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5186 VK_PIPELINE_BIND_POINT_GRAPHICS,
5187 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1,
5188 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005189 m_errorMonitor->VerifyFound();
5190
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005191 // 2. layoutIndex exceeds # of layouts in layout
Karl Schultz6addd812016-02-02 17:17:23 -07005192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5193 " attempting to bind set to index 1");
5194 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5195 VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout,
5196 0, 2, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005197 m_errorMonitor->VerifyFound();
5198
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005199 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005200 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
5201 // descriptors
5202 m_errorMonitor->SetDesiredFailureMsg(
5203 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005204 " has 2 descriptors, but DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005205 vkCmdBindDescriptorSets(
5206 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5207 pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005208 m_errorMonitor->VerifyFound();
5209
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005210 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
5211 // 4. same # of descriptors but mismatch in type
Karl Schultz6addd812016-02-02 17:17:23 -07005212 m_errorMonitor->SetDesiredFailureMsg(
5213 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005214 " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
Karl Schultz6addd812016-02-02 17:17:23 -07005215 vkCmdBindDescriptorSets(
5216 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5217 pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005218 m_errorMonitor->VerifyFound();
5219
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005220 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
5221 // 5. same # of descriptors but mismatch in stageFlags
Karl Schultz6addd812016-02-02 17:17:23 -07005222 m_errorMonitor->SetDesiredFailureMsg(
5223 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005224 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005225 vkCmdBindDescriptorSets(
5226 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5227 pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005228 m_errorMonitor->VerifyFound();
5229
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005230 // Cause INFO messages due to disturbing previously bound Sets
5231 // First bind sets 0 & 1
Karl Schultz6addd812016-02-02 17:17:23 -07005232 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5233 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5234 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005235 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Karl Schultz6addd812016-02-02 17:17:23 -07005236 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07005237 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005238 " previously bound as set #0 was disturbed ");
5239 vkCmdBindDescriptorSets(
5240 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5241 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005242 m_errorMonitor->VerifyFound();
5243
Karl Schultz6addd812016-02-02 17:17:23 -07005244 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5245 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5246 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005247 // 2. Disturb set after last bound set
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07005248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005249 " newly bound as set #0 so set #1 and "
5250 "any subsequent sets were disturbed ");
5251 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5252 VK_PIPELINE_BIND_POINT_GRAPHICS,
5253 pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005254 m_errorMonitor->VerifyFound();
5255
Tobin Ehlis88452832015-12-03 09:40:56 -07005256 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07005257 // 1. Error due to not binding required set (we actually use same code as
5258 // above to disturb set0)
5259 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5260 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5261 2, &descriptorSet[0], 0, NULL);
5262 vkCmdBindDescriptorSets(
5263 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5264 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
5265 m_errorMonitor->SetDesiredFailureMsg(
5266 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5267 " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07005268 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005269 m_errorMonitor->VerifyFound();
5270
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005271 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005272 // 2. Error due to bound set not being compatible with PSO's
5273 // VkPipelineLayout (diff stageFlags in this case)
5274 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5275 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5276 2, &descriptorSet[0], 0, NULL);
5277 m_errorMonitor->SetDesiredFailureMsg(
5278 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5279 " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07005280 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005281 m_errorMonitor->VerifyFound();
5282
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005283 // Remaining clean-up
5284 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005285 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005286 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
5287 }
5288 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06005289 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
5290 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005291 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005292 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5293 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5294}
Tobin Ehlis559c6382015-11-05 09:52:49 -07005295
Karl Schultz6addd812016-02-02 17:17:23 -07005296TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005297
Karl Schultz6addd812016-02-02 17:17:23 -07005298 m_errorMonitor->SetDesiredFailureMsg(
5299 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005300 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005301
5302 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005303 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005304 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005305 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005306
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005307 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005308}
5309
Karl Schultz6addd812016-02-02 17:17:23 -07005310TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
5311 VkResult err;
5312 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005313
Karl Schultz6addd812016-02-02 17:17:23 -07005314 m_errorMonitor->SetDesiredFailureMsg(
5315 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005316 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005317
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005318 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005319
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005320 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005321 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06005322 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005323 cmd.commandPool = m_commandPool;
5324 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005325 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06005326
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005327 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06005328 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005329
5330 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005331 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005332 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005333 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06005334 cmd_buf_info.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07005335 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
5336 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005337 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005338
5339 // The error should be caught by validation of the BeginCommandBuffer call
5340 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
5341
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005342 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005343 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005344}
5345
Karl Schultz6addd812016-02-02 17:17:23 -07005346TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005347 // Cause error due to Begin while recording CB
5348 // Then cause 2 errors for attempting to reset CB w/o having
5349 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
5350 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005352 "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005353
5354 ASSERT_NO_FATAL_FAILURE(InitState());
5355
5356 // Calls AllocateCommandBuffers
5357 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
5358
Karl Schultz6addd812016-02-02 17:17:23 -07005359 // Force the failure by setting the Renderpass and Framebuffer fields with
5360 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005361 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005362 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005363 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5364 cmd_buf_info.pNext = NULL;
5365 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005366 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005367
5368 // Begin CB to transition to recording state
5369 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
5370 // Can't re-begin. This should trigger error
5371 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005372 m_errorMonitor->VerifyFound();
5373
Karl Schultz6addd812016-02-02 17:17:23 -07005374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5375 "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005376 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
5377 // Reset attempt will trigger error due to incorrect CommandPool state
5378 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005379 m_errorMonitor->VerifyFound();
5380
Karl Schultz6addd812016-02-02 17:17:23 -07005381 m_errorMonitor->SetDesiredFailureMsg(
5382 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5383 " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005384 // Transition CB to RECORDED state
5385 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
5386 // Now attempting to Begin will implicitly reset, which triggers error
5387 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005388 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005389}
5390
Karl Schultz6addd812016-02-02 17:17:23 -07005391TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005392 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07005393 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005394
Karl Schultz6addd812016-02-02 17:17:23 -07005395 m_errorMonitor->SetDesiredFailureMsg(
5396 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005397 "Invalid Pipeline CreateInfo State: Vtx Shader required");
5398
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005399 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06005400 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005401
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005402 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005403 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5404 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005405
5406 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005407 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5408 ds_pool_ci.pNext = NULL;
5409 ds_pool_ci.maxSets = 1;
5410 ds_pool_ci.poolSizeCount = 1;
5411 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005412
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005413 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005414 err =
5415 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005416 ASSERT_VK_SUCCESS(err);
5417
Tony Barboureb254902015-07-15 12:50:33 -06005418 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005419 dsl_binding.binding = 0;
5420 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5421 dsl_binding.descriptorCount = 1;
5422 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5423 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005424
Tony Barboureb254902015-07-15 12:50:33 -06005425 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005426 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5427 ds_layout_ci.pNext = NULL;
5428 ds_layout_ci.bindingCount = 1;
5429 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06005430
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005431 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005432 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5433 &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005434 ASSERT_VK_SUCCESS(err);
5435
5436 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005437 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005438 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005439 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005440 alloc_info.descriptorPool = ds_pool;
5441 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005442 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5443 &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005444 ASSERT_VK_SUCCESS(err);
5445
Tony Barboureb254902015-07-15 12:50:33 -06005446 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005447 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5448 pipeline_layout_ci.setLayoutCount = 1;
5449 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005450
5451 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005452 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5453 &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005454 ASSERT_VK_SUCCESS(err);
5455
Tobin Ehlise68360f2015-10-01 11:15:13 -06005456 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07005457 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06005458
5459 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005460 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5461 vp_state_ci.scissorCount = 1;
5462 vp_state_ci.pScissors = &sc;
5463 vp_state_ci.viewportCount = 1;
5464 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005465
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005466 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
5467 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5468 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
5469 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
5470 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
5471 rs_state_ci.depthClampEnable = VK_FALSE;
5472 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
5473 rs_state_ci.depthBiasEnable = VK_FALSE;
5474
Tony Barboureb254902015-07-15 12:50:33 -06005475 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005476 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5477 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005478 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07005479 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5480 gp_ci.layout = pipeline_layout;
5481 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06005482
5483 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005484 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5485 pc_ci.initialDataSize = 0;
5486 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005487
5488 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06005489 VkPipelineCache pipelineCache;
5490
Karl Schultz6addd812016-02-02 17:17:23 -07005491 err =
5492 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06005493 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005494 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5495 &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005496
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005497 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005498
Chia-I Wuf7458c52015-10-26 21:10:41 +08005499 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5500 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5501 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5502 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005503}
Tobin Ehlis912df022015-09-17 08:46:18 -06005504/*// TODO : This test should be good, but needs Tess support in compiler to run
5505TEST_F(VkLayerTest, InvalidPatchControlPoints)
5506{
5507 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06005508 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005509
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005511 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
5512primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005513
Tobin Ehlis912df022015-09-17 08:46:18 -06005514 ASSERT_NO_FATAL_FAILURE(InitState());
5515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06005516
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005517 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06005518 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005519 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06005520
5521 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5522 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5523 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005524 ds_pool_ci.poolSizeCount = 1;
5525 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06005526
5527 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005528 err = vkCreateDescriptorPool(m_device->device(),
5529VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06005530 ASSERT_VK_SUCCESS(err);
5531
5532 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08005533 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06005534 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08005535 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06005536 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5537 dsl_binding.pImmutableSamplers = NULL;
5538
5539 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005540 ds_layout_ci.sType =
5541VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06005542 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005543 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005544 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06005545
5546 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005547 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5548&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06005549 ASSERT_VK_SUCCESS(err);
5550
5551 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07005552 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
5553VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06005554 ASSERT_VK_SUCCESS(err);
5555
5556 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005557 pipeline_layout_ci.sType =
5558VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06005559 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005560 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06005561 pipeline_layout_ci.pSetLayouts = &ds_layout;
5562
5563 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005564 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5565&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06005566 ASSERT_VK_SUCCESS(err);
5567
5568 VkPipelineShaderStageCreateInfo shaderStages[3];
5569 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
5570
Karl Schultz6addd812016-02-02 17:17:23 -07005571 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
5572this);
Tobin Ehlis912df022015-09-17 08:46:18 -06005573 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07005574 VkShaderObj
5575tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
5576this);
5577 VkShaderObj
5578te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
5579this);
Tobin Ehlis912df022015-09-17 08:46:18 -06005580
Karl Schultz6addd812016-02-02 17:17:23 -07005581 shaderStages[0].sType =
5582VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005583 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06005584 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07005585 shaderStages[1].sType =
5586VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005587 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06005588 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07005589 shaderStages[2].sType =
5590VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005591 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06005592 shaderStages[2].shader = te.handle();
5593
5594 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005595 iaCI.sType =
5596VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08005597 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06005598
5599 VkPipelineTessellationStateCreateInfo tsCI = {};
5600 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
5601 tsCI.patchControlPoints = 0; // This will cause an error
5602
5603 VkGraphicsPipelineCreateInfo gp_ci = {};
5604 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5605 gp_ci.pNext = NULL;
5606 gp_ci.stageCount = 3;
5607 gp_ci.pStages = shaderStages;
5608 gp_ci.pVertexInputState = NULL;
5609 gp_ci.pInputAssemblyState = &iaCI;
5610 gp_ci.pTessellationState = &tsCI;
5611 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005612 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06005613 gp_ci.pMultisampleState = NULL;
5614 gp_ci.pDepthStencilState = NULL;
5615 gp_ci.pColorBlendState = NULL;
5616 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5617 gp_ci.layout = pipeline_layout;
5618 gp_ci.renderPass = renderPass();
5619
5620 VkPipelineCacheCreateInfo pc_ci = {};
5621 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5622 pc_ci.pNext = NULL;
5623 pc_ci.initialSize = 0;
5624 pc_ci.initialData = 0;
5625 pc_ci.maxSize = 0;
5626
5627 VkPipeline pipeline;
5628 VkPipelineCache pipelineCache;
5629
Karl Schultz6addd812016-02-02 17:17:23 -07005630 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
5631&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06005632 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005633 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5634&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06005635
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005636 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005637
Chia-I Wuf7458c52015-10-26 21:10:41 +08005638 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5639 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5640 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5641 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06005642}
5643*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06005644// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07005645TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07005646 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005647
Karl Schultz6addd812016-02-02 17:17:23 -07005648 m_errorMonitor->SetDesiredFailureMsg(
5649 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005650 "Gfx Pipeline viewport count (1) must match scissor count (0).");
5651
Tobin Ehlise68360f2015-10-01 11:15:13 -06005652 ASSERT_NO_FATAL_FAILURE(InitState());
5653 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06005654
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005655 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005656 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5657 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005658
5659 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005660 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5661 ds_pool_ci.maxSets = 1;
5662 ds_pool_ci.poolSizeCount = 1;
5663 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005664
5665 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005666 err =
5667 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005668 ASSERT_VK_SUCCESS(err);
5669
5670 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005671 dsl_binding.binding = 0;
5672 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5673 dsl_binding.descriptorCount = 1;
5674 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005675
5676 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005677 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5678 ds_layout_ci.bindingCount = 1;
5679 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005680
5681 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005682 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5683 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005684 ASSERT_VK_SUCCESS(err);
5685
5686 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005687 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005688 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005689 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005690 alloc_info.descriptorPool = ds_pool;
5691 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005692 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5693 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005694 ASSERT_VK_SUCCESS(err);
5695
5696 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005697 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5698 pipeline_layout_ci.setLayoutCount = 1;
5699 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005700
5701 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005702 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5703 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005704 ASSERT_VK_SUCCESS(err);
5705
5706 VkViewport vp = {}; // Just need dummy vp to point to
5707
5708 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005709 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5710 vp_state_ci.scissorCount = 0;
5711 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
5712 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005713
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005714 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
5715 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5716 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
5717 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
5718 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
5719 rs_state_ci.depthClampEnable = VK_FALSE;
5720 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
5721 rs_state_ci.depthBiasEnable = VK_FALSE;
5722
Cody Northropeb3a6c12015-10-05 14:44:45 -06005723 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07005724 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06005725
Karl Schultz6addd812016-02-02 17:17:23 -07005726 VkShaderObj vs(m_device, bindStateVertShaderText,
5727 VK_SHADER_STAGE_VERTEX_BIT, this);
5728 VkShaderObj fs(m_device, bindStateFragShaderText,
5729 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06005730 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07005731 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08005732 shaderStages[0] = vs.GetStageCreateInfo();
5733 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005734
5735 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005736 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5737 gp_ci.stageCount = 2;
5738 gp_ci.pStages = shaderStages;
5739 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005740 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07005741 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5742 gp_ci.layout = pipeline_layout;
5743 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005744
5745 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005746 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005747
5748 VkPipeline pipeline;
5749 VkPipelineCache pipelineCache;
5750
Karl Schultz6addd812016-02-02 17:17:23 -07005751 err =
5752 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005753 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005754 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5755 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005756
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005757 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005758
Chia-I Wuf7458c52015-10-26 21:10:41 +08005759 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5760 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5761 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5762 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005763}
Karl Schultz6addd812016-02-02 17:17:23 -07005764// Don't set viewport state in PSO. This is an error b/c we always need this
5765// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06005766// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07005767TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06005768 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07005769 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005770
Karl Schultz6addd812016-02-02 17:17:23 -07005771 m_errorMonitor->SetDesiredFailureMsg(
5772 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005773 "Gfx Pipeline pViewportState is null. Even if ");
5774
Tobin Ehlise68360f2015-10-01 11:15:13 -06005775 ASSERT_NO_FATAL_FAILURE(InitState());
5776 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06005777
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005778 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005779 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5780 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005781
5782 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005783 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5784 ds_pool_ci.maxSets = 1;
5785 ds_pool_ci.poolSizeCount = 1;
5786 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005787
5788 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005789 err =
5790 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005791 ASSERT_VK_SUCCESS(err);
5792
5793 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005794 dsl_binding.binding = 0;
5795 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5796 dsl_binding.descriptorCount = 1;
5797 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005798
5799 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005800 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5801 ds_layout_ci.bindingCount = 1;
5802 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005803
5804 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005805 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5806 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005807 ASSERT_VK_SUCCESS(err);
5808
5809 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005810 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005811 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005812 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005813 alloc_info.descriptorPool = ds_pool;
5814 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005815 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5816 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005817 ASSERT_VK_SUCCESS(err);
5818
5819 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005820 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5821 pipeline_layout_ci.setLayoutCount = 1;
5822 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005823
5824 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005825 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5826 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005827 ASSERT_VK_SUCCESS(err);
5828
5829 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
5830 // Set scissor as dynamic to avoid second error
5831 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005832 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
5833 dyn_state_ci.dynamicStateCount = 1;
5834 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005835
Cody Northropeb3a6c12015-10-05 14:44:45 -06005836 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07005837 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06005838
Karl Schultz6addd812016-02-02 17:17:23 -07005839 VkShaderObj vs(m_device, bindStateVertShaderText,
5840 VK_SHADER_STAGE_VERTEX_BIT, this);
5841 VkShaderObj fs(m_device, bindStateFragShaderText,
5842 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06005843 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07005844 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08005845 shaderStages[0] = vs.GetStageCreateInfo();
5846 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005847
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005848
5849 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
5850 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5851 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
5852 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
5853 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
5854 rs_state_ci.depthClampEnable = VK_FALSE;
5855 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
5856 rs_state_ci.depthBiasEnable = VK_FALSE;
5857
Tobin Ehlise68360f2015-10-01 11:15:13 -06005858 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005859 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5860 gp_ci.stageCount = 2;
5861 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005862 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07005863 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
5864 // should cause validation error
5865 gp_ci.pDynamicState = &dyn_state_ci;
5866 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5867 gp_ci.layout = pipeline_layout;
5868 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005869
5870 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005871 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005872
5873 VkPipeline pipeline;
5874 VkPipelineCache pipelineCache;
5875
Karl Schultz6addd812016-02-02 17:17:23 -07005876 err =
5877 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005878 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005879 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5880 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005881
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005882 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005883
Chia-I Wuf7458c52015-10-26 21:10:41 +08005884 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5885 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5886 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5887 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005888}
5889// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07005890// Then run second test where dynamic scissor count doesn't match PSO scissor
5891// count
5892TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
5893 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005894
Karl Schultz6addd812016-02-02 17:17:23 -07005895 m_errorMonitor->SetDesiredFailureMsg(
5896 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005897 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
5898
Tobin Ehlise68360f2015-10-01 11:15:13 -06005899 ASSERT_NO_FATAL_FAILURE(InitState());
5900 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06005901
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005902 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005903 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5904 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005905
5906 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005907 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5908 ds_pool_ci.maxSets = 1;
5909 ds_pool_ci.poolSizeCount = 1;
5910 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005911
5912 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005913 err =
5914 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005915 ASSERT_VK_SUCCESS(err);
5916
5917 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005918 dsl_binding.binding = 0;
5919 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5920 dsl_binding.descriptorCount = 1;
5921 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005922
5923 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005924 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5925 ds_layout_ci.bindingCount = 1;
5926 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005927
5928 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005929 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5930 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005931 ASSERT_VK_SUCCESS(err);
5932
5933 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005934 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005935 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005936 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005937 alloc_info.descriptorPool = ds_pool;
5938 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005939 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5940 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005941 ASSERT_VK_SUCCESS(err);
5942
5943 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005944 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5945 pipeline_layout_ci.setLayoutCount = 1;
5946 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005947
5948 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005949 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5950 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005951 ASSERT_VK_SUCCESS(err);
5952
5953 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005954 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5955 vp_state_ci.viewportCount = 1;
5956 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
5957 vp_state_ci.scissorCount = 1;
5958 vp_state_ci.pScissors =
5959 NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06005960
5961 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
5962 // Set scissor as dynamic to avoid that 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
Cody Northropf6622dc2015-10-06 10:33:21 -06005980 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5981 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5982 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005983 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06005984 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005985 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06005986 vi_ci.pVertexAttributeDescriptions = nullptr;
5987
5988 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5989 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5990 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5991
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005992 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005993 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06005994 rs_ci.pNext = nullptr;
5995
Mark Youngc89c6312016-03-31 16:03:20 -06005996 VkPipelineColorBlendAttachmentState att = {};
5997 att.blendEnable = VK_FALSE;
5998 att.colorWriteMask = 0xf;
5999
Cody Northropf6622dc2015-10-06 10:33:21 -06006000 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6001 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6002 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006003 cb_ci.attachmentCount = 1;
6004 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06006005
Tobin Ehlise68360f2015-10-01 11:15:13 -06006006 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006007 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6008 gp_ci.stageCount = 2;
6009 gp_ci.pStages = shaderStages;
6010 gp_ci.pVertexInputState = &vi_ci;
6011 gp_ci.pInputAssemblyState = &ia_ci;
6012 gp_ci.pViewportState = &vp_state_ci;
6013 gp_ci.pRasterizationState = &rs_ci;
6014 gp_ci.pColorBlendState = &cb_ci;
6015 gp_ci.pDynamicState = &dyn_state_ci;
6016 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6017 gp_ci.layout = pipeline_layout;
6018 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006019
6020 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006021 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006022
6023 VkPipeline pipeline;
6024 VkPipelineCache pipelineCache;
6025
Karl Schultz6addd812016-02-02 17:17:23 -07006026 err =
6027 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006028 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006029 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6030 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006031
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006032 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006033
Tobin Ehlisd332f282015-10-02 11:00:56 -06006034 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07006035 // First need to successfully create the PSO from above by setting
6036 // pViewports
6037 m_errorMonitor->SetDesiredFailureMsg(
6038 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6039 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO "
6040 "scissorCount is 1. These counts must match.");
6041
6042 VkViewport vp = {}; // Just need dummy vp to point to
6043 vp_state_ci.pViewports = &vp;
6044 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6045 &gp_ci, NULL, &pipeline);
6046 ASSERT_VK_SUCCESS(err);
6047 BeginCommandBuffer();
6048 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6049 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
6050 VkRect2D scissors[2] = {}; // don't care about data
6051 // Count of 2 doesn't match PSO count of 1
6052 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
6053 Draw(1, 0, 0, 0);
6054
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006055 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006056
6057 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6058 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6059 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6060 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6061}
6062// Create PSO w/o non-zero scissorCount but no scissor data
6063// Then run second test where dynamic viewportCount doesn't match PSO
6064// viewportCount
6065TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
6066 VkResult err;
6067
6068 m_errorMonitor->SetDesiredFailureMsg(
6069 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6070 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
6071
6072 ASSERT_NO_FATAL_FAILURE(InitState());
6073 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6074
6075 VkDescriptorPoolSize ds_type_count = {};
6076 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6077 ds_type_count.descriptorCount = 1;
6078
6079 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6080 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6081 ds_pool_ci.maxSets = 1;
6082 ds_pool_ci.poolSizeCount = 1;
6083 ds_pool_ci.pPoolSizes = &ds_type_count;
6084
6085 VkDescriptorPool ds_pool;
6086 err =
6087 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6088 ASSERT_VK_SUCCESS(err);
6089
6090 VkDescriptorSetLayoutBinding dsl_binding = {};
6091 dsl_binding.binding = 0;
6092 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6093 dsl_binding.descriptorCount = 1;
6094 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6095
6096 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6097 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6098 ds_layout_ci.bindingCount = 1;
6099 ds_layout_ci.pBindings = &dsl_binding;
6100
6101 VkDescriptorSetLayout ds_layout;
6102 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6103 &ds_layout);
6104 ASSERT_VK_SUCCESS(err);
6105
6106 VkDescriptorSet descriptorSet;
6107 VkDescriptorSetAllocateInfo alloc_info = {};
6108 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6109 alloc_info.descriptorSetCount = 1;
6110 alloc_info.descriptorPool = ds_pool;
6111 alloc_info.pSetLayouts = &ds_layout;
6112 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6113 &descriptorSet);
6114 ASSERT_VK_SUCCESS(err);
6115
6116 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6117 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6118 pipeline_layout_ci.setLayoutCount = 1;
6119 pipeline_layout_ci.pSetLayouts = &ds_layout;
6120
6121 VkPipelineLayout pipeline_layout;
6122 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6123 &pipeline_layout);
6124 ASSERT_VK_SUCCESS(err);
6125
6126 VkPipelineViewportStateCreateInfo vp_state_ci = {};
6127 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6128 vp_state_ci.scissorCount = 1;
6129 vp_state_ci.pScissors =
6130 NULL; // Null scissor w/ count of 1 should cause error
6131 vp_state_ci.viewportCount = 1;
6132 vp_state_ci.pViewports =
6133 NULL; // vp is dynamic (below) so this won't cause error
6134
6135 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
6136 // Set scissor as dynamic to avoid that error
6137 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
6138 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6139 dyn_state_ci.dynamicStateCount = 1;
6140 dyn_state_ci.pDynamicStates = &vp_state;
6141
6142 VkPipelineShaderStageCreateInfo shaderStages[2];
6143 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6144
6145 VkShaderObj vs(m_device, bindStateVertShaderText,
6146 VK_SHADER_STAGE_VERTEX_BIT, this);
6147 VkShaderObj fs(m_device, bindStateFragShaderText,
6148 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006149 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006150 // but add it to be able to run on more devices
6151 shaderStages[0] = vs.GetStageCreateInfo();
6152 shaderStages[1] = fs.GetStageCreateInfo();
6153
6154 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6155 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6156 vi_ci.pNext = nullptr;
6157 vi_ci.vertexBindingDescriptionCount = 0;
6158 vi_ci.pVertexBindingDescriptions = nullptr;
6159 vi_ci.vertexAttributeDescriptionCount = 0;
6160 vi_ci.pVertexAttributeDescriptions = nullptr;
6161
6162 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6163 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6164 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6165
6166 VkPipelineRasterizationStateCreateInfo rs_ci = {};
6167 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6168 rs_ci.pNext = nullptr;
6169
Mark Youngc89c6312016-03-31 16:03:20 -06006170 VkPipelineColorBlendAttachmentState att = {};
6171 att.blendEnable = VK_FALSE;
6172 att.colorWriteMask = 0xf;
6173
Karl Schultz6addd812016-02-02 17:17:23 -07006174 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6175 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6176 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006177 cb_ci.attachmentCount = 1;
6178 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07006179
6180 VkGraphicsPipelineCreateInfo gp_ci = {};
6181 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6182 gp_ci.stageCount = 2;
6183 gp_ci.pStages = shaderStages;
6184 gp_ci.pVertexInputState = &vi_ci;
6185 gp_ci.pInputAssemblyState = &ia_ci;
6186 gp_ci.pViewportState = &vp_state_ci;
6187 gp_ci.pRasterizationState = &rs_ci;
6188 gp_ci.pColorBlendState = &cb_ci;
6189 gp_ci.pDynamicState = &dyn_state_ci;
6190 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6191 gp_ci.layout = pipeline_layout;
6192 gp_ci.renderPass = renderPass();
6193
6194 VkPipelineCacheCreateInfo pc_ci = {};
6195 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6196
6197 VkPipeline pipeline;
6198 VkPipelineCache pipelineCache;
6199
6200 err =
6201 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6202 ASSERT_VK_SUCCESS(err);
6203 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6204 &gp_ci, NULL, &pipeline);
6205
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006206 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006207
6208 // Now hit second fail case where we set scissor w/ different count than PSO
6209 // First need to successfully create the PSO from above by setting
6210 // pViewports
6211 m_errorMonitor->SetDesiredFailureMsg(
6212 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6213 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO "
6214 "viewportCount is 1. These counts must match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006215
Tobin Ehlisd332f282015-10-02 11:00:56 -06006216 VkRect2D sc = {}; // Just need dummy vp to point to
6217 vp_state_ci.pScissors = &sc;
Karl Schultz6addd812016-02-02 17:17:23 -07006218 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6219 &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006220 ASSERT_VK_SUCCESS(err);
6221 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006222 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6223 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006224 VkViewport viewports[2] = {}; // don't care about data
6225 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07006226 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006227 Draw(1, 0, 0, 0);
6228
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006229 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006230
Chia-I Wuf7458c52015-10-26 21:10:41 +08006231 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6232 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6233 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6234 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006235}
6236
Mark Young7394fdd2016-03-31 14:56:43 -06006237TEST_F(VkLayerTest, PSOLineWidthInvalid) {
6238 VkResult err;
6239
6240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06006241 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06006242
6243 ASSERT_NO_FATAL_FAILURE(InitState());
6244 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6245
6246 VkDescriptorPoolSize ds_type_count = {};
6247 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6248 ds_type_count.descriptorCount = 1;
6249
6250 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6251 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6252 ds_pool_ci.maxSets = 1;
6253 ds_pool_ci.poolSizeCount = 1;
6254 ds_pool_ci.pPoolSizes = &ds_type_count;
6255
6256 VkDescriptorPool ds_pool;
6257 err =
6258 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6259 ASSERT_VK_SUCCESS(err);
6260
6261 VkDescriptorSetLayoutBinding dsl_binding = {};
6262 dsl_binding.binding = 0;
6263 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6264 dsl_binding.descriptorCount = 1;
6265 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6266
6267 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6268 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6269 ds_layout_ci.bindingCount = 1;
6270 ds_layout_ci.pBindings = &dsl_binding;
6271
6272 VkDescriptorSetLayout ds_layout;
6273 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6274 &ds_layout);
6275 ASSERT_VK_SUCCESS(err);
6276
6277 VkDescriptorSet descriptorSet;
6278 VkDescriptorSetAllocateInfo alloc_info = {};
6279 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6280 alloc_info.descriptorSetCount = 1;
6281 alloc_info.descriptorPool = ds_pool;
6282 alloc_info.pSetLayouts = &ds_layout;
6283 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6284 &descriptorSet);
6285 ASSERT_VK_SUCCESS(err);
6286
6287 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6288 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6289 pipeline_layout_ci.setLayoutCount = 1;
6290 pipeline_layout_ci.pSetLayouts = &ds_layout;
6291
6292 VkPipelineLayout pipeline_layout;
6293 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6294 &pipeline_layout);
6295 ASSERT_VK_SUCCESS(err);
6296
6297 VkPipelineViewportStateCreateInfo vp_state_ci = {};
6298 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6299 vp_state_ci.scissorCount = 1;
6300 vp_state_ci.pScissors = NULL;
6301 vp_state_ci.viewportCount = 1;
6302 vp_state_ci.pViewports = NULL;
6303
6304 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT,
6305 VK_DYNAMIC_STATE_SCISSOR,
6306 VK_DYNAMIC_STATE_LINE_WIDTH};
6307 // Set scissor as dynamic to avoid that error
6308 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
6309 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6310 dyn_state_ci.dynamicStateCount = 2;
6311 dyn_state_ci.pDynamicStates = dynamic_states;
6312
6313 VkPipelineShaderStageCreateInfo shaderStages[2];
6314 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6315
6316 VkShaderObj vs(m_device, bindStateVertShaderText,
6317 VK_SHADER_STAGE_VERTEX_BIT, this);
6318 VkShaderObj fs(m_device, bindStateFragShaderText,
6319 VK_SHADER_STAGE_FRAGMENT_BIT,
6320 this); // TODO - We shouldn't need a fragment shader
6321 // but add it to be able to run on more devices
6322 shaderStages[0] = vs.GetStageCreateInfo();
6323 shaderStages[1] = fs.GetStageCreateInfo();
6324
6325 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6326 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6327 vi_ci.pNext = nullptr;
6328 vi_ci.vertexBindingDescriptionCount = 0;
6329 vi_ci.pVertexBindingDescriptions = nullptr;
6330 vi_ci.vertexAttributeDescriptionCount = 0;
6331 vi_ci.pVertexAttributeDescriptions = nullptr;
6332
6333 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6334 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6335 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6336
6337 VkPipelineRasterizationStateCreateInfo rs_ci = {};
6338 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6339 rs_ci.pNext = nullptr;
6340
Mark Young47107952016-05-02 15:59:55 -06006341 // Check too low (line width of -1.0f).
6342 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06006343
6344 VkPipelineColorBlendAttachmentState att = {};
6345 att.blendEnable = VK_FALSE;
6346 att.colorWriteMask = 0xf;
6347
6348 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6349 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6350 cb_ci.pNext = nullptr;
6351 cb_ci.attachmentCount = 1;
6352 cb_ci.pAttachments = &att;
6353
6354 VkGraphicsPipelineCreateInfo gp_ci = {};
6355 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6356 gp_ci.stageCount = 2;
6357 gp_ci.pStages = shaderStages;
6358 gp_ci.pVertexInputState = &vi_ci;
6359 gp_ci.pInputAssemblyState = &ia_ci;
6360 gp_ci.pViewportState = &vp_state_ci;
6361 gp_ci.pRasterizationState = &rs_ci;
6362 gp_ci.pColorBlendState = &cb_ci;
6363 gp_ci.pDynamicState = &dyn_state_ci;
6364 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6365 gp_ci.layout = pipeline_layout;
6366 gp_ci.renderPass = renderPass();
6367
6368 VkPipelineCacheCreateInfo pc_ci = {};
6369 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6370
6371 VkPipeline pipeline;
6372 VkPipelineCache pipelineCache;
6373
6374 err =
6375 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6376 ASSERT_VK_SUCCESS(err);
6377 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6378 &gp_ci, NULL, &pipeline);
6379
6380 m_errorMonitor->VerifyFound();
6381
6382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6383 "Attempt to set lineWidth to 65536");
6384
6385 // Check too high (line width of 65536.0f).
6386 rs_ci.lineWidth = 65536.0f;
6387
6388 err =
6389 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6390 ASSERT_VK_SUCCESS(err);
6391 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6392 &gp_ci, NULL, &pipeline);
6393
6394 m_errorMonitor->VerifyFound();
6395
6396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06006397 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06006398
6399 dyn_state_ci.dynamicStateCount = 3;
6400
6401 rs_ci.lineWidth = 1.0f;
6402
6403 err =
6404 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6405 ASSERT_VK_SUCCESS(err);
6406 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6407 &gp_ci, NULL, &pipeline);
6408 BeginCommandBuffer();
6409 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6410 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
6411
6412 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06006413 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06006414 m_errorMonitor->VerifyFound();
6415
6416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6417 "Attempt to set lineWidth to 65536");
6418
6419 // Check too high with dynamic setting.
6420 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
6421 m_errorMonitor->VerifyFound();
6422 EndCommandBuffer();
6423
6424 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6425 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6426 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6427 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6428}
6429
Karl Schultz6addd812016-02-02 17:17:23 -07006430TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006431 // Bind a NULL RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006432 m_errorMonitor->SetDesiredFailureMsg(
6433 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006434 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006435
6436 ASSERT_NO_FATAL_FAILURE(InitState());
6437 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006438
Tony Barbourfe3351b2015-07-28 10:17:20 -06006439 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006440 // Don't care about RenderPass handle b/c error should be flagged before
6441 // that
6442 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL,
6443 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006444
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006445 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006446}
6447
Karl Schultz6addd812016-02-02 17:17:23 -07006448TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006449 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006450 m_errorMonitor->SetDesiredFailureMsg(
6451 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006452 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006453
6454 ASSERT_NO_FATAL_FAILURE(InitState());
6455 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006456
Tony Barbourfe3351b2015-07-28 10:17:20 -06006457 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006458 // Just create a dummy Renderpass that's non-NULL so we can get to the
6459 // proper error
Tony Barboureb254902015-07-15 12:50:33 -06006460 VkRenderPassBeginInfo rp_begin = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006461 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
6462 rp_begin.pNext = NULL;
6463 rp_begin.renderPass = renderPass();
6464 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006465
Karl Schultz6addd812016-02-02 17:17:23 -07006466 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
6467 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006468
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006469 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006470}
6471
Cody Northrop3bb4d962016-05-09 16:15:57 -06006472TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
6473
6474 TEST_DESCRIPTION("End a command buffer with an active render pass");
6475
6476 m_errorMonitor->SetDesiredFailureMsg(
6477 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6478 "It is invalid to issue this call inside an active render pass");
6479
6480 ASSERT_NO_FATAL_FAILURE(InitState());
6481 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6482
6483 // The framework's BeginCommandBuffer calls CreateRenderPass
6484 BeginCommandBuffer();
6485
6486 // Call directly into vkEndCommandBuffer instead of the
6487 // the framework's EndCommandBuffer, which inserts a
6488 // vkEndRenderPass
6489 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
6490
6491 m_errorMonitor->VerifyFound();
6492
6493 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
6494 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
6495}
6496
Karl Schultz6addd812016-02-02 17:17:23 -07006497TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006498 // Call CmdFillBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07006499 m_errorMonitor->SetDesiredFailureMsg(
6500 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006501 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006502
6503 ASSERT_NO_FATAL_FAILURE(InitState());
6504 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006505
6506 // Renderpass is started here
6507 BeginCommandBuffer();
6508
6509 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006510 vk_testing::Buffer dstBuffer;
6511 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006512
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006513 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006514
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006515 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006516}
6517
Karl Schultz6addd812016-02-02 17:17:23 -07006518TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006519 // Call CmdUpdateBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07006520 m_errorMonitor->SetDesiredFailureMsg(
6521 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006522 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006523
6524 ASSERT_NO_FATAL_FAILURE(InitState());
6525 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006526
6527 // Renderpass is started here
6528 BeginCommandBuffer();
6529
6530 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006531 vk_testing::Buffer dstBuffer;
6532 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006533
Karl Schultz6addd812016-02-02 17:17:23 -07006534 VkDeviceSize dstOffset = 0;
6535 VkDeviceSize dataSize = 1024;
6536 const uint32_t *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006537
Karl Schultz6addd812016-02-02 17:17:23 -07006538 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
6539 dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006540
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006541 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006542}
6543
Karl Schultz6addd812016-02-02 17:17:23 -07006544TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006545 // Call CmdClearColorImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006546 m_errorMonitor->SetDesiredFailureMsg(
6547 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006548 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006549
6550 ASSERT_NO_FATAL_FAILURE(InitState());
6551 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006552
6553 // Renderpass is started here
6554 BeginCommandBuffer();
6555
Michael Lentine0a369f62016-02-03 16:51:46 -06006556 VkClearColorValue clear_color;
6557 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07006558 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
6559 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6560 const int32_t tex_width = 32;
6561 const int32_t tex_height = 32;
6562 VkImageCreateInfo image_create_info = {};
6563 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6564 image_create_info.pNext = NULL;
6565 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6566 image_create_info.format = tex_format;
6567 image_create_info.extent.width = tex_width;
6568 image_create_info.extent.height = tex_height;
6569 image_create_info.extent.depth = 1;
6570 image_create_info.mipLevels = 1;
6571 image_create_info.arrayLayers = 1;
6572 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6573 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
6574 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006575
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006576 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07006577 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
6578 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006579
Karl Schultz6addd812016-02-02 17:17:23 -07006580 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
6581 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006582
Karl Schultz6addd812016-02-02 17:17:23 -07006583 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
6584 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006585
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006586 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006587}
6588
Karl Schultz6addd812016-02-02 17:17:23 -07006589TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006590 // Call CmdClearDepthStencilImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006591 m_errorMonitor->SetDesiredFailureMsg(
6592 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006593 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006594
6595 ASSERT_NO_FATAL_FAILURE(InitState());
6596 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006597
6598 // Renderpass is started here
6599 BeginCommandBuffer();
6600
6601 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07006602 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07006603 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
6604 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6605 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
6606 image_create_info.extent.width = 64;
6607 image_create_info.extent.height = 64;
6608 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6609 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006610
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006611 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07006612 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
6613 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006614
Karl Schultz6addd812016-02-02 17:17:23 -07006615 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
6616 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006617
Karl Schultz6addd812016-02-02 17:17:23 -07006618 vkCmdClearDepthStencilImage(
6619 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
6620 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
6621 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006622
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006623 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006624}
6625
Karl Schultz6addd812016-02-02 17:17:23 -07006626TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006627 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006628 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006629
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006631 "vkCmdClearAttachments: This call "
6632 "must be issued inside an active "
6633 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006634
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006635 ASSERT_NO_FATAL_FAILURE(InitState());
6636 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006637
6638 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006639 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006640 ASSERT_VK_SUCCESS(err);
6641
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006642 VkClearAttachment color_attachment;
6643 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6644 color_attachment.clearValue.color.float32[0] = 0;
6645 color_attachment.clearValue.color.float32[1] = 0;
6646 color_attachment.clearValue.color.float32[2] = 0;
6647 color_attachment.clearValue.color.float32[3] = 0;
6648 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07006649 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
6650 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
6651 &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006652
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006653 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006654}
6655
Karl Schultz9e66a292016-04-21 15:57:51 -06006656TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
6657 // Try to add a buffer memory barrier with no buffer.
6658 m_errorMonitor->SetDesiredFailureMsg(
6659 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6660 "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE");
6661
6662 ASSERT_NO_FATAL_FAILURE(InitState());
6663 BeginCommandBuffer();
6664
6665 VkBufferMemoryBarrier buf_barrier = {};
6666 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
6667 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6668 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6669 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6670 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6671 buf_barrier.buffer = VK_NULL_HANDLE;
6672 buf_barrier.offset = 0;
6673 buf_barrier.size = VK_WHOLE_SIZE;
6674 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6675 VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
6676 0, 0, nullptr, 1, &buf_barrier, 0, nullptr);
6677
6678 m_errorMonitor->VerifyFound();
6679}
6680
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06006681TEST_F(VkLayerTest, InvalidBarriers) {
6682 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
6683
6684 m_errorMonitor->SetDesiredFailureMsg(
6685 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
6686
6687 ASSERT_NO_FATAL_FAILURE(InitState());
6688 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6689
6690 VkMemoryBarrier mem_barrier = {};
6691 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
6692 mem_barrier.pNext = NULL;
6693 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6694 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6695 BeginCommandBuffer();
6696 // BeginCommandBuffer() starts a render pass
6697 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6698 VK_PIPELINE_STAGE_HOST_BIT,
6699 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
6700 &mem_barrier, 0, nullptr, 0, nullptr);
6701 m_errorMonitor->VerifyFound();
6702
6703 m_errorMonitor->SetDesiredFailureMsg(
6704 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6705 "Image Layout cannot be transitioned to UNDEFINED");
6706 VkImageObj image(m_device);
6707 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
6708 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6709 ASSERT_TRUE(image.initialized());
6710 VkImageMemoryBarrier img_barrier = {};
6711 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
6712 img_barrier.pNext = NULL;
6713 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6714 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6715 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
6716 // New layout can't be UNDEFINED
6717 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6718 img_barrier.image = image.handle();
6719 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6720 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6721 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6722 img_barrier.subresourceRange.baseArrayLayer = 0;
6723 img_barrier.subresourceRange.baseMipLevel = 0;
6724 img_barrier.subresourceRange.layerCount = 1;
6725 img_barrier.subresourceRange.levelCount = 1;
6726 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6727 VK_PIPELINE_STAGE_HOST_BIT,
6728 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6729 nullptr, 1, &img_barrier);
6730 m_errorMonitor->VerifyFound();
6731 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
6732
6733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6734 "Subresource must have the sum of the "
6735 "baseArrayLayer");
6736 // baseArrayLayer + layerCount must be <= image's arrayLayers
6737 img_barrier.subresourceRange.baseArrayLayer = 1;
6738 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6739 VK_PIPELINE_STAGE_HOST_BIT,
6740 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6741 nullptr, 1, &img_barrier);
6742 m_errorMonitor->VerifyFound();
6743 img_barrier.subresourceRange.baseArrayLayer = 0;
6744
6745 m_errorMonitor->SetDesiredFailureMsg(
6746 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6747 "Subresource must have the sum of the baseMipLevel");
6748 // baseMipLevel + levelCount must be <= image's mipLevels
6749 img_barrier.subresourceRange.baseMipLevel = 1;
6750 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6751 VK_PIPELINE_STAGE_HOST_BIT,
6752 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6753 nullptr, 1, &img_barrier);
6754 m_errorMonitor->VerifyFound();
6755 img_barrier.subresourceRange.baseMipLevel = 0;
6756
6757 m_errorMonitor->SetDesiredFailureMsg(
6758 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6759 "Buffer Barriers cannot be used during a render pass");
6760 vk_testing::Buffer buffer;
6761 buffer.init(*m_device, 256);
6762 VkBufferMemoryBarrier buf_barrier = {};
6763 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
6764 buf_barrier.pNext = NULL;
6765 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6766 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6767 buf_barrier.buffer = buffer.handle();
6768 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6769 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6770 buf_barrier.offset = 0;
6771 buf_barrier.size = VK_WHOLE_SIZE;
6772 // Can't send buffer barrier during a render pass
6773 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6774 VK_PIPELINE_STAGE_HOST_BIT,
6775 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
6776 &buf_barrier, 0, nullptr);
6777 m_errorMonitor->VerifyFound();
6778 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
6779
6780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6781 "which is not less than total size");
6782 buf_barrier.offset = 257;
6783 // Offset greater than total size
6784 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6785 VK_PIPELINE_STAGE_HOST_BIT,
6786 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
6787 &buf_barrier, 0, nullptr);
6788 m_errorMonitor->VerifyFound();
6789 buf_barrier.offset = 0;
6790
6791 m_errorMonitor->SetDesiredFailureMsg(
6792 VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
6793 buf_barrier.size = 257;
6794 // Size greater than total size
6795 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6796 VK_PIPELINE_STAGE_HOST_BIT,
6797 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
6798 &buf_barrier, 0, nullptr);
6799 m_errorMonitor->VerifyFound();
6800 buf_barrier.size = VK_WHOLE_SIZE;
6801
6802 m_errorMonitor->SetDesiredFailureMsg(
6803 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6804 "Image is a depth and stencil format and thus must "
6805 "have both VK_IMAGE_ASPECT_DEPTH_BIT and "
6806 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
6807 VkDepthStencilObj ds_image(m_device);
6808 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
6809 ASSERT_TRUE(ds_image.initialized());
6810 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
6811 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
6812 img_barrier.image = ds_image.handle();
6813 // Leave aspectMask at COLOR on purpose
6814 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6815 VK_PIPELINE_STAGE_HOST_BIT,
6816 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6817 nullptr, 1, &img_barrier);
6818 m_errorMonitor->VerifyFound();
6819}
6820
Karl Schultz6addd812016-02-02 17:17:23 -07006821TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006822 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006823 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006824
Karl Schultz6addd812016-02-02 17:17:23 -07006825 m_errorMonitor->SetDesiredFailureMsg(
6826 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006827 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
6828
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006829 ASSERT_NO_FATAL_FAILURE(InitState());
6830 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006831 uint32_t qfi = 0;
6832 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006833 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6834 buffCI.size = 1024;
6835 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
6836 buffCI.queueFamilyIndexCount = 1;
6837 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006838
6839 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006840 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006841 ASSERT_VK_SUCCESS(err);
6842
6843 BeginCommandBuffer();
6844 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006845 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6846 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006847 // Should error before calling to driver so don't care about actual data
Karl Schultz6addd812016-02-02 17:17:23 -07006848 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
6849 VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006850
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006851 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006852
Chia-I Wuf7458c52015-10-26 21:10:41 +08006853 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006854}
6855
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07006856TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
6857 // Create an out-of-range queueFamilyIndex
6858 m_errorMonitor->SetDesiredFailureMsg(
6859 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesde628532016-04-21 16:30:17 -06006860 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
6861 "of the indices specified when the device was created, via the "
6862 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07006863
6864 ASSERT_NO_FATAL_FAILURE(InitState());
6865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6866 VkBufferCreateInfo buffCI = {};
6867 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6868 buffCI.size = 1024;
6869 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
6870 buffCI.queueFamilyIndexCount = 1;
6871 // Introduce failure by specifying invalid queue_family_index
6872 uint32_t qfi = 777;
6873 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06006874 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07006875
6876 VkBuffer ib;
6877 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
6878
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006879 m_errorMonitor->VerifyFound();
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07006880}
6881
Karl Schultz6addd812016-02-02 17:17:23 -07006882TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
6883 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
6884 // secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006885
Karl Schultz6addd812016-02-02 17:17:23 -07006886 m_errorMonitor->SetDesiredFailureMsg(
6887 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006888 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006889
6890 ASSERT_NO_FATAL_FAILURE(InitState());
6891 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006892
6893 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006894 // ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006895 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
6896 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006897
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006898 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006899}
6900
Karl Schultz6addd812016-02-02 17:17:23 -07006901TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006902 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07006903 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06006904
Karl Schultz6addd812016-02-02 17:17:23 -07006905 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006906 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6907 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
6908 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006909
Tobin Ehlis3b780662015-05-28 12:11:26 -06006910 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07006911 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006912 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006913 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6914 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006915
6916 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006917 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6918 ds_pool_ci.pNext = NULL;
6919 ds_pool_ci.maxSets = 1;
6920 ds_pool_ci.poolSizeCount = 1;
6921 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06006922
Tobin Ehlis3b780662015-05-28 12:11:26 -06006923 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006924 err =
6925 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06006926 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06006927 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006928 dsl_binding.binding = 0;
6929 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6930 dsl_binding.descriptorCount = 1;
6931 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6932 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06006933
Tony Barboureb254902015-07-15 12:50:33 -06006934 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006935 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6936 ds_layout_ci.pNext = NULL;
6937 ds_layout_ci.bindingCount = 1;
6938 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006939
Tobin Ehlis3b780662015-05-28 12:11:26 -06006940 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006941 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6942 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06006943 ASSERT_VK_SUCCESS(err);
6944
6945 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006946 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006947 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006948 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006949 alloc_info.descriptorPool = ds_pool;
6950 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006951 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6952 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06006953 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06006954
Tobin Ehlis30db8f82016-05-05 08:19:48 -06006955 VkSamplerCreateInfo sampler_ci = {};
6956 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6957 sampler_ci.pNext = NULL;
6958 sampler_ci.magFilter = VK_FILTER_NEAREST;
6959 sampler_ci.minFilter = VK_FILTER_NEAREST;
6960 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6961 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6962 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6963 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6964 sampler_ci.mipLodBias = 1.0;
6965 sampler_ci.anisotropyEnable = VK_FALSE;
6966 sampler_ci.maxAnisotropy = 1;
6967 sampler_ci.compareEnable = VK_FALSE;
6968 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6969 sampler_ci.minLod = 1.0;
6970 sampler_ci.maxLod = 1.0;
6971 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6972 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6973 VkSampler sampler;
6974 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6975 ASSERT_VK_SUCCESS(err);
6976
6977 VkDescriptorImageInfo info = {};
6978 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08006979
6980 VkWriteDescriptorSet descriptor_write;
6981 memset(&descriptor_write, 0, sizeof(descriptor_write));
6982 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006983 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006984 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06006985 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08006986 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06006987 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08006988
6989 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6990
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006991 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006992
Chia-I Wuf7458c52015-10-26 21:10:41 +08006993 vkDestroySampler(m_device->device(), sampler, NULL);
6994 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6995 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006996}
6997
Karl Schultz6addd812016-02-02 17:17:23 -07006998TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006999 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07007000 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007001
Karl Schultz6addd812016-02-02 17:17:23 -07007002 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007003 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7004 " binding #0 with 1 total descriptors but update of 1 descriptors "
7005 "starting at binding offset of 0 combined with update array element "
7006 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007007
Tobin Ehlis3b780662015-05-28 12:11:26 -06007008 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007009 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007010 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007011 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7012 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007013
7014 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007015 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7016 ds_pool_ci.pNext = NULL;
7017 ds_pool_ci.maxSets = 1;
7018 ds_pool_ci.poolSizeCount = 1;
7019 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06007020
Tobin Ehlis3b780662015-05-28 12:11:26 -06007021 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007022 err =
7023 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007024 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007025
Tony Barboureb254902015-07-15 12:50:33 -06007026 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007027 dsl_binding.binding = 0;
7028 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7029 dsl_binding.descriptorCount = 1;
7030 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7031 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06007032
7033 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007034 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7035 ds_layout_ci.pNext = NULL;
7036 ds_layout_ci.bindingCount = 1;
7037 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007038
Tobin Ehlis3b780662015-05-28 12:11:26 -06007039 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007040 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7041 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007042 ASSERT_VK_SUCCESS(err);
7043
7044 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007045 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007046 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007047 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007048 alloc_info.descriptorPool = ds_pool;
7049 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007050 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7051 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007052 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007053
Tobin Ehlis30db8f82016-05-05 08:19:48 -06007054 // Correctly update descriptor to avoid "NOT_UPDATED" error
7055 VkDescriptorBufferInfo buff_info = {};
7056 buff_info.buffer =
7057 VkBuffer(0); // Don't care about buffer handle for this test
7058 buff_info.offset = 0;
7059 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007060
7061 VkWriteDescriptorSet descriptor_write;
7062 memset(&descriptor_write, 0, sizeof(descriptor_write));
7063 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007064 descriptor_write.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007065 descriptor_write.dstArrayElement =
7066 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08007067 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007068 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7069 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007070
7071 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7072
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007073 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007074
Chia-I Wuf7458c52015-10-26 21:10:41 +08007075 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7076 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007077}
7078
Karl Schultz6addd812016-02-02 17:17:23 -07007079TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
7080 // Create layout w/ count of 1 and attempt update to that layout w/ binding
7081 // index 2
7082 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007083
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7085 " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007086
Tobin Ehlis3b780662015-05-28 12:11:26 -06007087 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007088 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007089 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007090 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7091 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007092
7093 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007094 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7095 ds_pool_ci.pNext = NULL;
7096 ds_pool_ci.maxSets = 1;
7097 ds_pool_ci.poolSizeCount = 1;
7098 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06007099
Tobin Ehlis3b780662015-05-28 12:11:26 -06007100 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007101 err =
7102 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007103 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007104
Tony Barboureb254902015-07-15 12:50:33 -06007105 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007106 dsl_binding.binding = 0;
7107 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7108 dsl_binding.descriptorCount = 1;
7109 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7110 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06007111
7112 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007113 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7114 ds_layout_ci.pNext = NULL;
7115 ds_layout_ci.bindingCount = 1;
7116 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007117 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007118 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7119 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007120 ASSERT_VK_SUCCESS(err);
7121
7122 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007123 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007124 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007125 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007126 alloc_info.descriptorPool = ds_pool;
7127 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007128 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7129 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007130 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007131
Tony Barboureb254902015-07-15 12:50:33 -06007132 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007133 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7134 sampler_ci.pNext = NULL;
7135 sampler_ci.magFilter = VK_FILTER_NEAREST;
7136 sampler_ci.minFilter = VK_FILTER_NEAREST;
7137 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7138 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7139 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7140 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7141 sampler_ci.mipLodBias = 1.0;
7142 sampler_ci.anisotropyEnable = VK_FALSE;
7143 sampler_ci.maxAnisotropy = 1;
7144 sampler_ci.compareEnable = VK_FALSE;
7145 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7146 sampler_ci.minLod = 1.0;
7147 sampler_ci.maxLod = 1.0;
7148 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7149 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06007150
Tobin Ehlis3b780662015-05-28 12:11:26 -06007151 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007152 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007153 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007154
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007155 VkDescriptorImageInfo info = {};
7156 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007157
7158 VkWriteDescriptorSet descriptor_write;
7159 memset(&descriptor_write, 0, sizeof(descriptor_write));
7160 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007161 descriptor_write.dstSet = descriptorSet;
7162 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007163 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007164 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007165 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007166 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007167
7168 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7169
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007170 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007171
Chia-I Wuf7458c52015-10-26 21:10:41 +08007172 vkDestroySampler(m_device->device(), sampler, NULL);
7173 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7174 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007175}
7176
Karl Schultz6addd812016-02-02 17:17:23 -07007177TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
7178 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
7179 // types
7180 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007181
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis660bcdc2016-05-17 10:39:46 -06007183 ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007184
Tobin Ehlis3b780662015-05-28 12:11:26 -06007185 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007186
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007187 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007188 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7189 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007190
7191 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007192 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7193 ds_pool_ci.pNext = NULL;
7194 ds_pool_ci.maxSets = 1;
7195 ds_pool_ci.poolSizeCount = 1;
7196 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06007197
Tobin Ehlis3b780662015-05-28 12:11:26 -06007198 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007199 err =
7200 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007201 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06007202 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007203 dsl_binding.binding = 0;
7204 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7205 dsl_binding.descriptorCount = 1;
7206 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7207 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007208
Tony Barboureb254902015-07-15 12:50:33 -06007209 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007210 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7211 ds_layout_ci.pNext = NULL;
7212 ds_layout_ci.bindingCount = 1;
7213 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007214
Tobin Ehlis3b780662015-05-28 12:11:26 -06007215 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007216 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7217 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007218 ASSERT_VK_SUCCESS(err);
7219
7220 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007221 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007222 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007223 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007224 alloc_info.descriptorPool = ds_pool;
7225 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007226 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7227 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007228 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007229
Tony Barboureb254902015-07-15 12:50:33 -06007230 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007231 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7232 sampler_ci.pNext = NULL;
7233 sampler_ci.magFilter = VK_FILTER_NEAREST;
7234 sampler_ci.minFilter = VK_FILTER_NEAREST;
7235 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7236 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7237 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7238 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7239 sampler_ci.mipLodBias = 1.0;
7240 sampler_ci.anisotropyEnable = VK_FALSE;
7241 sampler_ci.maxAnisotropy = 1;
7242 sampler_ci.compareEnable = VK_FALSE;
7243 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7244 sampler_ci.minLod = 1.0;
7245 sampler_ci.maxLod = 1.0;
7246 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7247 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007248 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007249 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007250 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007251
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007252 VkDescriptorImageInfo info = {};
7253 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007254
7255 VkWriteDescriptorSet descriptor_write;
7256 memset(&descriptor_write, 0, sizeof(descriptor_write));
Karl Schultz6addd812016-02-02 17:17:23 -07007257 descriptor_write.sType =
7258 (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007259 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007260 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007261 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007262 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007263 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007264
7265 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7266
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007267 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007268
Chia-I Wuf7458c52015-10-26 21:10:41 +08007269 vkDestroySampler(m_device->device(), sampler, NULL);
7270 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7271 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007272}
7273
Karl Schultz6addd812016-02-02 17:17:23 -07007274TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007275 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07007276 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007277
Karl Schultz6addd812016-02-02 17:17:23 -07007278 m_errorMonitor->SetDesiredFailureMsg(
7279 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007280 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007281
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007282 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007283 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
7284 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007285 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007286 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
7287 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007288
7289 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007290 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7291 ds_pool_ci.pNext = NULL;
7292 ds_pool_ci.maxSets = 1;
7293 ds_pool_ci.poolSizeCount = 1;
7294 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007295
7296 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007297 err =
7298 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007299 ASSERT_VK_SUCCESS(err);
7300
7301 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007302 dsl_binding.binding = 0;
7303 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7304 dsl_binding.descriptorCount = 1;
7305 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7306 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007307
7308 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007309 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7310 ds_layout_ci.pNext = NULL;
7311 ds_layout_ci.bindingCount = 1;
7312 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007313 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007314 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7315 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007316 ASSERT_VK_SUCCESS(err);
7317
7318 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007319 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007320 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007321 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007322 alloc_info.descriptorPool = ds_pool;
7323 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007324 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7325 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007326 ASSERT_VK_SUCCESS(err);
7327
Karl Schultz6addd812016-02-02 17:17:23 -07007328 VkSampler sampler =
7329 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007330
7331 VkDescriptorImageInfo descriptor_info;
7332 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
7333 descriptor_info.sampler = sampler;
7334
7335 VkWriteDescriptorSet descriptor_write;
7336 memset(&descriptor_write, 0, sizeof(descriptor_write));
7337 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007338 descriptor_write.dstSet = descriptorSet;
7339 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007340 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007341 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7342 descriptor_write.pImageInfo = &descriptor_info;
7343
7344 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7345
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007346 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007347
Chia-I Wuf7458c52015-10-26 21:10:41 +08007348 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7349 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007350}
7351
Karl Schultz6addd812016-02-02 17:17:23 -07007352TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
7353 // Create a single combined Image/Sampler descriptor and send it an invalid
7354 // imageView
7355 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007356
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7358 "Attempted write update to combined "
7359 "image sampler descriptor failed due "
Tobin Ehlis63c4b8a2016-05-09 10:29:34 -06007360 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007361
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007362 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007363 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007364 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7365 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007366
7367 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007368 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7369 ds_pool_ci.pNext = NULL;
7370 ds_pool_ci.maxSets = 1;
7371 ds_pool_ci.poolSizeCount = 1;
7372 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007373
7374 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007375 err =
7376 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007377 ASSERT_VK_SUCCESS(err);
7378
7379 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007380 dsl_binding.binding = 0;
7381 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7382 dsl_binding.descriptorCount = 1;
7383 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7384 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007385
7386 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007387 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7388 ds_layout_ci.pNext = NULL;
7389 ds_layout_ci.bindingCount = 1;
7390 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007391 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007392 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7393 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007394 ASSERT_VK_SUCCESS(err);
7395
7396 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007397 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007398 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007399 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007400 alloc_info.descriptorPool = ds_pool;
7401 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007402 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7403 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007404 ASSERT_VK_SUCCESS(err);
7405
7406 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007407 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7408 sampler_ci.pNext = NULL;
7409 sampler_ci.magFilter = VK_FILTER_NEAREST;
7410 sampler_ci.minFilter = VK_FILTER_NEAREST;
7411 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7412 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7413 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7414 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7415 sampler_ci.mipLodBias = 1.0;
7416 sampler_ci.anisotropyEnable = VK_FALSE;
7417 sampler_ci.maxAnisotropy = 1;
7418 sampler_ci.compareEnable = VK_FALSE;
7419 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7420 sampler_ci.minLod = 1.0;
7421 sampler_ci.maxLod = 1.0;
7422 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7423 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007424
7425 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007426 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007427 ASSERT_VK_SUCCESS(err);
7428
Karl Schultz6addd812016-02-02 17:17:23 -07007429 VkImageView view =
7430 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007431
7432 VkDescriptorImageInfo descriptor_info;
7433 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
7434 descriptor_info.sampler = sampler;
7435 descriptor_info.imageView = view;
7436
7437 VkWriteDescriptorSet descriptor_write;
7438 memset(&descriptor_write, 0, sizeof(descriptor_write));
7439 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007440 descriptor_write.dstSet = descriptorSet;
7441 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007442 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007443 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7444 descriptor_write.pImageInfo = &descriptor_info;
7445
7446 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7447
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007448 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007449
Chia-I Wuf7458c52015-10-26 21:10:41 +08007450 vkDestroySampler(m_device->device(), sampler, NULL);
7451 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7452 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007453}
7454
Karl Schultz6addd812016-02-02 17:17:23 -07007455TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
7456 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
7457 // into the other
7458 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007459
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7461 " binding #1 with type "
7462 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
7463 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007464
Tobin Ehlis04356f92015-10-27 16:35:27 -06007465 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007466 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007467 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007468 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7469 ds_type_count[0].descriptorCount = 1;
7470 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7471 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007472
7473 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007474 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7475 ds_pool_ci.pNext = NULL;
7476 ds_pool_ci.maxSets = 1;
7477 ds_pool_ci.poolSizeCount = 2;
7478 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007479
7480 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007481 err =
7482 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007483 ASSERT_VK_SUCCESS(err);
7484 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007485 dsl_binding[0].binding = 0;
7486 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7487 dsl_binding[0].descriptorCount = 1;
7488 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7489 dsl_binding[0].pImmutableSamplers = NULL;
7490 dsl_binding[1].binding = 1;
7491 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7492 dsl_binding[1].descriptorCount = 1;
7493 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7494 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007495
7496 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007497 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7498 ds_layout_ci.pNext = NULL;
7499 ds_layout_ci.bindingCount = 2;
7500 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007501
7502 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007503 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7504 &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007505 ASSERT_VK_SUCCESS(err);
7506
7507 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007508 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007509 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007510 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007511 alloc_info.descriptorPool = ds_pool;
7512 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007513 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7514 &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007515 ASSERT_VK_SUCCESS(err);
7516
7517 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007518 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7519 sampler_ci.pNext = NULL;
7520 sampler_ci.magFilter = VK_FILTER_NEAREST;
7521 sampler_ci.minFilter = VK_FILTER_NEAREST;
7522 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7523 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7524 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7525 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7526 sampler_ci.mipLodBias = 1.0;
7527 sampler_ci.anisotropyEnable = VK_FALSE;
7528 sampler_ci.maxAnisotropy = 1;
7529 sampler_ci.compareEnable = VK_FALSE;
7530 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7531 sampler_ci.minLod = 1.0;
7532 sampler_ci.maxLod = 1.0;
7533 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7534 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007535
7536 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007537 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007538 ASSERT_VK_SUCCESS(err);
7539
7540 VkDescriptorImageInfo info = {};
7541 info.sampler = sampler;
7542
7543 VkWriteDescriptorSet descriptor_write;
7544 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
7545 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007546 descriptor_write.dstSet = descriptorSet;
7547 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08007548 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007549 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7550 descriptor_write.pImageInfo = &info;
7551 // This write update should succeed
7552 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7553 // Now perform a copy update that fails due to type mismatch
7554 VkCopyDescriptorSet copy_ds_update;
7555 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
7556 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
7557 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06007558 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007559 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007560 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08007561 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06007562 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
7563
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007564 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06007565 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07007566 m_errorMonitor->SetDesiredFailureMsg(
7567 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007568 " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -06007569 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
7570 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
7571 copy_ds_update.srcSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007572 copy_ds_update.srcBinding =
7573 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007574 copy_ds_update.dstSet = descriptorSet;
7575 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06007576 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06007577 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
7578
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007579 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007580
Tobin Ehlis04356f92015-10-27 16:35:27 -06007581 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07007582 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007583 VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
7584 "update array offset of 0 and update of "
7585 "5 descriptors oversteps total number "
7586 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007587
Tobin Ehlis04356f92015-10-27 16:35:27 -06007588 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
7589 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
7590 copy_ds_update.srcSet = descriptorSet;
7591 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007592 copy_ds_update.dstSet = descriptorSet;
7593 copy_ds_update.dstBinding = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007594 copy_ds_update.descriptorCount =
7595 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06007596 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
7597
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007598 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06007599
Chia-I Wuf7458c52015-10-26 21:10:41 +08007600 vkDestroySampler(m_device->device(), sampler, NULL);
7601 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7602 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007603}
7604
Karl Schultz6addd812016-02-02 17:17:23 -07007605TEST_F(VkLayerTest, NumSamplesMismatch) {
7606 // Create CommandBuffer where MSAA samples doesn't match RenderPass
7607 // sampleCount
7608 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007609
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007611 "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007612
Tobin Ehlis3b780662015-05-28 12:11:26 -06007613 ASSERT_NO_FATAL_FAILURE(InitState());
7614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007615 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06007616 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007617 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007618
7619 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007620 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7621 ds_pool_ci.pNext = NULL;
7622 ds_pool_ci.maxSets = 1;
7623 ds_pool_ci.poolSizeCount = 1;
7624 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06007625
Tobin Ehlis3b780662015-05-28 12:11:26 -06007626 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007627 err =
7628 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007629 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007630
Tony Barboureb254902015-07-15 12:50:33 -06007631 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007632 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06007633 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007634 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007635 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7636 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007637
Tony Barboureb254902015-07-15 12:50:33 -06007638 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7639 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7640 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007641 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007642 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007643
Tobin Ehlis3b780662015-05-28 12:11:26 -06007644 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007645 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7646 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007647 ASSERT_VK_SUCCESS(err);
7648
7649 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007650 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007651 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007652 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007653 alloc_info.descriptorPool = ds_pool;
7654 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007655 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7656 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007657 ASSERT_VK_SUCCESS(err);
7658
Tony Barboureb254902015-07-15 12:50:33 -06007659 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007660 pipe_ms_state_ci.sType =
7661 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7662 pipe_ms_state_ci.pNext = NULL;
7663 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7664 pipe_ms_state_ci.sampleShadingEnable = 0;
7665 pipe_ms_state_ci.minSampleShading = 1.0;
7666 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007667
Tony Barboureb254902015-07-15 12:50:33 -06007668 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007669 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7670 pipeline_layout_ci.pNext = NULL;
7671 pipeline_layout_ci.setLayoutCount = 1;
7672 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007673
7674 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007675 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7676 &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007677 ASSERT_VK_SUCCESS(err);
7678
Karl Schultz6addd812016-02-02 17:17:23 -07007679 VkShaderObj vs(m_device, bindStateVertShaderText,
7680 VK_SHADER_STAGE_VERTEX_BIT, this);
7681 VkShaderObj fs(m_device, bindStateFragShaderText,
7682 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06007683 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07007684 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06007685 VkPipelineObj pipe(m_device);
7686 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007687 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06007688 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06007689 pipe.SetMSAA(&pipe_ms_state_ci);
7690 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06007691
Tony Barbourfe3351b2015-07-28 10:17:20 -06007692 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007693 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7694 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06007695
Mark Young29927482016-05-04 14:38:51 -06007696 // Render triangle (the error should trigger on the attempt to draw).
7697 Draw(3, 1, 0, 0);
7698
7699 // Finalize recording of the command buffer
7700 EndCommandBuffer();
7701
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007702 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007703
Chia-I Wuf7458c52015-10-26 21:10:41 +08007704 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7705 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7706 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007707}
Mark Young29927482016-05-04 14:38:51 -06007708
Mark Youngc89c6312016-03-31 16:03:20 -06007709TEST_F(VkLayerTest, NumBlendAttachMismatch) {
7710 // Create Pipeline where the number of blend attachments doesn't match the
7711 // number of color attachments. In this case, we don't add any color
7712 // blend attachments even though we have a color attachment.
7713 VkResult err;
7714
7715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young29927482016-05-04 14:38:51 -06007716 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06007717
7718 ASSERT_NO_FATAL_FAILURE(InitState());
7719 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7720 VkDescriptorPoolSize ds_type_count = {};
7721 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7722 ds_type_count.descriptorCount = 1;
7723
7724 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7725 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7726 ds_pool_ci.pNext = NULL;
7727 ds_pool_ci.maxSets = 1;
7728 ds_pool_ci.poolSizeCount = 1;
7729 ds_pool_ci.pPoolSizes = &ds_type_count;
7730
7731 VkDescriptorPool ds_pool;
7732 err =
7733 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7734 ASSERT_VK_SUCCESS(err);
7735
7736 VkDescriptorSetLayoutBinding dsl_binding = {};
7737 dsl_binding.binding = 0;
7738 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7739 dsl_binding.descriptorCount = 1;
7740 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7741 dsl_binding.pImmutableSamplers = NULL;
7742
7743 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7744 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7745 ds_layout_ci.pNext = NULL;
7746 ds_layout_ci.bindingCount = 1;
7747 ds_layout_ci.pBindings = &dsl_binding;
7748
7749 VkDescriptorSetLayout ds_layout;
7750 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7751 &ds_layout);
7752 ASSERT_VK_SUCCESS(err);
7753
7754 VkDescriptorSet descriptorSet;
7755 VkDescriptorSetAllocateInfo alloc_info = {};
7756 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7757 alloc_info.descriptorSetCount = 1;
7758 alloc_info.descriptorPool = ds_pool;
7759 alloc_info.pSetLayouts = &ds_layout;
7760 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7761 &descriptorSet);
7762 ASSERT_VK_SUCCESS(err);
7763
7764 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7765 pipe_ms_state_ci.sType =
7766 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7767 pipe_ms_state_ci.pNext = NULL;
7768 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7769 pipe_ms_state_ci.sampleShadingEnable = 0;
7770 pipe_ms_state_ci.minSampleShading = 1.0;
7771 pipe_ms_state_ci.pSampleMask = NULL;
7772
7773 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7774 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7775 pipeline_layout_ci.pNext = NULL;
7776 pipeline_layout_ci.setLayoutCount = 1;
7777 pipeline_layout_ci.pSetLayouts = &ds_layout;
7778
7779 VkPipelineLayout pipeline_layout;
7780 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7781 &pipeline_layout);
7782 ASSERT_VK_SUCCESS(err);
7783
7784 VkShaderObj vs(m_device, bindStateVertShaderText,
7785 VK_SHADER_STAGE_VERTEX_BIT, this);
7786 VkShaderObj fs(m_device, bindStateFragShaderText,
7787 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06007788 this); // We shouldn't need a fragment shader
Mark Youngc89c6312016-03-31 16:03:20 -06007789 // but add it to be able to run on more devices
7790 VkPipelineObj pipe(m_device);
7791 pipe.AddShader(&vs);
7792 pipe.AddShader(&fs);
7793 pipe.SetMSAA(&pipe_ms_state_ci);
7794 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7795
7796 BeginCommandBuffer();
7797 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7798 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7799
Mark Young29927482016-05-04 14:38:51 -06007800 // Render triangle (the error should trigger on the attempt to draw).
7801 Draw(3, 1, 0, 0);
7802
7803 // Finalize recording of the command buffer
7804 EndCommandBuffer();
7805
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007806 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06007807
7808 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7809 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7810 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7811}
Mark Young29927482016-05-04 14:38:51 -06007812
Karl Schultz6addd812016-02-02 17:17:23 -07007813TEST_F(VkLayerTest, ClearCmdNoDraw) {
7814 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
7815 // to issuing a Draw
7816 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007817
Karl Schultz6addd812016-02-02 17:17:23 -07007818 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbour7e56d302016-03-02 15:12:01 -07007819 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007820 "vkCmdClearAttachments() issued on CB object ");
7821
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007822 ASSERT_NO_FATAL_FAILURE(InitState());
7823 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06007824
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007825 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007826 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7827 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007828
7829 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007830 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7831 ds_pool_ci.pNext = NULL;
7832 ds_pool_ci.maxSets = 1;
7833 ds_pool_ci.poolSizeCount = 1;
7834 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06007835
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007836 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007837 err =
7838 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007839 ASSERT_VK_SUCCESS(err);
7840
Tony Barboureb254902015-07-15 12:50:33 -06007841 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007842 dsl_binding.binding = 0;
7843 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7844 dsl_binding.descriptorCount = 1;
7845 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7846 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007847
Tony Barboureb254902015-07-15 12:50:33 -06007848 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007849 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7850 ds_layout_ci.pNext = NULL;
7851 ds_layout_ci.bindingCount = 1;
7852 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007853
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007854 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007855 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7856 &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007857 ASSERT_VK_SUCCESS(err);
7858
7859 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007860 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007861 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007862 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007863 alloc_info.descriptorPool = ds_pool;
7864 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007865 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7866 &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007867 ASSERT_VK_SUCCESS(err);
7868
Tony Barboureb254902015-07-15 12:50:33 -06007869 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007870 pipe_ms_state_ci.sType =
7871 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7872 pipe_ms_state_ci.pNext = NULL;
7873 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7874 pipe_ms_state_ci.sampleShadingEnable = 0;
7875 pipe_ms_state_ci.minSampleShading = 1.0;
7876 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007877
Tony Barboureb254902015-07-15 12:50:33 -06007878 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007879 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7880 pipeline_layout_ci.pNext = NULL;
7881 pipeline_layout_ci.setLayoutCount = 1;
7882 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007883
7884 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007885 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7886 &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007887 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007888
Karl Schultz6addd812016-02-02 17:17:23 -07007889 VkShaderObj vs(m_device, bindStateVertShaderText,
7890 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06007891 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07007892 // on more devices
7893 VkShaderObj fs(m_device, bindStateFragShaderText,
7894 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007895
Tony Barbour62e1a5b2015-08-06 10:16:07 -06007896 VkPipelineObj pipe(m_device);
7897 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007898 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06007899 pipe.SetMSAA(&pipe_ms_state_ci);
7900 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06007901
7902 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007903
Karl Schultz6addd812016-02-02 17:17:23 -07007904 // Main thing we care about for this test is that the VkImage obj we're
7905 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007906 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007907 VkClearAttachment color_attachment;
7908 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7909 color_attachment.clearValue.color.float32[0] = 1.0;
7910 color_attachment.clearValue.color.float32[1] = 1.0;
7911 color_attachment.clearValue.color.float32[2] = 1.0;
7912 color_attachment.clearValue.color.float32[3] = 1.0;
7913 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007914 VkClearRect clear_rect = {
7915 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007916
Karl Schultz6addd812016-02-02 17:17:23 -07007917 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
7918 &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007919
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007920 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007921
Chia-I Wuf7458c52015-10-26 21:10:41 +08007922 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7923 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7924 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007925}
7926
Karl Schultz6addd812016-02-02 17:17:23 -07007927TEST_F(VkLayerTest, VtxBufferBadIndex) {
7928 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06007929
Karl Schultz6addd812016-02-02 17:17:23 -07007930 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07007931 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07007932 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007933
Tobin Ehlis502480b2015-06-24 15:53:07 -06007934 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06007935 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06007936 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06007937
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007938 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007939 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7940 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007941
7942 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007943 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7944 ds_pool_ci.pNext = NULL;
7945 ds_pool_ci.maxSets = 1;
7946 ds_pool_ci.poolSizeCount = 1;
7947 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06007948
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06007949 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007950 err =
7951 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06007952 ASSERT_VK_SUCCESS(err);
7953
Tony Barboureb254902015-07-15 12:50:33 -06007954 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007955 dsl_binding.binding = 0;
7956 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7957 dsl_binding.descriptorCount = 1;
7958 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7959 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06007960
Tony Barboureb254902015-07-15 12:50:33 -06007961 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007962 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7963 ds_layout_ci.pNext = NULL;
7964 ds_layout_ci.bindingCount = 1;
7965 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007966
Tobin Ehlis502480b2015-06-24 15:53:07 -06007967 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007968 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7969 &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06007970 ASSERT_VK_SUCCESS(err);
7971
7972 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007973 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007974 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007975 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007976 alloc_info.descriptorPool = ds_pool;
7977 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007978 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7979 &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06007980 ASSERT_VK_SUCCESS(err);
7981
Tony Barboureb254902015-07-15 12:50:33 -06007982 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007983 pipe_ms_state_ci.sType =
7984 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7985 pipe_ms_state_ci.pNext = NULL;
7986 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7987 pipe_ms_state_ci.sampleShadingEnable = 0;
7988 pipe_ms_state_ci.minSampleShading = 1.0;
7989 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06007990
Tony Barboureb254902015-07-15 12:50:33 -06007991 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007992 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7993 pipeline_layout_ci.pNext = NULL;
7994 pipeline_layout_ci.setLayoutCount = 1;
7995 pipeline_layout_ci.pSetLayouts = &ds_layout;
7996 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06007997
Karl Schultz6addd812016-02-02 17:17:23 -07007998 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7999 &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008000 ASSERT_VK_SUCCESS(err);
8001
Karl Schultz6addd812016-02-02 17:17:23 -07008002 VkShaderObj vs(m_device, bindStateVertShaderText,
8003 VK_SHADER_STAGE_VERTEX_BIT, this);
8004 VkShaderObj fs(m_device, bindStateFragShaderText,
8005 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06008006 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07008007 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008008 VkPipelineObj pipe(m_device);
8009 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008010 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06008011 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008012 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008013 pipe.SetViewport(m_viewports);
8014 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008015 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06008016
8017 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008018 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8019 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06008020 // Don't care about actual data, just need to get to draw to flag error
8021 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz6addd812016-02-02 17:17:23 -07008022 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
8023 (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06008024 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06008025 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008026
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008027 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008028
Chia-I Wuf7458c52015-10-26 21:10:41 +08008029 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8030 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8031 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008032}
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06008033// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
8034TEST_F(VkLayerTest, InvalidImageLayout) {
8035 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
8036 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
8037 "images in the wrong layout when they're copied or transitioned.");
8038 // 3 in ValidateCmdBufImageLayouts
8039 // * -1 Attempt to submit cmd buf w/ deleted image
8040 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
8041 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
8042 m_errorMonitor->SetDesiredFailureMsg(
8043 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8044 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
8045
8046 ASSERT_NO_FATAL_FAILURE(InitState());
8047 // Create src & dst images to use for copy operations
8048 VkImage src_image;
8049 VkImage dst_image;
8050
8051 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8052 const int32_t tex_width = 32;
8053 const int32_t tex_height = 32;
8054
8055 VkImageCreateInfo image_create_info = {};
8056 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8057 image_create_info.pNext = NULL;
8058 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8059 image_create_info.format = tex_format;
8060 image_create_info.extent.width = tex_width;
8061 image_create_info.extent.height = tex_height;
8062 image_create_info.extent.depth = 1;
8063 image_create_info.mipLevels = 1;
8064 image_create_info.arrayLayers = 4;
8065 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8066 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8067 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8068 image_create_info.flags = 0;
8069
8070 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
8071 ASSERT_VK_SUCCESS(err);
8072 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
8073 ASSERT_VK_SUCCESS(err);
8074
8075 BeginCommandBuffer();
8076 VkImageCopy copyRegion;
8077 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8078 copyRegion.srcSubresource.mipLevel = 0;
8079 copyRegion.srcSubresource.baseArrayLayer = 0;
8080 copyRegion.srcSubresource.layerCount = 1;
8081 copyRegion.srcOffset.x = 0;
8082 copyRegion.srcOffset.y = 0;
8083 copyRegion.srcOffset.z = 0;
8084 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8085 copyRegion.dstSubresource.mipLevel = 0;
8086 copyRegion.dstSubresource.baseArrayLayer = 0;
8087 copyRegion.dstSubresource.layerCount = 1;
8088 copyRegion.dstOffset.x = 0;
8089 copyRegion.dstOffset.y = 0;
8090 copyRegion.dstOffset.z = 0;
8091 copyRegion.extent.width = 1;
8092 copyRegion.extent.height = 1;
8093 copyRegion.extent.depth = 1;
8094 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8095 m_errorMonitor->VerifyFound();
8096 // Now cause error due to src image layout changing
8097 m_errorMonitor->SetDesiredFailureMsg(
8098 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8099 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
8100 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8101 m_errorMonitor->VerifyFound();
8102 // Final src error is due to bad layout type
8103 m_errorMonitor->SetDesiredFailureMsg(
8104 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8105 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
8106 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8107 m_errorMonitor->VerifyFound();
8108 // Now verify same checks for dst
8109 m_errorMonitor->SetDesiredFailureMsg(
8110 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8111 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
8112 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8113 m_errorMonitor->VerifyFound();
8114 // Now cause error due to src image layout changing
8115 m_errorMonitor->SetDesiredFailureMsg(
8116 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8117 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
8118 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
8119 m_errorMonitor->VerifyFound();
8120 m_errorMonitor->SetDesiredFailureMsg(
8121 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8122 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
8123 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
8124 m_errorMonitor->VerifyFound();
8125 // Now cause error due to bad image layout transition in PipelineBarrier
8126 VkImageMemoryBarrier image_barrier[1] = {};
8127 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
8128 image_barrier[0].image = src_image;
8129 image_barrier[0].subresourceRange.layerCount = 2;
8130 image_barrier[0].subresourceRange.levelCount = 2;
8131 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8132 m_errorMonitor->SetDesiredFailureMsg(
8133 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8134 "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL.");
8135 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier);
8136 m_errorMonitor->VerifyFound();
8137
8138 // Finally some layout errors at RenderPass create time
8139 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
8140 VkAttachmentReference attach = {};
8141 // perf warning for GENERAL layout w/ non-DS input attachment
8142 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8143 VkSubpassDescription subpass = {};
8144 subpass.inputAttachmentCount = 1;
8145 subpass.pInputAttachments = &attach;
8146 VkRenderPassCreateInfo rpci = {};
8147 rpci.subpassCount = 1;
8148 rpci.pSubpasses = &subpass;
8149 rpci.attachmentCount = 1;
8150 VkAttachmentDescription attach_desc = {};
8151 attach_desc.format = VK_FORMAT_UNDEFINED;
8152 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -06008153 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06008154 VkRenderPass rp;
8155 m_errorMonitor->SetDesiredFailureMsg(
8156 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8157 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
8158 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8159 m_errorMonitor->VerifyFound();
8160 // error w/ non-general layout
8161 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
8162
8163 m_errorMonitor->SetDesiredFailureMsg(
8164 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8165 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
8166 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8167 m_errorMonitor->VerifyFound();
8168 subpass.inputAttachmentCount = 0;
8169 subpass.colorAttachmentCount = 1;
8170 subpass.pColorAttachments = &attach;
8171 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8172 // perf warning for GENERAL layout on color attachment
8173 m_errorMonitor->SetDesiredFailureMsg(
8174 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8175 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
8176 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8177 m_errorMonitor->VerifyFound();
8178 // error w/ non-color opt or GENERAL layout for color attachment
8179 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
8180 m_errorMonitor->SetDesiredFailureMsg(
8181 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8182 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
8183 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8184 m_errorMonitor->VerifyFound();
8185 subpass.colorAttachmentCount = 0;
8186 subpass.pDepthStencilAttachment = &attach;
8187 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8188 // perf warning for GENERAL layout on DS attachment
8189 m_errorMonitor->SetDesiredFailureMsg(
8190 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8191 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
8192 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8193 m_errorMonitor->VerifyFound();
8194 // error w/ non-ds opt or GENERAL layout for color attachment
8195 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
8196 m_errorMonitor->SetDesiredFailureMsg(
8197 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8198 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.");
8199 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8200 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -06008201 // For this error we need a valid renderpass so create default one
8202 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
8203 attach.attachment = 0;
8204 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
8205 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
8206 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
8207 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
8208 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
8209 // Can't do a CLEAR load on READ_ONLY initialLayout
8210 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8211 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
8212 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8214 " with invalid first layout "
8215 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
8216 "ONLY_OPTIMAL");
8217 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8218 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06008219
8220 vkDestroyImage(m_device->device(), src_image, NULL);
8221 vkDestroyImage(m_device->device(), dst_image, NULL);
8222}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008223#endif // DRAW_STATE_TESTS
8224
Tobin Ehlis0788f522015-05-26 16:11:58 -06008225#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06008226#if GTEST_IS_THREADSAFE
8227struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008228 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008229 VkEvent event;
8230 bool bailout;
8231};
8232
Karl Schultz6addd812016-02-02 17:17:23 -07008233extern "C" void *AddToCommandBuffer(void *arg) {
8234 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008235
Karl Schultz6addd812016-02-02 17:17:23 -07008236 for (int i = 0; i < 10000; i++) {
8237 vkCmdSetEvent(data->commandBuffer, data->event,
8238 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008239 if (data->bailout) {
8240 break;
8241 }
8242 }
8243 return NULL;
8244}
8245
Karl Schultz6addd812016-02-02 17:17:23 -07008246TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -06008247 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008248
Karl Schultz6addd812016-02-02 17:17:23 -07008249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8250 "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008251
Mike Stroyanaccf7692015-05-12 16:00:45 -06008252 ASSERT_NO_FATAL_FAILURE(InitState());
8253 ASSERT_NO_FATAL_FAILURE(InitViewport());
8254 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8255
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008256 // Calls AllocateCommandBuffers
8257 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06008258
8259 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008260 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008261
8262 VkEventCreateInfo event_info;
8263 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008264 VkResult err;
8265
8266 memset(&event_info, 0, sizeof(event_info));
8267 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8268
Chia-I Wuf7458c52015-10-26 21:10:41 +08008269 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008270 ASSERT_VK_SUCCESS(err);
8271
Mike Stroyanaccf7692015-05-12 16:00:45 -06008272 err = vkResetEvent(device(), event);
8273 ASSERT_VK_SUCCESS(err);
8274
8275 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008276 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008277 data.event = event;
8278 data.bailout = false;
8279 m_errorMonitor->SetBailout(&data.bailout);
8280 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06008281 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008282 // Add many entries to command buffer from this thread at the same time.
8283 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06008284
Mike Stroyan4268d1f2015-07-13 14:45:35 -06008285 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008286 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008287
Mike Stroyan10b8cb72016-01-22 15:22:03 -07008288 m_errorMonitor->SetBailout(NULL);
8289
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008290 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008291
Chia-I Wuf7458c52015-10-26 21:10:41 +08008292 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008293}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008294#endif // GTEST_IS_THREADSAFE
8295#endif // THREADING_TESTS
8296
Chris Forbes9f7ff632015-05-25 11:13:08 +12008297#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07008298TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008300 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008301
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008302 ASSERT_NO_FATAL_FAILURE(InitState());
8303 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8304
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008305 VkShaderModule module;
8306 VkShaderModuleCreateInfo moduleCreateInfo;
8307 struct icd_spv_header spv;
8308
8309 spv.magic = ICD_SPV_MAGIC;
8310 spv.version = ICD_SPV_VERSION;
8311 spv.gen_magic = 0;
8312
8313 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
8314 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07008315 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008316 moduleCreateInfo.codeSize = 4;
8317 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008318 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008319
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008320 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008321}
8322
Karl Schultz6addd812016-02-02 17:17:23 -07008323TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008325 "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008326
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008327 ASSERT_NO_FATAL_FAILURE(InitState());
8328 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8329
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008330 VkShaderModule module;
8331 VkShaderModuleCreateInfo moduleCreateInfo;
8332 struct icd_spv_header spv;
8333
8334 spv.magic = ~ICD_SPV_MAGIC;
8335 spv.version = ICD_SPV_VERSION;
8336 spv.gen_magic = 0;
8337
8338 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
8339 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07008340 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008341 moduleCreateInfo.codeSize = sizeof(spv) + 10;
8342 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008343 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008344
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008345 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008346}
8347
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008348#if 0
8349// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -07008350TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008352 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008353
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008354 ASSERT_NO_FATAL_FAILURE(InitState());
8355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8356
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008357 VkShaderModule module;
8358 VkShaderModuleCreateInfo moduleCreateInfo;
8359 struct icd_spv_header spv;
8360
8361 spv.magic = ICD_SPV_MAGIC;
8362 spv.version = ~ICD_SPV_VERSION;
8363 spv.gen_magic = 0;
8364
8365 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
8366 moduleCreateInfo.pNext = NULL;
8367
Karl Schultz6addd812016-02-02 17:17:23 -07008368 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008369 moduleCreateInfo.codeSize = sizeof(spv) + 10;
8370 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008371 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008372
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008373 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008374}
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008375#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008376
Karl Schultz6addd812016-02-02 17:17:23 -07008377TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008379 "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008380
Chris Forbes9f7ff632015-05-25 11:13:08 +12008381 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008382 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12008383
8384 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008385 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12008386 "\n"
8387 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07008388 "out gl_PerVertex {\n"
8389 " vec4 gl_Position;\n"
8390 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12008391 "void main(){\n"
8392 " gl_Position = vec4(1);\n"
8393 " x = 0;\n"
8394 "}\n";
8395 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008396 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12008397 "\n"
8398 "layout(location=0) out vec4 color;\n"
8399 "void main(){\n"
8400 " color = vec4(1);\n"
8401 "}\n";
8402
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008403 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8404 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12008405
8406 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008407 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12008408 pipe.AddShader(&vs);
8409 pipe.AddShader(&fs);
8410
Chris Forbes9f7ff632015-05-25 11:13:08 +12008411 VkDescriptorSetObj descriptorSet(m_device);
8412 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008413 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12008414
Tony Barbour5781e8f2015-08-04 16:23:11 -06008415 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12008416
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008417 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +12008418}
Chris Forbes9f7ff632015-05-25 11:13:08 +12008419
Karl Schultz6addd812016-02-02 17:17:23 -07008420TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008422 "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008423
Chris Forbes59cb88d2015-05-25 11:13:13 +12008424 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008425 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12008426
8427 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008428 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12008429 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07008430 "out gl_PerVertex {\n"
8431 " vec4 gl_Position;\n"
8432 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12008433 "void main(){\n"
8434 " gl_Position = vec4(1);\n"
8435 "}\n";
8436 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008437 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12008438 "\n"
8439 "layout(location=0) in float x;\n"
8440 "layout(location=0) out vec4 color;\n"
8441 "void main(){\n"
8442 " color = vec4(x);\n"
8443 "}\n";
8444
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008445 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8446 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12008447
8448 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008449 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12008450 pipe.AddShader(&vs);
8451 pipe.AddShader(&fs);
8452
Chris Forbes59cb88d2015-05-25 11:13:13 +12008453 VkDescriptorSetObj descriptorSet(m_device);
8454 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008455 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12008456
Tony Barbour5781e8f2015-08-04 16:23:11 -06008457 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12008458
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008459 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +12008460}
8461
Karl Schultz6addd812016-02-02 17:17:23 -07008462TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13008463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008464 "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +13008465
8466 ASSERT_NO_FATAL_FAILURE(InitState());
8467 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8468
8469 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008470 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008471 "\n"
8472 "out gl_PerVertex {\n"
8473 " vec4 gl_Position;\n"
8474 "};\n"
8475 "void main(){\n"
8476 " gl_Position = vec4(1);\n"
8477 "}\n";
8478 char const *fsSource =
8479 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008480 "\n"
8481 "in block { layout(location=0) float x; } ins;\n"
8482 "layout(location=0) out vec4 color;\n"
8483 "void main(){\n"
8484 " color = vec4(ins.x);\n"
8485 "}\n";
8486
8487 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8488 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8489
8490 VkPipelineObj pipe(m_device);
8491 pipe.AddColorAttachment();
8492 pipe.AddShader(&vs);
8493 pipe.AddShader(&fs);
8494
8495 VkDescriptorSetObj descriptorSet(m_device);
8496 descriptorSet.AppendDummy();
8497 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8498
8499 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8500
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008501 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13008502}
8503
Karl Schultz6addd812016-02-02 17:17:23 -07008504TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes0036fd12016-01-26 14:19:49 +13008505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbese9928822016-02-17 14:44:52 +13008506 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz6addd812016-02-02 17:17:23 -07008507 "output arr[2] of float32' vs 'ptr to "
8508 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +13008509
8510 ASSERT_NO_FATAL_FAILURE(InitState());
8511 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8512
8513 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008514 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13008515 "\n"
8516 "layout(location=0) out float x[2];\n"
8517 "out gl_PerVertex {\n"
8518 " vec4 gl_Position;\n"
8519 "};\n"
8520 "void main(){\n"
8521 " x[0] = 0; x[1] = 0;\n"
8522 " gl_Position = vec4(1);\n"
8523 "}\n";
8524 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008525 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13008526 "\n"
8527 "layout(location=0) in float x[3];\n"
8528 "layout(location=0) out vec4 color;\n"
8529 "void main(){\n"
8530 " color = vec4(x[0] + x[1] + x[2]);\n"
8531 "}\n";
8532
8533 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8534 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8535
8536 VkPipelineObj pipe(m_device);
8537 pipe.AddColorAttachment();
8538 pipe.AddShader(&vs);
8539 pipe.AddShader(&fs);
8540
8541 VkDescriptorSetObj descriptorSet(m_device);
8542 descriptorSet.AppendDummy();
8543 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8544
8545 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8546
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008547 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +13008548}
8549
Karl Schultz6addd812016-02-02 17:17:23 -07008550TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008552 "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008553
Chris Forbesb56af562015-05-25 11:13:17 +12008554 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008555 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12008556
8557 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008558 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12008559 "\n"
8560 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07008561 "out gl_PerVertex {\n"
8562 " vec4 gl_Position;\n"
8563 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12008564 "void main(){\n"
8565 " x = 0;\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 Forbesb56af562015-05-25 11:13:17 +12008570 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008571 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbesb56af562015-05-25 11:13:17 +12008572 "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 Forbesb56af562015-05-25 11:13:17 +12008579
8580 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008581 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12008582 pipe.AddShader(&vs);
8583 pipe.AddShader(&fs);
8584
Chris Forbesb56af562015-05-25 11:13:17 +12008585 VkDescriptorSetObj descriptorSet(m_device);
8586 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008587 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12008588
Tony Barbour5781e8f2015-08-04 16:23:11 -06008589 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12008590
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008591 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +12008592}
8593
Karl Schultz6addd812016-02-02 17:17:23 -07008594TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
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 "Type mismatch on location 0");
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 =
8602 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008603 "\n"
8604 "out block { layout(location=0) int x; } outs;\n"
8605 "out gl_PerVertex {\n"
8606 " vec4 gl_Position;\n"
8607 "};\n"
8608 "void main(){\n"
8609 " outs.x = 0;\n"
8610 " gl_Position = vec4(1);\n"
8611 "}\n";
8612 char const *fsSource =
8613 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008614 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008615 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbesa3e85f62016-01-15 14:53:11 +13008616 "layout(location=0) out vec4 color;\n"
8617 "void main(){\n"
8618 " color = vec4(ins.x);\n"
8619 "}\n";
8620
8621 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8622 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8623
8624 VkPipelineObj pipe(m_device);
8625 pipe.AddColorAttachment();
8626 pipe.AddShader(&vs);
8627 pipe.AddShader(&fs);
8628
8629 VkDescriptorSetObj descriptorSet(m_device);
8630 descriptorSet.AppendDummy();
8631 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8632
8633 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8634
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008635 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13008636}
8637
8638TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
8639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8640 "location 0.0 which is not written by vertex shader");
8641
8642 ASSERT_NO_FATAL_FAILURE(InitState());
8643 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8644
8645 char const *vsSource =
8646 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008647 "\n"
8648 "out block { layout(location=1) float x; } outs;\n"
8649 "out gl_PerVertex {\n"
8650 " vec4 gl_Position;\n"
8651 "};\n"
8652 "void main(){\n"
8653 " outs.x = 0;\n"
8654 " gl_Position = vec4(1);\n"
8655 "}\n";
8656 char const *fsSource =
8657 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008658 "\n"
8659 "in block { layout(location=0) float x; } ins;\n"
8660 "layout(location=0) out vec4 color;\n"
8661 "void main(){\n"
8662 " color = vec4(ins.x);\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 Forbese9928822016-02-17 14:44:52 +13008680}
8681
8682TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
8683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8684 "location 0.1 which is not written by vertex shader");
8685
8686 ASSERT_NO_FATAL_FAILURE(InitState());
8687 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8688
8689 char const *vsSource =
8690 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008691 "\n"
8692 "out block { layout(location=0, component=0) float x; } outs;\n"
8693 "out gl_PerVertex {\n"
8694 " vec4 gl_Position;\n"
8695 "};\n"
8696 "void main(){\n"
8697 " outs.x = 0;\n"
8698 " gl_Position = vec4(1);\n"
8699 "}\n";
8700 char const *fsSource =
8701 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008702 "\n"
8703 "in block { layout(location=0, component=1) float x; } ins;\n"
8704 "layout(location=0) out vec4 color;\n"
8705 "void main(){\n"
8706 " color = vec4(ins.x);\n"
8707 "}\n";
8708
8709 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8710 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8711
8712 VkPipelineObj pipe(m_device);
8713 pipe.AddColorAttachment();
8714 pipe.AddShader(&vs);
8715 pipe.AddShader(&fs);
8716
8717 VkDescriptorSetObj descriptorSet(m_device);
8718 descriptorSet.AppendDummy();
8719 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8720
8721 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8722
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008723 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13008724}
8725
Karl Schultz6addd812016-02-02 17:17:23 -07008726TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008728 "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008729
Chris Forbesde136e02015-05-25 11:13:28 +12008730 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12008732
8733 VkVertexInputBindingDescription input_binding;
8734 memset(&input_binding, 0, sizeof(input_binding));
8735
8736 VkVertexInputAttributeDescription input_attrib;
8737 memset(&input_attrib, 0, sizeof(input_attrib));
8738 input_attrib.format = VK_FORMAT_R32_SFLOAT;
8739
8740 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008741 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12008742 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07008743 "out gl_PerVertex {\n"
8744 " vec4 gl_Position;\n"
8745 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +12008746 "void main(){\n"
8747 " gl_Position = vec4(1);\n"
8748 "}\n";
8749 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008750 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12008751 "\n"
8752 "layout(location=0) out vec4 color;\n"
8753 "void main(){\n"
8754 " color = vec4(1);\n"
8755 "}\n";
8756
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008757 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8758 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12008759
8760 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008761 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12008762 pipe.AddShader(&vs);
8763 pipe.AddShader(&fs);
8764
8765 pipe.AddVertexInputBindings(&input_binding, 1);
8766 pipe.AddVertexInputAttribs(&input_attrib, 1);
8767
Chris Forbesde136e02015-05-25 11:13:28 +12008768 VkDescriptorSetObj descriptorSet(m_device);
8769 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008770 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12008771
Tony Barbour5781e8f2015-08-04 16:23:11 -06008772 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12008773
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008774 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +12008775}
8776
Karl Schultz6addd812016-02-02 17:17:23 -07008777TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008779 "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +13008780
8781 ASSERT_NO_FATAL_FAILURE(InitState());
8782 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8783
8784 VkVertexInputBindingDescription input_binding;
8785 memset(&input_binding, 0, sizeof(input_binding));
8786
8787 VkVertexInputAttributeDescription input_attrib;
8788 memset(&input_attrib, 0, sizeof(input_attrib));
8789 input_attrib.format = VK_FORMAT_R32_SFLOAT;
8790
8791 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008792 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13008793 "\n"
8794 "layout(location=1) in float x;\n"
8795 "out gl_PerVertex {\n"
8796 " vec4 gl_Position;\n"
8797 "};\n"
8798 "void main(){\n"
8799 " gl_Position = vec4(x);\n"
8800 "}\n";
8801 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008802 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13008803 "\n"
8804 "layout(location=0) out vec4 color;\n"
8805 "void main(){\n"
8806 " color = vec4(1);\n"
8807 "}\n";
8808
8809 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8810 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8811
8812 VkPipelineObj pipe(m_device);
8813 pipe.AddColorAttachment();
8814 pipe.AddShader(&vs);
8815 pipe.AddShader(&fs);
8816
8817 pipe.AddVertexInputBindings(&input_binding, 1);
8818 pipe.AddVertexInputAttribs(&input_attrib, 1);
8819
8820 VkDescriptorSetObj descriptorSet(m_device);
8821 descriptorSet.AppendDummy();
8822 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8823
8824 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8825
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008826 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +13008827}
8828
Karl Schultz6addd812016-02-02 17:17:23 -07008829TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
8830 m_errorMonitor->SetDesiredFailureMsg(
8831 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008832 "VS consumes input at location 0 but not provided");
8833
Chris Forbes62e8e502015-05-25 11:13:29 +12008834 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008835 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12008836
8837 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008838 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12008839 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008840 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -07008841 "out gl_PerVertex {\n"
8842 " vec4 gl_Position;\n"
8843 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12008844 "void main(){\n"
8845 " gl_Position = x;\n"
8846 "}\n";
8847 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008848 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12008849 "\n"
8850 "layout(location=0) out vec4 color;\n"
8851 "void main(){\n"
8852 " color = vec4(1);\n"
8853 "}\n";
8854
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008855 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8856 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12008857
8858 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008859 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12008860 pipe.AddShader(&vs);
8861 pipe.AddShader(&fs);
8862
Chris Forbes62e8e502015-05-25 11:13:29 +12008863 VkDescriptorSetObj descriptorSet(m_device);
8864 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008865 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12008866
Tony Barbour5781e8f2015-08-04 16:23:11 -06008867 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12008868
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008869 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +12008870}
8871
Karl Schultz6addd812016-02-02 17:17:23 -07008872TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
8873 m_errorMonitor->SetDesiredFailureMsg(
8874 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008875 "location 0 does not match VS input type");
8876
Chris Forbesc97d98e2015-05-25 11:13:31 +12008877 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008878 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12008879
8880 VkVertexInputBindingDescription input_binding;
8881 memset(&input_binding, 0, sizeof(input_binding));
8882
8883 VkVertexInputAttributeDescription input_attrib;
8884 memset(&input_attrib, 0, sizeof(input_attrib));
8885 input_attrib.format = VK_FORMAT_R32_SFLOAT;
8886
8887 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008888 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12008889 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008890 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07008891 "out gl_PerVertex {\n"
8892 " vec4 gl_Position;\n"
8893 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12008894 "void main(){\n"
8895 " gl_Position = vec4(x);\n"
8896 "}\n";
8897 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008898 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12008899 "\n"
8900 "layout(location=0) out vec4 color;\n"
8901 "void main(){\n"
8902 " color = vec4(1);\n"
8903 "}\n";
8904
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008905 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8906 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12008907
8908 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008909 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12008910 pipe.AddShader(&vs);
8911 pipe.AddShader(&fs);
8912
8913 pipe.AddVertexInputBindings(&input_binding, 1);
8914 pipe.AddVertexInputAttribs(&input_attrib, 1);
8915
Chris Forbesc97d98e2015-05-25 11:13:31 +12008916 VkDescriptorSetObj descriptorSet(m_device);
8917 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008918 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12008919
Tony Barbour5781e8f2015-08-04 16:23:11 -06008920 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12008921
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008922 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +12008923}
8924
Chris Forbesc68b43c2016-04-06 11:18:47 +12008925TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
8926 m_errorMonitor->SetDesiredFailureMsg(
8927 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8928 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
8929
8930 ASSERT_NO_FATAL_FAILURE(InitState());
8931 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8932
8933 char const *vsSource =
8934 "#version 450\n"
8935 "\n"
8936 "out gl_PerVertex {\n"
8937 " vec4 gl_Position;\n"
8938 "};\n"
8939 "void main(){\n"
8940 " gl_Position = vec4(1);\n"
8941 "}\n";
8942 char const *fsSource =
8943 "#version 450\n"
8944 "\n"
8945 "layout(location=0) out vec4 color;\n"
8946 "void main(){\n"
8947 " color = vec4(1);\n"
8948 "}\n";
8949
8950 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8951 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8952
8953 VkPipelineObj pipe(m_device);
8954 pipe.AddColorAttachment();
8955 pipe.AddShader(&vs);
8956 pipe.AddShader(&vs);
8957 pipe.AddShader(&fs);
8958
8959 VkDescriptorSetObj descriptorSet(m_device);
8960 descriptorSet.AppendDummy();
8961 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8962
8963 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8964
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008965 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +12008966}
8967
Karl Schultz6addd812016-02-02 17:17:23 -07008968TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008969 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13008970
8971 ASSERT_NO_FATAL_FAILURE(InitState());
8972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8973
8974 VkVertexInputBindingDescription input_binding;
8975 memset(&input_binding, 0, sizeof(input_binding));
8976
8977 VkVertexInputAttributeDescription input_attribs[2];
8978 memset(input_attribs, 0, sizeof(input_attribs));
8979
8980 for (int i = 0; i < 2; i++) {
8981 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
8982 input_attribs[i].location = i;
8983 }
8984
8985 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008986 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13008987 "\n"
8988 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07008989 "out gl_PerVertex {\n"
8990 " vec4 gl_Position;\n"
8991 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13008992 "void main(){\n"
8993 " gl_Position = x[0] + x[1];\n"
8994 "}\n";
8995 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008996 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13008997 "\n"
8998 "layout(location=0) out vec4 color;\n"
8999 "void main(){\n"
9000 " color = vec4(1);\n"
9001 "}\n";
9002
9003 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9004 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9005
9006 VkPipelineObj pipe(m_device);
9007 pipe.AddColorAttachment();
9008 pipe.AddShader(&vs);
9009 pipe.AddShader(&fs);
9010
9011 pipe.AddVertexInputBindings(&input_binding, 1);
9012 pipe.AddVertexInputAttribs(input_attribs, 2);
9013
9014 VkDescriptorSetObj descriptorSet(m_device);
9015 descriptorSet.AppendDummy();
9016 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9017
9018 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9019
9020 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009021 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +13009022}
9023
Chris Forbes2682b242015-11-24 11:13:14 +13009024TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
9025{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009026 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13009027
9028 ASSERT_NO_FATAL_FAILURE(InitState());
9029 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9030
9031 VkVertexInputBindingDescription input_binding;
9032 memset(&input_binding, 0, sizeof(input_binding));
9033
9034 VkVertexInputAttributeDescription input_attribs[2];
9035 memset(input_attribs, 0, sizeof(input_attribs));
9036
9037 for (int i = 0; i < 2; i++) {
9038 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
9039 input_attribs[i].location = i;
9040 }
9041
9042 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009043 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009044 "\n"
9045 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -07009046 "out gl_PerVertex {\n"
9047 " vec4 gl_Position;\n"
9048 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009049 "void main(){\n"
9050 " gl_Position = x[0] + x[1];\n"
9051 "}\n";
9052 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009053 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009054 "\n"
9055 "layout(location=0) out vec4 color;\n"
9056 "void main(){\n"
9057 " color = vec4(1);\n"
9058 "}\n";
9059
9060 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9061 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9062
9063 VkPipelineObj pipe(m_device);
9064 pipe.AddColorAttachment();
9065 pipe.AddShader(&vs);
9066 pipe.AddShader(&fs);
9067
9068 pipe.AddVertexInputBindings(&input_binding, 1);
9069 pipe.AddVertexInputAttribs(input_attribs, 2);
9070
9071 VkDescriptorSetObj descriptorSet(m_device);
9072 descriptorSet.AppendDummy();
9073 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9074
9075 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9076
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009077 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +13009078}
Chris Forbes2682b242015-11-24 11:13:14 +13009079
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009080TEST_F(VkLayerTest, CreatePipelineSimplePositive)
9081{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009082 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009083
9084 ASSERT_NO_FATAL_FAILURE(InitState());
9085 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9086
9087 char const *vsSource =
9088 "#version 450\n"
9089 "out gl_PerVertex {\n"
9090 " vec4 gl_Position;\n"
9091 "};\n"
9092 "void main(){\n"
9093 " gl_Position = vec4(0);\n"
9094 "}\n";
9095 char const *fsSource =
9096 "#version 450\n"
9097 "\n"
9098 "layout(location=0) out vec4 color;\n"
9099 "void main(){\n"
9100 " color = vec4(1);\n"
9101 "}\n";
9102
9103 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9104 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9105
9106 VkPipelineObj pipe(m_device);
9107 pipe.AddColorAttachment();
9108 pipe.AddShader(&vs);
9109 pipe.AddShader(&fs);
9110
9111 VkDescriptorSetObj descriptorSet(m_device);
9112 descriptorSet.AppendDummy();
9113 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9114
9115 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9116
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009117 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009118}
9119
Chris Forbes912c9192016-04-05 17:50:35 +12009120TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch)
9121{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009122 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +12009123
9124 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
9125
9126 ASSERT_NO_FATAL_FAILURE(InitState());
9127 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9128
9129 char const *vsSource =
9130 "#version 450\n"
9131 "out gl_PerVertex {\n"
9132 " vec4 gl_Position;\n"
9133 "};\n"
9134 "layout(location=0) out vec3 x;\n"
9135 "layout(location=1) out ivec3 y;\n"
9136 "layout(location=2) out vec3 z;\n"
9137 "void main(){\n"
9138 " gl_Position = vec4(0);\n"
9139 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
9140 "}\n";
9141 char const *fsSource =
9142 "#version 450\n"
9143 "\n"
9144 "layout(location=0) out vec4 color;\n"
9145 "layout(location=0) in float x;\n"
9146 "layout(location=1) flat in int y;\n"
9147 "layout(location=2) in vec2 z;\n"
9148 "void main(){\n"
9149 " color = vec4(1 + x + y + z.x);\n"
9150 "}\n";
9151
9152 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9153 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9154
9155 VkPipelineObj pipe(m_device);
9156 pipe.AddColorAttachment();
9157 pipe.AddShader(&vs);
9158 pipe.AddShader(&fs);
9159
9160 VkDescriptorSetObj descriptorSet(m_device);
9161 descriptorSet.AppendDummy();
9162 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9163
9164 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9165
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009166 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +12009167}
9168
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009169TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
9170{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009171 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009172
9173 ASSERT_NO_FATAL_FAILURE(InitState());
9174 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9175
Chris Forbesc1e852d2016-04-04 19:26:42 +12009176 if (!m_device->phy().features().tessellationShader) {
9177 printf("Device does not support tessellation shaders; skipped.\n");
9178 return;
9179 }
9180
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009181 char const *vsSource =
9182 "#version 450\n"
9183 "void main(){}\n";
9184 char const *tcsSource =
9185 "#version 450\n"
9186 "layout(location=0) out int x[];\n"
9187 "layout(vertices=3) out;\n"
9188 "void main(){\n"
9189 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
9190 " gl_TessLevelInner[0] = 1;\n"
9191 " x[gl_InvocationID] = gl_InvocationID;\n"
9192 "}\n";
9193 char const *tesSource =
9194 "#version 450\n"
9195 "layout(triangles, equal_spacing, cw) in;\n"
9196 "layout(location=0) in int x[];\n"
9197 "out gl_PerVertex { vec4 gl_Position; };\n"
9198 "void main(){\n"
9199 " gl_Position.xyz = gl_TessCoord;\n"
9200 " gl_Position.w = x[0] + x[1] + x[2];\n"
9201 "}\n";
9202 char const *fsSource =
9203 "#version 450\n"
9204 "layout(location=0) out vec4 color;\n"
9205 "void main(){\n"
9206 " color = vec4(1);\n"
9207 "}\n";
9208
9209 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9210 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
9211 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
9212 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9213
9214 VkPipelineInputAssemblyStateCreateInfo iasci{
9215 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
9216 nullptr,
9217 0,
9218 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
9219 VK_FALSE};
9220
Chris Forbesb4cacb62016-04-04 19:15:00 +12009221 VkPipelineTessellationStateCreateInfo tsci{
9222 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
9223 nullptr,
9224 0,
9225 3};
9226
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009227 VkPipelineObj pipe(m_device);
9228 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +12009229 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009230 pipe.AddColorAttachment();
9231 pipe.AddShader(&vs);
9232 pipe.AddShader(&tcs);
9233 pipe.AddShader(&tes);
9234 pipe.AddShader(&fs);
9235
9236 VkDescriptorSetObj descriptorSet(m_device);
9237 descriptorSet.AppendDummy();
9238 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9239
9240 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9241
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009242 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009243}
9244
Chris Forbesa0ab8152016-04-20 13:34:27 +12009245TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive)
9246{
9247 m_errorMonitor->ExpectSuccess();
9248
9249 ASSERT_NO_FATAL_FAILURE(InitState());
9250 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9251
9252 if (!m_device->phy().features().geometryShader) {
9253 printf("Device does not support geometry shaders; skipped.\n");
9254 return;
9255 }
9256
9257 char const *vsSource =
9258 "#version 450\n"
9259 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
9260 "void main(){\n"
9261 " vs_out.x = vec4(1);\n"
9262 "}\n";
9263 char const *gsSource =
9264 "#version 450\n"
9265 "layout(triangles) in;\n"
9266 "layout(triangle_strip, max_vertices=3) out;\n"
9267 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
9268 "out gl_PerVertex { vec4 gl_Position; };\n"
9269 "void main() {\n"
9270 " gl_Position = gs_in[0].x;\n"
9271 " EmitVertex();\n"
9272 "}\n";
9273 char const *fsSource =
9274 "#version 450\n"
9275 "layout(location=0) out vec4 color;\n"
9276 "void main(){\n"
9277 " color = vec4(1);\n"
9278 "}\n";
9279
9280 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9281 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
9282 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9283
9284 VkPipelineObj pipe(m_device);
9285 pipe.AddColorAttachment();
9286 pipe.AddShader(&vs);
9287 pipe.AddShader(&gs);
9288 pipe.AddShader(&fs);
9289
9290 VkDescriptorSetObj descriptorSet(m_device);
9291 descriptorSet.AppendDummy();
9292 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9293
9294 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9295
9296 m_errorMonitor->VerifyNotFound();
9297}
9298
Chris Forbesa0193bc2016-04-04 19:19:47 +12009299TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
9300{
9301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9302 "is per-vertex in tessellation control shader stage "
9303 "but per-patch in tessellation evaluation shader stage");
9304
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 Forbesa0193bc2016-04-04 19:19:47 +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) patch 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;\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
9353 VkPipelineTessellationStateCreateInfo tsci{
9354 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
9355 nullptr,
9356 0,
9357 3};
9358
9359 VkPipelineObj pipe(m_device);
9360 pipe.SetInputAssembly(&iasci);
9361 pipe.SetTessellation(&tsci);
9362 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->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +12009375}
9376
Karl Schultz6addd812016-02-02 17:17:23 -07009377TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
9378 m_errorMonitor->SetDesiredFailureMsg(
9379 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009380 "Duplicate vertex input binding descriptions for binding 0");
9381
Chris Forbes280ba2c2015-06-12 11:16:41 +12009382 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009383 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12009384
9385 /* Two binding descriptions for binding 0 */
9386 VkVertexInputBindingDescription input_bindings[2];
9387 memset(input_bindings, 0, sizeof(input_bindings));
9388
9389 VkVertexInputAttributeDescription input_attrib;
9390 memset(&input_attrib, 0, sizeof(input_attrib));
9391 input_attrib.format = VK_FORMAT_R32_SFLOAT;
9392
9393 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009394 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12009395 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009396 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07009397 "out gl_PerVertex {\n"
9398 " vec4 gl_Position;\n"
9399 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12009400 "void main(){\n"
9401 " gl_Position = vec4(x);\n"
9402 "}\n";
9403 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009404 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12009405 "\n"
9406 "layout(location=0) out vec4 color;\n"
9407 "void main(){\n"
9408 " color = vec4(1);\n"
9409 "}\n";
9410
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009411 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9412 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +12009413
9414 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009415 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12009416 pipe.AddShader(&vs);
9417 pipe.AddShader(&fs);
9418
9419 pipe.AddVertexInputBindings(input_bindings, 2);
9420 pipe.AddVertexInputAttribs(&input_attrib, 1);
9421
Chris Forbes280ba2c2015-06-12 11:16:41 +12009422 VkDescriptorSetObj descriptorSet(m_device);
9423 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009424 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12009425
Tony Barbour5781e8f2015-08-04 16:23:11 -06009426 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12009427
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009428 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +12009429}
Chris Forbes8f68b562015-05-25 11:13:32 +12009430
Chris Forbes35efec72016-04-21 14:32:08 +12009431TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
9432 m_errorMonitor->ExpectSuccess();
9433
9434 ASSERT_NO_FATAL_FAILURE(InitState());
9435 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9436
9437 if (!m_device->phy().features().tessellationShader) {
9438 printf("Device does not support 64bit vertex attributes; skipped.\n");
9439 return;
9440 }
9441
9442 VkVertexInputBindingDescription input_bindings[1];
9443 memset(input_bindings, 0, sizeof(input_bindings));
9444
9445 VkVertexInputAttributeDescription input_attribs[4];
9446 memset(input_attribs, 0, sizeof(input_attribs));
9447 input_attribs[0].location = 0;
9448 input_attribs[0].offset = 0;
9449 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9450 input_attribs[1].location = 2;
9451 input_attribs[1].offset = 32;
9452 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9453 input_attribs[2].location = 4;
9454 input_attribs[2].offset = 64;
9455 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9456 input_attribs[3].location = 6;
9457 input_attribs[3].offset = 96;
9458 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9459
9460 char const *vsSource =
9461 "#version 450\n"
9462 "\n"
9463 "layout(location=0) in dmat4 x;\n"
9464 "out gl_PerVertex {\n"
9465 " vec4 gl_Position;\n"
9466 "};\n"
9467 "void main(){\n"
9468 " gl_Position = vec4(x[0][0]);\n"
9469 "}\n";
9470 char const *fsSource =
9471 "#version 450\n"
9472 "\n"
9473 "layout(location=0) out vec4 color;\n"
9474 "void main(){\n"
9475 " color = vec4(1);\n"
9476 "}\n";
9477
9478 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9479 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9480
9481 VkPipelineObj pipe(m_device);
9482 pipe.AddColorAttachment();
9483 pipe.AddShader(&vs);
9484 pipe.AddShader(&fs);
9485
9486 pipe.AddVertexInputBindings(input_bindings, 1);
9487 pipe.AddVertexInputAttribs(input_attribs, 4);
9488
9489 VkDescriptorSetObj descriptorSet(m_device);
9490 descriptorSet.AppendDummy();
9491 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9492
9493 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9494
9495 m_errorMonitor->VerifyNotFound();
9496}
9497
Karl Schultz6addd812016-02-02 17:17:23 -07009498TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009500 "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009501
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009502 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009503
9504 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009505 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009506 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009507 "out gl_PerVertex {\n"
9508 " vec4 gl_Position;\n"
9509 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009510 "void main(){\n"
9511 " gl_Position = vec4(1);\n"
9512 "}\n";
9513 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009514 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009515 "\n"
9516 "void main(){\n"
9517 "}\n";
9518
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009519 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9520 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009521
9522 VkPipelineObj pipe(m_device);
9523 pipe.AddShader(&vs);
9524 pipe.AddShader(&fs);
9525
Chia-I Wu08accc62015-07-07 11:50:03 +08009526 /* set up CB 0, not written */
9527 pipe.AddColorAttachment();
9528 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009529
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009530 VkDescriptorSetObj descriptorSet(m_device);
9531 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009532 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009533
Tony Barbour5781e8f2015-08-04 16:23:11 -06009534 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009535
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009536 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009537}
9538
Karl Schultz6addd812016-02-02 17:17:23 -07009539TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Karl Schultz6addd812016-02-02 17:17:23 -07009540 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009541 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009542 "FS writes to output location 1 with no matching attachment");
9543
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009544 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009545
9546 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009547 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009548 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009549 "out gl_PerVertex {\n"
9550 " vec4 gl_Position;\n"
9551 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009552 "void main(){\n"
9553 " gl_Position = vec4(1);\n"
9554 "}\n";
9555 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009556 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009557 "\n"
9558 "layout(location=0) out vec4 x;\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009559 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009560 "void main(){\n"
9561 " x = vec4(1);\n"
9562 " y = vec4(1);\n"
9563 "}\n";
9564
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009565 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9566 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009567
9568 VkPipelineObj pipe(m_device);
9569 pipe.AddShader(&vs);
9570 pipe.AddShader(&fs);
9571
Chia-I Wu08accc62015-07-07 11:50:03 +08009572 /* set up CB 0, not written */
9573 pipe.AddColorAttachment();
9574 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009575 /* FS writes CB 1, but we don't configure it */
9576
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009577 VkDescriptorSetObj descriptorSet(m_device);
9578 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009579 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009580
Tony Barbour5781e8f2015-08-04 16:23:11 -06009581 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009582
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009583 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009584}
9585
Karl Schultz6addd812016-02-02 17:17:23 -07009586TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009588 "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009589
Chris Forbesa36d69e2015-05-25 11:13:44 +12009590 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12009591
9592 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009593 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12009594 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009595 "out gl_PerVertex {\n"
9596 " vec4 gl_Position;\n"
9597 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12009598 "void main(){\n"
9599 " gl_Position = vec4(1);\n"
9600 "}\n";
9601 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009602 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12009603 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009604 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbesa36d69e2015-05-25 11:13:44 +12009605 "void main(){\n"
9606 " x = ivec4(1);\n"
9607 "}\n";
9608
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009609 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9610 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +12009611
9612 VkPipelineObj pipe(m_device);
9613 pipe.AddShader(&vs);
9614 pipe.AddShader(&fs);
9615
Chia-I Wu08accc62015-07-07 11:50:03 +08009616 /* set up CB 0; type is UNORM by default */
9617 pipe.AddColorAttachment();
9618 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12009619
Chris Forbesa36d69e2015-05-25 11:13:44 +12009620 VkDescriptorSetObj descriptorSet(m_device);
9621 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009622 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12009623
Tony Barbour5781e8f2015-08-04 16:23:11 -06009624 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12009625
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009626 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +12009627}
Chris Forbes7b1b8932015-06-05 14:43:36 +12009628
Karl Schultz6addd812016-02-02 17:17:23 -07009629TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009631 "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009632
Chris Forbes556c76c2015-08-14 12:04:59 +12009633 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12009634
9635 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009636 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12009637 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009638 "out gl_PerVertex {\n"
9639 " vec4 gl_Position;\n"
9640 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12009641 "void main(){\n"
9642 " gl_Position = vec4(1);\n"
9643 "}\n";
9644 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009645 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12009646 "\n"
9647 "layout(location=0) out vec4 x;\n"
9648 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
9649 "void main(){\n"
9650 " x = vec4(bar.y);\n"
9651 "}\n";
9652
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009653 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9654 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +12009655
Chris Forbes556c76c2015-08-14 12:04:59 +12009656 VkPipelineObj pipe(m_device);
9657 pipe.AddShader(&vs);
9658 pipe.AddShader(&fs);
9659
9660 /* set up CB 0; type is UNORM by default */
9661 pipe.AddColorAttachment();
9662 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9663
9664 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009665 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +12009666
9667 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9668
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009669 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +12009670}
9671
Chris Forbes5c59e902016-02-26 16:56:09 +13009672TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
9673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9674 "not declared in layout");
9675
9676 ASSERT_NO_FATAL_FAILURE(InitState());
9677
9678 char const *vsSource =
9679 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +13009680 "\n"
9681 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
9682 "out gl_PerVertex {\n"
9683 " vec4 gl_Position;\n"
9684 "};\n"
9685 "void main(){\n"
9686 " gl_Position = vec4(consts.x);\n"
9687 "}\n";
9688 char const *fsSource =
9689 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +13009690 "\n"
9691 "layout(location=0) out vec4 x;\n"
9692 "void main(){\n"
9693 " x = vec4(1);\n"
9694 "}\n";
9695
9696 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9697 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9698
9699 VkPipelineObj pipe(m_device);
9700 pipe.AddShader(&vs);
9701 pipe.AddShader(&fs);
9702
9703 /* set up CB 0; type is UNORM by default */
9704 pipe.AddColorAttachment();
9705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9706
9707 VkDescriptorSetObj descriptorSet(m_device);
9708 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9709
9710 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9711
9712 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009713 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +13009714}
9715
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009716#endif // SHADER_CHECKER_TESTS
9717
9718#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -06009719TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Karl Schultz6addd812016-02-02 17:17:23 -07009720 m_errorMonitor->SetDesiredFailureMsg(
9721 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009722 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009723
9724 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009725
9726 // Create an image
9727 VkImage image;
9728
Karl Schultz6addd812016-02-02 17:17:23 -07009729 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9730 const int32_t tex_width = 32;
9731 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009732
9733 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009734 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9735 image_create_info.pNext = NULL;
9736 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9737 image_create_info.format = tex_format;
9738 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009739 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -07009740 image_create_info.extent.depth = 1;
9741 image_create_info.mipLevels = 1;
9742 image_create_info.arrayLayers = 1;
9743 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9744 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9745 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9746 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009747
9748 // Introduce error by sending down a bogus width extent
9749 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009750 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009751
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009752 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009753}
9754
Mark Youngc48c4c12016-04-11 14:26:49 -06009755TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
9756 m_errorMonitor->SetDesiredFailureMsg(
9757 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9758 "CreateImage extents is 0 for at least one required dimension");
9759
9760 ASSERT_NO_FATAL_FAILURE(InitState());
9761
9762 // Create an image
9763 VkImage image;
9764
9765 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9766 const int32_t tex_width = 32;
9767 const int32_t tex_height = 32;
9768
9769 VkImageCreateInfo image_create_info = {};
9770 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9771 image_create_info.pNext = NULL;
9772 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9773 image_create_info.format = tex_format;
9774 image_create_info.extent.width = tex_width;
9775 image_create_info.extent.height = tex_height;
9776 image_create_info.extent.depth = 1;
9777 image_create_info.mipLevels = 1;
9778 image_create_info.arrayLayers = 1;
9779 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9780 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9781 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9782 image_create_info.flags = 0;
9783
9784 // Introduce error by sending down a bogus width extent
9785 image_create_info.extent.width = 0;
9786 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
9787
9788 m_errorMonitor->VerifyFound();
9789}
9790
Karl Schultz6addd812016-02-02 17:17:23 -07009791TEST_F(VkLayerTest, UpdateBufferAlignment) {
9792 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mike Stroyana3082432015-09-25 13:39:21 -06009793
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009795 "dstOffset, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009796
Mike Stroyana3082432015-09-25 13:39:21 -06009797 ASSERT_NO_FATAL_FAILURE(InitState());
9798
9799 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9800 vk_testing::Buffer buffer;
9801 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
9802
9803 BeginCommandBuffer();
9804 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009805 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009806 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009807
Mike Stroyana3082432015-09-25 13:39:21 -06009808 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009810 "dataSize, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009811
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009812 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009813 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06009814 EndCommandBuffer();
9815}
9816
Karl Schultz6addd812016-02-02 17:17:23 -07009817TEST_F(VkLayerTest, FillBufferAlignment) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009819 "dstOffset, is not a multiple of 4");
Mike Stroyana3082432015-09-25 13:39:21 -06009820
9821 ASSERT_NO_FATAL_FAILURE(InitState());
9822
9823 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9824 vk_testing::Buffer buffer;
9825 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
9826
9827 BeginCommandBuffer();
9828 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009829 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009830 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009831
Mike Stroyana3082432015-09-25 13:39:21 -06009832 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009834 "size, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009835
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009836 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009837
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009838 m_errorMonitor->VerifyFound();
9839
Mike Stroyana3082432015-09-25 13:39:21 -06009840 EndCommandBuffer();
9841}
9842
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009843#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +12009844
Tobin Ehliscde08892015-09-22 10:11:37 -06009845#if IMAGE_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07009846TEST_F(VkLayerTest, InvalidImageView) {
9847 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -06009848
Karl Schultz6addd812016-02-02 17:17:23 -07009849 m_errorMonitor->SetDesiredFailureMsg(
9850 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009851 "vkCreateImageView called with baseMipLevel 10 ");
9852
Tobin Ehliscde08892015-09-22 10:11:37 -06009853 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -06009854
Mike Stroyana3082432015-09-25 13:39:21 -06009855 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -07009856 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -06009857
Karl Schultz6addd812016-02-02 17:17:23 -07009858 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9859 const int32_t tex_width = 32;
9860 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -06009861
9862 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009863 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9864 image_create_info.pNext = NULL;
9865 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9866 image_create_info.format = tex_format;
9867 image_create_info.extent.width = tex_width;
9868 image_create_info.extent.height = tex_height;
9869 image_create_info.extent.depth = 1;
9870 image_create_info.mipLevels = 1;
9871 image_create_info.arrayLayers = 1;
9872 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9873 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9874 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9875 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -06009876
Chia-I Wuf7458c52015-10-26 21:10:41 +08009877 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -06009878 ASSERT_VK_SUCCESS(err);
9879
9880 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009881 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9882 image_view_create_info.image = image;
9883 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
9884 image_view_create_info.format = tex_format;
9885 image_view_create_info.subresourceRange.layerCount = 1;
9886 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
9887 image_view_create_info.subresourceRange.levelCount = 1;
9888 image_view_create_info.subresourceRange.aspectMask =
9889 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06009890
9891 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07009892 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
9893 &view);
Tobin Ehliscde08892015-09-22 10:11:37 -06009894
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009895 m_errorMonitor->VerifyFound();
Tobin Ehliscde08892015-09-22 10:11:37 -06009896}
Mike Stroyana3082432015-09-25 13:39:21 -06009897
Karl Schultz6addd812016-02-02 17:17:23 -07009898TEST_F(VkLayerTest, InvalidImageViewAspect) {
9899 VkResult err;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009900
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009902 "vkCreateImageView: Color image "
9903 "formats must have ONLY the "
9904 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009905
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009906 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009907
9908 // Create an image and try to create a view with an invalid aspectMask
Karl Schultz6addd812016-02-02 17:17:23 -07009909 VkImage image;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009910
Karl Schultz6addd812016-02-02 17:17:23 -07009911 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9912 const int32_t tex_width = 32;
9913 const int32_t tex_height = 32;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009914
9915 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009916 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9917 image_create_info.pNext = NULL;
9918 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9919 image_create_info.format = tex_format;
9920 image_create_info.extent.width = tex_width;
9921 image_create_info.extent.height = tex_height;
9922 image_create_info.extent.depth = 1;
9923 image_create_info.mipLevels = 1;
9924 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9925 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9926 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9927 image_create_info.flags = 0;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009928
Chia-I Wuf7458c52015-10-26 21:10:41 +08009929 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009930 ASSERT_VK_SUCCESS(err);
9931
9932 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009933 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9934 image_view_create_info.image = image;
9935 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
9936 image_view_create_info.format = tex_format;
9937 image_view_create_info.subresourceRange.baseMipLevel = 0;
9938 image_view_create_info.subresourceRange.levelCount = 1;
9939 // Cause an error by setting an invalid image aspect
9940 image_view_create_info.subresourceRange.aspectMask =
9941 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009942
9943 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07009944 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
9945 &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009946
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009947 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009948}
9949
Mark Lobodzinskidb117632016-03-31 10:45:56 -06009950TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07009951 VkResult err;
9952 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06009953
Karl Schultz6addd812016-02-02 17:17:23 -07009954 m_errorMonitor->SetDesiredFailureMsg(
9955 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -06009956 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009957
Mike Stroyana3082432015-09-25 13:39:21 -06009958 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06009959
9960 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -07009961 VkImage srcImage;
9962 VkImage dstImage;
9963 VkDeviceMemory srcMem;
9964 VkDeviceMemory destMem;
9965 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06009966
9967 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009968 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9969 image_create_info.pNext = NULL;
9970 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9971 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
9972 image_create_info.extent.width = 32;
9973 image_create_info.extent.height = 32;
9974 image_create_info.extent.depth = 1;
9975 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -06009976 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -07009977 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9978 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9979 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
9980 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009981
Karl Schultz6addd812016-02-02 17:17:23 -07009982 err =
9983 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009984 ASSERT_VK_SUCCESS(err);
9985
Karl Schultz6addd812016-02-02 17:17:23 -07009986 err =
9987 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009988 ASSERT_VK_SUCCESS(err);
9989
9990 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009991 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009992 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9993 memAlloc.pNext = NULL;
9994 memAlloc.allocationSize = 0;
9995 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009996
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06009997 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009998 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009999 pass =
10000 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010001 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010002 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010003 ASSERT_VK_SUCCESS(err);
10004
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010005 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010006 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010007 pass =
10008 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010009 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010010 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010011 ASSERT_VK_SUCCESS(err);
10012
10013 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10014 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010015 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010016 ASSERT_VK_SUCCESS(err);
10017
10018 BeginCommandBuffer();
10019 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010020 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010021 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010022 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010023 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060010024 copyRegion.srcOffset.x = 0;
10025 copyRegion.srcOffset.y = 0;
10026 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010027 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010028 copyRegion.dstSubresource.mipLevel = 0;
10029 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010030 // Introduce failure by forcing the dst layerCount to differ from src
10031 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010032 copyRegion.dstOffset.x = 0;
10033 copyRegion.dstOffset.y = 0;
10034 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010035 copyRegion.extent.width = 1;
10036 copyRegion.extent.height = 1;
10037 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010038 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10039 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010040 EndCommandBuffer();
10041
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010042 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010043
Chia-I Wuf7458c52015-10-26 21:10:41 +080010044 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010045 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010046 vkFreeMemory(m_device->device(), srcMem, NULL);
10047 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010048}
10049
Tony Barbourd6673642016-05-05 14:46:39 -060010050TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
10051
10052 TEST_DESCRIPTION("Creating images with unsuported formats ");
10053
10054 ASSERT_NO_FATAL_FAILURE(InitState());
10055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10056 VkImageObj image(m_device);
10057 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
10058 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
10059 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
10060 VK_IMAGE_TILING_OPTIMAL, 0);
10061 ASSERT_TRUE(image.initialized());
10062
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010063 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
10064 VkImageCreateInfo image_create_info;
10065 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10066 image_create_info.pNext = NULL;
10067 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10068 image_create_info.format = VK_FORMAT_UNDEFINED;
10069 image_create_info.extent.width = 32;
10070 image_create_info.extent.height = 32;
10071 image_create_info.extent.depth = 1;
10072 image_create_info.mipLevels = 1;
10073 image_create_info.arrayLayers = 1;
10074 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10075 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10076 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10077 image_create_info.flags = 0;
10078
10079 m_errorMonitor->SetDesiredFailureMsg(
10080 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10081 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
10082
10083 VkImage localImage;
10084 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
10085 m_errorMonitor->VerifyFound();
10086
Tony Barbourd6673642016-05-05 14:46:39 -060010087 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010088 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060010089 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
10090 VkFormat format = static_cast<VkFormat>(f);
10091 VkFormatProperties fProps = m_device->format_properties(format);
10092 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
10093 fProps.optimalTilingFeatures == 0) {
10094 unsupported = format;
10095 break;
10096 }
10097 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010098
Tony Barbourd6673642016-05-05 14:46:39 -060010099 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060010100 image_create_info.format = unsupported;
Tony Barbourd6673642016-05-05 14:46:39 -060010101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010102 "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060010103
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010104 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060010105 m_errorMonitor->VerifyFound();
10106 }
10107}
10108
10109TEST_F(VkLayerTest, ImageLayerViewTests) {
10110 VkResult ret;
10111 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
10112
10113 ASSERT_NO_FATAL_FAILURE(InitState());
10114
10115 VkImageObj image(m_device);
10116 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
10117 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
10118 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
10119 VK_IMAGE_TILING_OPTIMAL, 0);
10120 ASSERT_TRUE(image.initialized());
10121
10122 VkImageView imgView;
10123 VkImageViewCreateInfo imgViewInfo = {};
10124 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10125 imgViewInfo.image = image.handle();
10126 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
10127 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
10128 imgViewInfo.subresourceRange.layerCount = 1;
10129 imgViewInfo.subresourceRange.baseMipLevel = 0;
10130 imgViewInfo.subresourceRange.levelCount = 1;
10131 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10132
10133 m_errorMonitor->SetDesiredFailureMsg(
10134 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10135 "vkCreateImageView called with baseMipLevel");
10136 // View can't have baseMipLevel >= image's mipLevels - Expect
10137 // VIEW_CREATE_ERROR
10138 imgViewInfo.subresourceRange.baseMipLevel = 1;
10139 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10140 m_errorMonitor->VerifyFound();
10141 imgViewInfo.subresourceRange.baseMipLevel = 0;
10142
10143 m_errorMonitor->SetDesiredFailureMsg(
10144 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10145 "vkCreateImageView called with baseArrayLayer");
10146 // View can't have baseArrayLayer >= image's arraySize - Expect
10147 // VIEW_CREATE_ERROR
10148 imgViewInfo.subresourceRange.baseArrayLayer = 1;
10149 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10150 m_errorMonitor->VerifyFound();
10151 imgViewInfo.subresourceRange.baseArrayLayer = 0;
10152
10153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10154 "vkCreateImageView called with 0 in "
10155 "pCreateInfo->subresourceRange."
10156 "levelCount");
10157 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
10158 imgViewInfo.subresourceRange.levelCount = 0;
10159 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10160 m_errorMonitor->VerifyFound();
10161 imgViewInfo.subresourceRange.levelCount = 1;
10162
10163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10164 "vkCreateImageView called with 0 in "
10165 "pCreateInfo->subresourceRange."
10166 "layerCount");
10167 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
10168 imgViewInfo.subresourceRange.layerCount = 0;
10169 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10170 m_errorMonitor->VerifyFound();
10171 imgViewInfo.subresourceRange.layerCount = 1;
10172
10173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10174 "but both must be color formats");
10175 // Can't use depth format for view into color image - Expect INVALID_FORMAT
10176 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
10177 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10178 m_errorMonitor->VerifyFound();
10179 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
10180
10181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10182 "Formats MUST be IDENTICAL unless "
10183 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
10184 "was set on image creation.");
10185 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
10186 // VIEW_CREATE_ERROR
10187 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
10188 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10189 m_errorMonitor->VerifyFound();
10190 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
10191
10192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10193 "can support ImageViews with "
10194 "differing formats but they must be "
10195 "in the same compatibility class.");
10196 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
10197 // VIEW_CREATE_ERROR
10198 VkImageCreateInfo mutImgInfo = image.create_info();
10199 VkImage mutImage;
10200 mutImgInfo.format = VK_FORMAT_R8_UINT;
10201 assert(
10202 m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures &
10203 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
10204 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
10205 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10206 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
10207 ASSERT_VK_SUCCESS(ret);
10208 imgViewInfo.image = mutImage;
10209 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10210 m_errorMonitor->VerifyFound();
10211 imgViewInfo.image = image.handle();
10212 vkDestroyImage(m_device->handle(), mutImage, NULL);
10213}
10214
10215TEST_F(VkLayerTest, MiscImageLayerTests) {
10216
10217 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
10218
10219 ASSERT_NO_FATAL_FAILURE(InitState());
10220
10221 VkImageObj image(m_device);
10222 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
10223 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
10224 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
10225 VK_IMAGE_TILING_OPTIMAL, 0);
10226 ASSERT_TRUE(image.initialized());
10227
10228 m_errorMonitor->SetDesiredFailureMsg(
10229 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10230 "number of layers in image subresource is zero");
10231 vk_testing::Buffer buffer;
10232 VkMemoryPropertyFlags reqs = 0;
10233 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
10234 VkBufferImageCopy region = {};
10235 region.bufferRowLength = 128;
10236 region.bufferImageHeight = 128;
10237 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10238 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
10239 region.imageSubresource.layerCount = 0;
10240 region.imageExtent.height = 4;
10241 region.imageExtent.width = 4;
10242 region.imageExtent.depth = 1;
10243 m_commandBuffer->BeginCommandBuffer();
10244 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
10245 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
10246 1, &region);
10247 m_errorMonitor->VerifyFound();
10248 region.imageSubresource.layerCount = 1;
10249
10250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10251 "aspectMasks for each region must "
10252 "specify only COLOR or DEPTH or "
10253 "STENCIL");
10254 // Expect MISMATCHED_IMAGE_ASPECT
10255 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
10256 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
10257 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
10258 1, &region);
10259 m_errorMonitor->VerifyFound();
10260 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10261
10262 m_errorMonitor->SetDesiredFailureMsg(
10263 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10264 "If the format of srcImage is a depth, stencil, depth stencil or "
10265 "integer-based format then filter must be VK_FILTER_NEAREST");
10266 // Expect INVALID_FILTER
10267 VkImageObj intImage1(m_device);
10268 intImage1.init(128, 128, VK_FORMAT_R8_UINT,
10269 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
10270 0);
10271 VkImageObj intImage2(m_device);
10272 intImage2.init(128, 128, VK_FORMAT_R8_UINT,
10273 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
10274 0);
10275 VkImageBlit blitRegion = {};
10276 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10277 blitRegion.srcSubresource.baseArrayLayer = 0;
10278 blitRegion.srcSubresource.layerCount = 1;
10279 blitRegion.srcSubresource.mipLevel = 0;
10280 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10281 blitRegion.dstSubresource.baseArrayLayer = 0;
10282 blitRegion.dstSubresource.layerCount = 1;
10283 blitRegion.dstSubresource.mipLevel = 0;
10284
10285 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(),
10286 intImage1.layout(), intImage2.handle(), intImage2.layout(),
10287 16, &blitRegion, VK_FILTER_LINEAR);
10288 m_errorMonitor->VerifyFound();
10289
10290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10291 "called with 0 in ppMemoryBarriers");
10292 VkImageMemoryBarrier img_barrier;
10293 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10294 img_barrier.pNext = NULL;
10295 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10296 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10297 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10298 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10299 img_barrier.image = image.handle();
10300 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10301 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10302 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10303 img_barrier.subresourceRange.baseArrayLayer = 0;
10304 img_barrier.subresourceRange.baseMipLevel = 0;
10305 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
10306 img_barrier.subresourceRange.layerCount = 0;
10307 img_barrier.subresourceRange.levelCount = 1;
10308 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
10309 VK_PIPELINE_STAGE_HOST_BIT,
10310 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
10311 nullptr, 1, &img_barrier);
10312 m_errorMonitor->VerifyFound();
10313 img_barrier.subresourceRange.layerCount = 1;
10314}
10315
10316TEST_F(VkLayerTest, ImageFormatLimits) {
10317
10318 TEST_DESCRIPTION("Exceed the limits of image format ");
10319
10320 m_errorMonitor->SetDesiredFailureMsg(
10321 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10322 "CreateImage extents exceed allowable limits for format");
10323 VkImageCreateInfo image_create_info = {};
10324 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10325 image_create_info.pNext = NULL;
10326 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10327 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10328 image_create_info.extent.width = 32;
10329 image_create_info.extent.height = 32;
10330 image_create_info.extent.depth = 1;
10331 image_create_info.mipLevels = 1;
10332 image_create_info.arrayLayers = 1;
10333 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10334 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10335 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10336 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10337 image_create_info.flags = 0;
10338
10339 VkImage nullImg;
10340 VkImageFormatProperties imgFmtProps;
10341 vkGetPhysicalDeviceImageFormatProperties(
10342 gpu(), image_create_info.format, image_create_info.imageType,
10343 image_create_info.tiling, image_create_info.usage,
10344 image_create_info.flags, &imgFmtProps);
10345 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
10346 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10347 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10348 m_errorMonitor->VerifyFound();
10349 image_create_info.extent.depth = 1;
10350
10351 m_errorMonitor->SetDesiredFailureMsg(
10352 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10353 "exceeds allowable maximum supported by format of");
10354 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
10355 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10356 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10357 m_errorMonitor->VerifyFound();
10358 image_create_info.mipLevels = 1;
10359
10360 m_errorMonitor->SetDesiredFailureMsg(
10361 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10362 "exceeds allowable maximum supported by format of");
10363 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
10364 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10365 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10366 m_errorMonitor->VerifyFound();
10367 image_create_info.arrayLayers = 1;
10368
10369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10370 "is not supported by format");
10371 int samples = imgFmtProps.sampleCounts >> 1;
10372 image_create_info.samples = (VkSampleCountFlagBits)samples;
10373 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10374 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10375 m_errorMonitor->VerifyFound();
10376 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10377
10378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10379 "pCreateInfo->initialLayout, must be "
10380 "VK_IMAGE_LAYOUT_UNDEFINED or "
10381 "VK_IMAGE_LAYOUT_PREINITIALIZED");
10382 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10383 // Expect INVALID_LAYOUT
10384 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10385 m_errorMonitor->VerifyFound();
10386 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10387}
10388
Karl Schultz6addd812016-02-02 17:17:23 -070010389TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060010390 VkResult err;
10391 bool pass;
10392
10393 // Create color images with different format sizes and try to copy between them
10394 m_errorMonitor->SetDesiredFailureMsg(
10395 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10396 "vkCmdCopyImage called with unmatched source and dest image format sizes");
10397
10398 ASSERT_NO_FATAL_FAILURE(InitState());
10399
10400 // Create two images of different types and try to copy between them
10401 VkImage srcImage;
10402 VkImage dstImage;
10403 VkDeviceMemory srcMem;
10404 VkDeviceMemory destMem;
10405 VkMemoryRequirements memReqs;
10406
10407 VkImageCreateInfo image_create_info = {};
10408 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10409 image_create_info.pNext = NULL;
10410 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10411 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10412 image_create_info.extent.width = 32;
10413 image_create_info.extent.height = 32;
10414 image_create_info.extent.depth = 1;
10415 image_create_info.mipLevels = 1;
10416 image_create_info.arrayLayers = 1;
10417 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10418 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10419 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10420 image_create_info.flags = 0;
10421
10422 err =
10423 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
10424 ASSERT_VK_SUCCESS(err);
10425
10426 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
10427 // Introduce failure by creating second image with a different-sized format.
10428 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
10429
10430 err =
10431 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
10432 ASSERT_VK_SUCCESS(err);
10433
10434 // Allocate memory
10435 VkMemoryAllocateInfo memAlloc = {};
10436 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10437 memAlloc.pNext = NULL;
10438 memAlloc.allocationSize = 0;
10439 memAlloc.memoryTypeIndex = 0;
10440
10441 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
10442 memAlloc.allocationSize = memReqs.size;
10443 pass =
10444 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
10445 ASSERT_TRUE(pass);
10446 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
10447 ASSERT_VK_SUCCESS(err);
10448
10449 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
10450 memAlloc.allocationSize = memReqs.size;
10451 pass =
10452 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
10453 ASSERT_TRUE(pass);
10454 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
10455 ASSERT_VK_SUCCESS(err);
10456
10457 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10458 ASSERT_VK_SUCCESS(err);
10459 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
10460 ASSERT_VK_SUCCESS(err);
10461
10462 BeginCommandBuffer();
10463 VkImageCopy copyRegion;
10464 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10465 copyRegion.srcSubresource.mipLevel = 0;
10466 copyRegion.srcSubresource.baseArrayLayer = 0;
10467 copyRegion.srcSubresource.layerCount = 0;
10468 copyRegion.srcOffset.x = 0;
10469 copyRegion.srcOffset.y = 0;
10470 copyRegion.srcOffset.z = 0;
10471 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10472 copyRegion.dstSubresource.mipLevel = 0;
10473 copyRegion.dstSubresource.baseArrayLayer = 0;
10474 copyRegion.dstSubresource.layerCount = 0;
10475 copyRegion.dstOffset.x = 0;
10476 copyRegion.dstOffset.y = 0;
10477 copyRegion.dstOffset.z = 0;
10478 copyRegion.extent.width = 1;
10479 copyRegion.extent.height = 1;
10480 copyRegion.extent.depth = 1;
10481 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10482 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10483 EndCommandBuffer();
10484
10485 m_errorMonitor->VerifyFound();
10486
10487 vkDestroyImage(m_device->device(), srcImage, NULL);
10488 vkDestroyImage(m_device->device(), dstImage, NULL);
10489 vkFreeMemory(m_device->device(), srcMem, NULL);
10490 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010491}
10492
Karl Schultz6addd812016-02-02 17:17:23 -070010493TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
10494 VkResult err;
10495 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010496
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010497 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010498 m_errorMonitor->SetDesiredFailureMsg(
10499 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010500 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010501
Mike Stroyana3082432015-09-25 13:39:21 -060010502 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010503
10504 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010505 VkImage srcImage;
10506 VkImage dstImage;
10507 VkDeviceMemory srcMem;
10508 VkDeviceMemory destMem;
10509 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010510
10511 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010512 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10513 image_create_info.pNext = NULL;
10514 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10515 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10516 image_create_info.extent.width = 32;
10517 image_create_info.extent.height = 32;
10518 image_create_info.extent.depth = 1;
10519 image_create_info.mipLevels = 1;
10520 image_create_info.arrayLayers = 1;
10521 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10522 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10523 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10524 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010525
Karl Schultz6addd812016-02-02 17:17:23 -070010526 err =
10527 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010528 ASSERT_VK_SUCCESS(err);
10529
Karl Schultzbdb75952016-04-19 11:36:49 -060010530 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
10531
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010532 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070010533 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010534 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
10535 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010536
Karl Schultz6addd812016-02-02 17:17:23 -070010537 err =
10538 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010539 ASSERT_VK_SUCCESS(err);
10540
10541 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010542 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010543 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10544 memAlloc.pNext = NULL;
10545 memAlloc.allocationSize = 0;
10546 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010547
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010548 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010549 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010550 pass =
10551 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010552 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010553 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010554 ASSERT_VK_SUCCESS(err);
10555
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010556 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010557 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010558 pass =
10559 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010560 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010561 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010562 ASSERT_VK_SUCCESS(err);
10563
10564 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10565 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010566 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010567 ASSERT_VK_SUCCESS(err);
10568
10569 BeginCommandBuffer();
10570 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010571 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010572 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010573 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010574 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010575 copyRegion.srcOffset.x = 0;
10576 copyRegion.srcOffset.y = 0;
10577 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010578 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010579 copyRegion.dstSubresource.mipLevel = 0;
10580 copyRegion.dstSubresource.baseArrayLayer = 0;
10581 copyRegion.dstSubresource.layerCount = 0;
10582 copyRegion.dstOffset.x = 0;
10583 copyRegion.dstOffset.y = 0;
10584 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010585 copyRegion.extent.width = 1;
10586 copyRegion.extent.height = 1;
10587 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010588 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10589 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010590 EndCommandBuffer();
10591
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010592 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010593
Chia-I Wuf7458c52015-10-26 21:10:41 +080010594 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010595 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010596 vkFreeMemory(m_device->device(), srcMem, NULL);
10597 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010598}
10599
Karl Schultz6addd812016-02-02 17:17:23 -070010600TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
10601 VkResult err;
10602 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010603
Karl Schultz6addd812016-02-02 17:17:23 -070010604 m_errorMonitor->SetDesiredFailureMsg(
10605 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010606 "vkCmdResolveImage called with source sample count less than 2.");
10607
Mike Stroyana3082432015-09-25 13:39:21 -060010608 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010609
10610 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070010611 VkImage srcImage;
10612 VkImage dstImage;
10613 VkDeviceMemory srcMem;
10614 VkDeviceMemory destMem;
10615 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010616
10617 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010618 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10619 image_create_info.pNext = NULL;
10620 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10621 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10622 image_create_info.extent.width = 32;
10623 image_create_info.extent.height = 1;
10624 image_create_info.extent.depth = 1;
10625 image_create_info.mipLevels = 1;
10626 image_create_info.arrayLayers = 1;
10627 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10628 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10629 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10630 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010631
Karl Schultz6addd812016-02-02 17:17:23 -070010632 err =
10633 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010634 ASSERT_VK_SUCCESS(err);
10635
Karl Schultz6addd812016-02-02 17:17:23 -070010636 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010637
Karl Schultz6addd812016-02-02 17:17:23 -070010638 err =
10639 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010640 ASSERT_VK_SUCCESS(err);
10641
10642 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010643 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010644 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10645 memAlloc.pNext = NULL;
10646 memAlloc.allocationSize = 0;
10647 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010648
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010649 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010650 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010651 pass =
10652 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010653 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010654 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010655 ASSERT_VK_SUCCESS(err);
10656
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010657 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010658 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010659 pass =
10660 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010661 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010662 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010663 ASSERT_VK_SUCCESS(err);
10664
10665 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10666 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010667 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010668 ASSERT_VK_SUCCESS(err);
10669
10670 BeginCommandBuffer();
10671 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070010672 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
10673 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060010674 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010675 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010676 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010677 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010678 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010679 resolveRegion.srcOffset.x = 0;
10680 resolveRegion.srcOffset.y = 0;
10681 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010682 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010683 resolveRegion.dstSubresource.mipLevel = 0;
10684 resolveRegion.dstSubresource.baseArrayLayer = 0;
10685 resolveRegion.dstSubresource.layerCount = 0;
10686 resolveRegion.dstOffset.x = 0;
10687 resolveRegion.dstOffset.y = 0;
10688 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010689 resolveRegion.extent.width = 1;
10690 resolveRegion.extent.height = 1;
10691 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010692 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10693 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010694 EndCommandBuffer();
10695
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010696 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010697
Chia-I Wuf7458c52015-10-26 21:10:41 +080010698 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010699 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010700 vkFreeMemory(m_device->device(), srcMem, NULL);
10701 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010702}
10703
Karl Schultz6addd812016-02-02 17:17:23 -070010704TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
10705 VkResult err;
10706 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010707
Karl Schultz6addd812016-02-02 17:17:23 -070010708 m_errorMonitor->SetDesiredFailureMsg(
10709 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010710 "vkCmdResolveImage called with dest sample count greater than 1.");
10711
Mike Stroyana3082432015-09-25 13:39:21 -060010712 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010713
Chris Forbesa7530692016-05-08 12:35:39 +120010714 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070010715 VkImage srcImage;
10716 VkImage dstImage;
10717 VkDeviceMemory srcMem;
10718 VkDeviceMemory destMem;
10719 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010720
10721 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010722 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10723 image_create_info.pNext = NULL;
10724 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10725 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10726 image_create_info.extent.width = 32;
10727 image_create_info.extent.height = 1;
10728 image_create_info.extent.depth = 1;
10729 image_create_info.mipLevels = 1;
10730 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120010731 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070010732 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10733 // Note: Some implementations expect color attachment usage for any
10734 // multisample surface
10735 image_create_info.usage =
10736 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10737 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010738
Karl Schultz6addd812016-02-02 17:17:23 -070010739 err =
10740 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010741 ASSERT_VK_SUCCESS(err);
10742
Karl Schultz6addd812016-02-02 17:17:23 -070010743 // Note: Some implementations expect color attachment usage for any
10744 // multisample surface
10745 image_create_info.usage =
10746 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010747
Karl Schultz6addd812016-02-02 17:17:23 -070010748 err =
10749 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010750 ASSERT_VK_SUCCESS(err);
10751
10752 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010753 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010754 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10755 memAlloc.pNext = NULL;
10756 memAlloc.allocationSize = 0;
10757 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010758
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010759 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010760 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010761 pass =
10762 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010763 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010764 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010765 ASSERT_VK_SUCCESS(err);
10766
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010767 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010768 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010769 pass =
10770 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010771 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010772 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010773 ASSERT_VK_SUCCESS(err);
10774
10775 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10776 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010777 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010778 ASSERT_VK_SUCCESS(err);
10779
10780 BeginCommandBuffer();
10781 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070010782 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
10783 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060010784 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010785 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010786 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010787 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010788 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010789 resolveRegion.srcOffset.x = 0;
10790 resolveRegion.srcOffset.y = 0;
10791 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010792 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010793 resolveRegion.dstSubresource.mipLevel = 0;
10794 resolveRegion.dstSubresource.baseArrayLayer = 0;
10795 resolveRegion.dstSubresource.layerCount = 0;
10796 resolveRegion.dstOffset.x = 0;
10797 resolveRegion.dstOffset.y = 0;
10798 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010799 resolveRegion.extent.width = 1;
10800 resolveRegion.extent.height = 1;
10801 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010802 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10803 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010804 EndCommandBuffer();
10805
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010806 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010807
Chia-I Wuf7458c52015-10-26 21:10:41 +080010808 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010809 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010810 vkFreeMemory(m_device->device(), srcMem, NULL);
10811 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010812}
10813
Karl Schultz6addd812016-02-02 17:17:23 -070010814TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
10815 VkResult err;
10816 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010817
Karl Schultz6addd812016-02-02 17:17:23 -070010818 m_errorMonitor->SetDesiredFailureMsg(
10819 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010820 "vkCmdResolveImage called with unmatched source and dest formats.");
10821
Mike Stroyana3082432015-09-25 13:39:21 -060010822 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010823
10824 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010825 VkImage srcImage;
10826 VkImage dstImage;
10827 VkDeviceMemory srcMem;
10828 VkDeviceMemory destMem;
10829 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010830
10831 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010832 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10833 image_create_info.pNext = NULL;
10834 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10835 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10836 image_create_info.extent.width = 32;
10837 image_create_info.extent.height = 1;
10838 image_create_info.extent.depth = 1;
10839 image_create_info.mipLevels = 1;
10840 image_create_info.arrayLayers = 1;
10841 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
10842 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10843 // Note: Some implementations expect color attachment usage for any
10844 // multisample surface
10845 image_create_info.usage =
10846 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10847 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010848
Karl Schultz6addd812016-02-02 17:17:23 -070010849 err =
10850 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010851 ASSERT_VK_SUCCESS(err);
10852
Karl Schultz6addd812016-02-02 17:17:23 -070010853 // Set format to something other than source image
10854 image_create_info.format = VK_FORMAT_R32_SFLOAT;
10855 // Note: Some implementations expect color attachment usage for any
10856 // multisample surface
10857 image_create_info.usage =
10858 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10859 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010860
Karl Schultz6addd812016-02-02 17:17:23 -070010861 err =
10862 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010863 ASSERT_VK_SUCCESS(err);
10864
10865 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010866 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010867 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10868 memAlloc.pNext = NULL;
10869 memAlloc.allocationSize = 0;
10870 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010871
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010872 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010873 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010874 pass =
10875 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010876 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010877 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010878 ASSERT_VK_SUCCESS(err);
10879
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010880 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010881 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010882 pass =
10883 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010884 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010885 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010886 ASSERT_VK_SUCCESS(err);
10887
10888 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10889 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010890 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010891 ASSERT_VK_SUCCESS(err);
10892
10893 BeginCommandBuffer();
10894 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070010895 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
10896 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060010897 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010898 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010899 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010900 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010901 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010902 resolveRegion.srcOffset.x = 0;
10903 resolveRegion.srcOffset.y = 0;
10904 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010905 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010906 resolveRegion.dstSubresource.mipLevel = 0;
10907 resolveRegion.dstSubresource.baseArrayLayer = 0;
10908 resolveRegion.dstSubresource.layerCount = 0;
10909 resolveRegion.dstOffset.x = 0;
10910 resolveRegion.dstOffset.y = 0;
10911 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010912 resolveRegion.extent.width = 1;
10913 resolveRegion.extent.height = 1;
10914 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010915 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10916 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010917 EndCommandBuffer();
10918
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010919 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010920
Chia-I Wuf7458c52015-10-26 21:10:41 +080010921 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010922 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010923 vkFreeMemory(m_device->device(), srcMem, NULL);
10924 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010925}
10926
Karl Schultz6addd812016-02-02 17:17:23 -070010927TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
10928 VkResult err;
10929 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010930
Karl Schultz6addd812016-02-02 17:17:23 -070010931 m_errorMonitor->SetDesiredFailureMsg(
10932 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010933 "vkCmdResolveImage called with unmatched source and dest image types.");
10934
Mike Stroyana3082432015-09-25 13:39:21 -060010935 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010936
10937 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010938 VkImage srcImage;
10939 VkImage dstImage;
10940 VkDeviceMemory srcMem;
10941 VkDeviceMemory destMem;
10942 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010943
10944 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010945 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10946 image_create_info.pNext = NULL;
10947 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10948 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10949 image_create_info.extent.width = 32;
10950 image_create_info.extent.height = 1;
10951 image_create_info.extent.depth = 1;
10952 image_create_info.mipLevels = 1;
10953 image_create_info.arrayLayers = 1;
10954 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
10955 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10956 // Note: Some implementations expect color attachment usage for any
10957 // multisample surface
10958 image_create_info.usage =
10959 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10960 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010961
Karl Schultz6addd812016-02-02 17:17:23 -070010962 err =
10963 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010964 ASSERT_VK_SUCCESS(err);
10965
Karl Schultz6addd812016-02-02 17:17:23 -070010966 image_create_info.imageType = VK_IMAGE_TYPE_1D;
10967 // Note: Some implementations expect color attachment usage for any
10968 // multisample surface
10969 image_create_info.usage =
10970 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10971 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010972
Karl Schultz6addd812016-02-02 17:17:23 -070010973 err =
10974 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010975 ASSERT_VK_SUCCESS(err);
10976
10977 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010978 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010979 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10980 memAlloc.pNext = NULL;
10981 memAlloc.allocationSize = 0;
10982 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010983
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010984 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010985 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010986 pass =
10987 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010988 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010989 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010990 ASSERT_VK_SUCCESS(err);
10991
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010992 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010993 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010994 pass =
10995 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010996 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010997 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010998 ASSERT_VK_SUCCESS(err);
10999
11000 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11001 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011002 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011003 ASSERT_VK_SUCCESS(err);
11004
11005 BeginCommandBuffer();
11006 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011007 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11008 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011009 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011010 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011011 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011012 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011013 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011014 resolveRegion.srcOffset.x = 0;
11015 resolveRegion.srcOffset.y = 0;
11016 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011017 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011018 resolveRegion.dstSubresource.mipLevel = 0;
11019 resolveRegion.dstSubresource.baseArrayLayer = 0;
11020 resolveRegion.dstSubresource.layerCount = 0;
11021 resolveRegion.dstOffset.x = 0;
11022 resolveRegion.dstOffset.y = 0;
11023 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011024 resolveRegion.extent.width = 1;
11025 resolveRegion.extent.height = 1;
11026 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011027 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11028 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011029 EndCommandBuffer();
11030
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011031 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011032
Chia-I Wuf7458c52015-10-26 21:10:41 +080011033 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011034 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011035 vkFreeMemory(m_device->device(), srcMem, NULL);
11036 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011037}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011038
Karl Schultz6addd812016-02-02 17:17:23 -070011039TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011040 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070011041 // to using a DS format, then cause it to hit error due to COLOR_BIT not
11042 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011043 // The image format check comes 2nd in validation so we trigger it first,
11044 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070011045 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011046
Karl Schultz6addd812016-02-02 17:17:23 -070011047 m_errorMonitor->SetDesiredFailureMsg(
11048 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011049 "Combination depth/stencil image formats can have only the ");
11050
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011051 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011052
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011053 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011054 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
11055 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011056
11057 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011058 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11059 ds_pool_ci.pNext = NULL;
11060 ds_pool_ci.maxSets = 1;
11061 ds_pool_ci.poolSizeCount = 1;
11062 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011063
11064 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -070011065 err =
11066 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011067 ASSERT_VK_SUCCESS(err);
11068
11069 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011070 dsl_binding.binding = 0;
11071 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
11072 dsl_binding.descriptorCount = 1;
11073 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11074 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011075
11076 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011077 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11078 ds_layout_ci.pNext = NULL;
11079 ds_layout_ci.bindingCount = 1;
11080 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011081 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070011082 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
11083 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011084 ASSERT_VK_SUCCESS(err);
11085
11086 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011087 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011088 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011089 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011090 alloc_info.descriptorPool = ds_pool;
11091 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070011092 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
11093 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011094 ASSERT_VK_SUCCESS(err);
11095
Karl Schultz6addd812016-02-02 17:17:23 -070011096 VkImage image_bad;
11097 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011098 // One bad format and one good format for Color attachment
Karl Schultz6addd812016-02-02 17:17:23 -070011099 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011100 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070011101 const int32_t tex_width = 32;
11102 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011103
11104 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011105 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11106 image_create_info.pNext = NULL;
11107 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11108 image_create_info.format = tex_format_bad;
11109 image_create_info.extent.width = tex_width;
11110 image_create_info.extent.height = tex_height;
11111 image_create_info.extent.depth = 1;
11112 image_create_info.mipLevels = 1;
11113 image_create_info.arrayLayers = 1;
11114 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11115 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11116 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
11117 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11118 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011119
Karl Schultz6addd812016-02-02 17:17:23 -070011120 err =
11121 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011122 ASSERT_VK_SUCCESS(err);
11123 image_create_info.format = tex_format_good;
Karl Schultz6addd812016-02-02 17:17:23 -070011124 image_create_info.usage =
11125 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11126 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
11127 &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011128 ASSERT_VK_SUCCESS(err);
11129
11130 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011131 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11132 image_view_create_info.image = image_bad;
11133 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11134 image_view_create_info.format = tex_format_bad;
11135 image_view_create_info.subresourceRange.baseArrayLayer = 0;
11136 image_view_create_info.subresourceRange.baseMipLevel = 0;
11137 image_view_create_info.subresourceRange.layerCount = 1;
11138 image_view_create_info.subresourceRange.levelCount = 1;
11139 image_view_create_info.subresourceRange.aspectMask =
11140 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011141
11142 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070011143 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
11144 &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011145
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011146 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011147
Chia-I Wuf7458c52015-10-26 21:10:41 +080011148 vkDestroyImage(m_device->device(), image_bad, NULL);
11149 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011150 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11151 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011152}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060011153
11154TEST_F(VkLayerTest, ClearImageErrors) {
11155 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
11156 "ClearDepthStencilImage with a color image.");
11157
11158 ASSERT_NO_FATAL_FAILURE(InitState());
11159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11160
11161 // Renderpass is started here so end it as Clear cmds can't be in renderpass
11162 BeginCommandBuffer();
11163 m_commandBuffer->EndRenderPass();
11164
11165 // Color image
11166 VkClearColorValue clear_color;
11167 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
11168 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
11169 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
11170 const int32_t img_width = 32;
11171 const int32_t img_height = 32;
11172 VkImageCreateInfo image_create_info = {};
11173 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11174 image_create_info.pNext = NULL;
11175 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11176 image_create_info.format = color_format;
11177 image_create_info.extent.width = img_width;
11178 image_create_info.extent.height = img_height;
11179 image_create_info.extent.depth = 1;
11180 image_create_info.mipLevels = 1;
11181 image_create_info.arrayLayers = 1;
11182 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11183 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11184 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11185
11186 vk_testing::Image color_image;
11187 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info,
11188 reqs);
11189
11190 const VkImageSubresourceRange color_range =
11191 vk_testing::Image::subresource_range(image_create_info,
11192 VK_IMAGE_ASPECT_COLOR_BIT);
11193
11194 // Depth/Stencil image
11195 VkClearDepthStencilValue clear_value = {0};
11196 reqs = 0; // don't need HOST_VISIBLE DS image
11197 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
11198 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
11199 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
11200 ds_image_create_info.extent.width = 64;
11201 ds_image_create_info.extent.height = 64;
11202 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11203 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11204
11205 vk_testing::Image ds_image;
11206 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info,
11207 reqs);
11208
11209 const VkImageSubresourceRange ds_range =
11210 vk_testing::Image::subresource_range(ds_image_create_info,
11211 VK_IMAGE_ASPECT_DEPTH_BIT);
11212
11213 m_errorMonitor->SetDesiredFailureMsg(
11214 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11215 "vkCmdClearColorImage called with depth/stencil image.");
11216
11217 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
11218 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
11219 &color_range);
11220
11221 m_errorMonitor->VerifyFound();
11222
11223 // Call CmdClearDepthStencilImage with color image
11224 m_errorMonitor->SetDesiredFailureMsg(
11225 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11226 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
11227
11228 vkCmdClearDepthStencilImage(
11229 m_commandBuffer->GetBufferHandle(), color_image.handle(),
11230 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
11231 &ds_range);
11232
11233 m_errorMonitor->VerifyFound();
11234}
Tobin Ehliscde08892015-09-22 10:11:37 -060011235#endif // IMAGE_TESTS
11236
Tony Barbour300a6082015-04-07 13:44:53 -060011237int main(int argc, char **argv) {
11238 int result;
11239
Cody Northrop8e54a402016-03-08 22:25:52 -070011240#ifdef ANDROID
11241 int vulkanSupport = InitVulkan();
11242 if (vulkanSupport == 0)
11243 return 1;
11244#endif
11245
Tony Barbour300a6082015-04-07 13:44:53 -060011246 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060011247 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060011248
11249 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
11250
11251 result = RUN_ALL_TESTS();
11252
Tony Barbour6918cd52015-04-09 12:58:51 -060011253 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060011254 return result;
11255}