blob: 5476dc7f1294fda8025ba556dd42002d3b21e7df [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
20 */
Tony Barbour65c48b32015-11-17 10:02:56 -070021
Cody Northrop8e54a402016-03-08 22:25:52 -070022#ifdef ANDROID
23#include "vulkan_wrapper.h"
24#else
David Pinedo9316d3b2015-11-06 12:54:48 -070025#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070026#endif
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -060027#include "test_common.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060028#include "vkrenderframework.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060029#include "vk_layer_config.h"
Jon Ashburn7fa7e222016-02-02 12:08:10 -070030#include "icd-spv.h"
Tony Barbour300a6082015-04-07 13:44:53 -060031
Mark Lobodzinski3780e142015-05-14 15:08:13 -050032#define GLM_FORCE_RADIANS
33#include "glm/glm.hpp"
34#include <glm/gtc/matrix_transform.hpp>
35
Dustin Gravesffa90fa2016-05-06 11:20:38 -060036#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060037#define MEM_TRACKER_TESTS 1
38#define OBJ_TRACKER_TESTS 1
39#define DRAW_STATE_TESTS 1
40#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120041#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060042#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060043#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060044
Mark Lobodzinski3780e142015-05-14 15:08:13 -050045//--------------------------------------------------------------------------------------
46// Mesh and VertexFormat Data
47//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070048struct Vertex {
49 float posX, posY, posZ, posW; // Position data
50 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050051};
52
Karl Schultz6addd812016-02-02 17:17:23 -070053#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050054
55typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070056 BsoFailNone = 0x00000000,
57 BsoFailLineWidth = 0x00000001,
58 BsoFailDepthBias = 0x00000002,
59 BsoFailViewport = 0x00000004,
60 BsoFailScissor = 0x00000008,
61 BsoFailBlend = 0x00000010,
62 BsoFailDepthBounds = 0x00000020,
63 BsoFailStencilReadMask = 0x00000040,
64 BsoFailStencilWriteMask = 0x00000080,
65 BsoFailStencilReference = 0x00000100,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050066} BsoFailSelect;
67
68struct vktriangle_vs_uniform {
69 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070070 float mvp[4][4];
71 float position[3][4];
72 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050073};
74
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050075static const char bindStateVertShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120076 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070077 "vec2 vertices[3];\n"
78 "out gl_PerVertex {\n"
79 " vec4 gl_Position;\n"
80 "};\n"
81 "void main() {\n"
82 " vertices[0] = vec2(-1.0, -1.0);\n"
83 " vertices[1] = vec2( 1.0, -1.0);\n"
84 " vertices[2] = vec2( 0.0, 1.0);\n"
85 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
86 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050087
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050088static const char bindStateFragShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120089 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070090 "\n"
91 "layout(location = 0) out vec4 uFragColor;\n"
92 "void main(){\n"
93 " uFragColor = vec4(0,1,0,1);\n"
94 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050095
Karl Schultz6addd812016-02-02 17:17:23 -070096static VKAPI_ATTR VkBool32 VKAPI_CALL
97myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
98 uint64_t srcObject, size_t location, int32_t msgCode,
99 const char *pLayerPrefix, const char *pMsg, void *pUserData);
Tony Barbour300a6082015-04-07 13:44:53 -0600100
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600101// ********************************************************
102// ErrorMonitor Usage:
103//
104// Call SetDesiredFailureMsg with a string to be compared against all
105// encountered log messages. Passing NULL will match all log messages.
106// logMsg will return true for skipCall only if msg is matched or NULL.
107//
108// Call DesiredMsgFound to determine if the desired failure message
109// was encountered.
110
Tony Barbour300a6082015-04-07 13:44:53 -0600111class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700112 public:
113 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600114 test_platform_thread_create_mutex(&m_mutex);
115 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700116 m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700117 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600118 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600119 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600120
Dustin Graves48458142016-04-29 16:11:55 -0600121 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
122
Karl Schultz6addd812016-02-02 17:17:23 -0700123 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200124 // also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600125 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600126 m_failureMsg.clear();
127 m_otherMsgs.clear();
128 m_desiredMsg = msgString;
Karl Schultz6addd812016-02-02 17:17:23 -0700129 m_msgFound = VK_FALSE;
130 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600131 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600132 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600133
Karl Schultz6addd812016-02-02 17:17:23 -0700134 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600135 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600136 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600137 if (m_bailout != NULL) {
138 *m_bailout = true;
139 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600140 string errorString(msgString);
141 if (msgFlags & m_msgFlags) {
142 if (errorString.find(m_desiredMsg) != string::npos) {
Chris Forbesc7b8ad72016-04-04 18:50:38 +1200143 if (m_msgFound) { /* if multiple matches, don't lose all but the last! */
144 m_otherMsgs.push_back(m_failureMsg);
145 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600146 m_failureMsg = errorString;
Karl Schultz6addd812016-02-02 17:17:23 -0700147 m_msgFound = VK_TRUE;
148 result = VK_TRUE;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600149 } else {
150 m_otherMsgs.push_back(errorString);
151 }
152 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600153 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600154 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600155 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600156
Karl Schultz6addd812016-02-02 17:17:23 -0700157 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600158
Karl Schultz6addd812016-02-02 17:17:23 -0700159 string GetFailureMsg(void) { return m_failureMsg; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600160
Karl Schultz6addd812016-02-02 17:17:23 -0700161 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600162
Karl Schultz6addd812016-02-02 17:17:23 -0700163 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600164
Karl Schultz6addd812016-02-02 17:17:23 -0700165 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 vector<string> otherMsgs = GetOtherFailureMsgs();
167 cout << "Other error messages logged for this test were:" << endl;
168 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
169 cout << " " << *iter << endl;
170 }
171 }
172
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200173 /* helpers */
174
175 void ExpectSuccess() {
176 // match anything
177 SetDesiredFailureMsg(~0u, "");
178 }
179
180 void VerifyFound() {
181 // Not seeing the desired message is a failure. /Before/ throwing, dump
182 // any other messages.
183 if (!DesiredMsgFound()) {
184 DumpFailureMsgs();
185 FAIL() << "Did not receive expected error '" << m_desiredMsg << "'";
186 }
187 }
188
189 void VerifyNotFound() {
190 // ExpectSuccess() configured us to match anything. Any error is a
191 // failure.
192 if (DesiredMsgFound()) {
193 DumpFailureMsgs();
194 FAIL() << "Expected to succeed but got error: " << GetFailureMsg();
195 }
196 }
197
Karl Schultz6addd812016-02-02 17:17:23 -0700198 private:
199 VkFlags m_msgFlags;
200 string m_desiredMsg;
201 string m_failureMsg;
202 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600203 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700204 bool *m_bailout;
205 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600206};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500207
Karl Schultz6addd812016-02-02 17:17:23 -0700208static VKAPI_ATTR VkBool32 VKAPI_CALL
209myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
210 uint64_t srcObject, size_t location, int32_t msgCode,
211 const char *pLayerPrefix, const char *pMsg, void *pUserData) {
212 if (msgFlags &
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700213 (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
Karl Schultz6addd812016-02-02 17:17:23 -0700214 VK_DEBUG_REPORT_ERROR_BIT_EXT)) {
Tony Barbour0b4d9562015-04-09 10:48:04 -0600215 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600216 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600217 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600218 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600219}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500220
Karl Schultz6addd812016-02-02 17:17:23 -0700221class VkLayerTest : public VkRenderFramework {
222 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800223 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
224 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700225 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText,
226 BsoFailSelect failMask);
227 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
228 VkPipelineObj &pipelineobj,
229 VkDescriptorSetObj &descriptorSet,
230 BsoFailSelect failMask);
231 void GenericDrawPreparation(VkPipelineObj &pipelineobj,
232 VkDescriptorSetObj &descriptorSet,
233 BsoFailSelect failMask) {
234 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet,
235 failMask);
236 }
Tony Barbour300a6082015-04-07 13:44:53 -0600237
Tony Barbourfe3351b2015-07-28 10:17:20 -0600238 /* Convenience functions that use built-in command buffer */
Karl Schultz6addd812016-02-02 17:17:23 -0700239 VkResult BeginCommandBuffer() {
240 return BeginCommandBuffer(*m_commandBuffer);
241 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800242 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Karl Schultz6addd812016-02-02 17:17:23 -0700243 void Draw(uint32_t vertexCount, uint32_t instanceCount,
244 uint32_t firstVertex, uint32_t firstInstance) {
245 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex,
246 firstInstance);
247 }
248 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount,
249 uint32_t firstIndex, int32_t vertexOffset,
250 uint32_t firstInstance) {
251 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex,
252 vertexOffset, firstInstance);
253 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800254 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
Karl Schultz6addd812016-02-02 17:17:23 -0700255 void QueueCommandBuffer(const VkFence &fence) {
256 m_commandBuffer->QueueCommandBuffer(fence);
257 }
258 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer,
259 VkDeviceSize offset, uint32_t binding) {
260 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
261 }
262 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
263 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
264 }
265
266 protected:
267 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600268 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600269
270 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600271 std::vector<const char *> instance_layer_names;
272 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600273 std::vector<const char *> instance_extension_names;
274 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600275
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700276 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600277 /*
278 * Since CreateDbgMsgCallback is an instance level extension call
279 * any extension / layer that utilizes that feature also needs
280 * to be enabled at create instance time.
281 */
Karl Schultz6addd812016-02-02 17:17:23 -0700282 // Use Threading layer first to protect others from
283 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700284 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600285 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800286 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700287 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800288 instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
289 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600290 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700291 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600292
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700293 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600294 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800295 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700296 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800297 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
298 device_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600299 device_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700300 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Tony Barbour300a6082015-04-07 13:44:53 -0600301
Ian Elliott2c1daf52016-05-12 09:41:46 -0600302 if (m_enableWSI) {
303 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
304 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
305#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
306#if defined(VK_USE_PLATFORM_ANDROID_KHR)
307 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
308#endif // VK_USE_PLATFORM_ANDROID_KHR
309#if defined(VK_USE_PLATFORM_MIR_KHR)
310 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
311#endif // VK_USE_PLATFORM_MIR_KHR
312#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
313 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
314#endif // VK_USE_PLATFORM_WAYLAND_KHR
315#if defined(VK_USE_PLATFORM_WIN32_KHR)
316 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
317#endif // VK_USE_PLATFORM_WIN32_KHR
318#endif // NEED_TO_TEST_THIS_ON_PLATFORM
319#if defined(VK_USE_PLATFORM_XCB_KHR)
320 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
321#elif defined(VK_USE_PLATFORM_XLIB_KHR)
322 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
323#endif // VK_USE_PLATFORM_XLIB_KHR
324 }
325
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600326 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600327 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800328 this->app_info.pApplicationName = "layer_tests";
329 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600330 this->app_info.pEngineName = "unittest";
331 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600332 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600333
Tony Barbour15524c32015-04-29 17:34:29 -0600334 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600335 InitFramework(instance_layer_names, device_layer_names,
336 instance_extension_names, device_extension_names,
337 myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600338 }
339
340 virtual void TearDown() {
341 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600342 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600343 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600344 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600345
346 VkLayerTest() {
347 m_enableWSI = false;
348 }
Tony Barbour300a6082015-04-07 13:44:53 -0600349};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500350
Karl Schultz6addd812016-02-02 17:17:23 -0700351VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600352 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600353
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800354 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600355
356 /*
357 * For render test all drawing happens in a single render pass
358 * on a single command buffer.
359 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200360 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800361 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600362 }
363
364 return result;
365}
366
Karl Schultz6addd812016-02-02 17:17:23 -0700367VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600368 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600369
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200370 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800371 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200372 }
Tony Barbour300a6082015-04-07 13:44:53 -0600373
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800374 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600375
376 return result;
377}
378
Karl Schultz6addd812016-02-02 17:17:23 -0700379void VkLayerTest::VKTriangleTest(const char *vertShaderText,
380 const char *fragShaderText,
381 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500382 // Create identity matrix
383 int i;
384 struct vktriangle_vs_uniform data;
385
386 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700387 glm::mat4 View = glm::mat4(1.0f);
388 glm::mat4 Model = glm::mat4(1.0f);
389 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500390 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700391 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500392
393 memcpy(&data.mvp, &MVP[0][0], matrixSize);
394
Karl Schultz6addd812016-02-02 17:17:23 -0700395 static const Vertex tri_data[] = {
396 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)},
397 {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)},
398 {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500399 };
400
Karl Schultz6addd812016-02-02 17:17:23 -0700401 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500402 data.position[i][0] = tri_data[i].posX;
403 data.position[i][1] = tri_data[i].posY;
404 data.position[i][2] = tri_data[i].posZ;
405 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700406 data.color[i][0] = tri_data[i].r;
407 data.color[i][1] = tri_data[i].g;
408 data.color[i][2] = tri_data[i].b;
409 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500410 }
411
412 ASSERT_NO_FATAL_FAILURE(InitState());
413 ASSERT_NO_FATAL_FAILURE(InitViewport());
414
Karl Schultz6addd812016-02-02 17:17:23 -0700415 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float),
416 (const void *)&data);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500417
Karl Schultz6addd812016-02-02 17:17:23 -0700418 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
419 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
420 this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500421
422 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800423 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500424 pipelineobj.AddShader(&vs);
425 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600426 if (failMask & BsoFailLineWidth) {
427 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600428 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
429 ia_state.sType =
430 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
431 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
432 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600433 }
434 if (failMask & BsoFailDepthBias) {
435 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600436 VkPipelineRasterizationStateCreateInfo rs_state = {};
437 rs_state.sType =
438 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
439 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600440 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600441 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600442 }
Karl Schultz6addd812016-02-02 17:17:23 -0700443 // Viewport and scissors must stay in synch or other errors will occur than
444 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600445 if (failMask & BsoFailViewport) {
446 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600447 m_viewports.clear();
448 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600449 }
450 if (failMask & BsoFailScissor) {
451 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600452 m_scissors.clear();
453 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600454 }
455 if (failMask & BsoFailBlend) {
456 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600457 VkPipelineColorBlendAttachmentState att_state = {};
458 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
459 att_state.blendEnable = VK_TRUE;
460 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600461 }
462 if (failMask & BsoFailDepthBounds) {
463 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
464 }
465 if (failMask & BsoFailStencilReadMask) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
467 }
468 if (failMask & BsoFailStencilWriteMask) {
469 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
470 }
471 if (failMask & BsoFailStencilReference) {
472 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
473 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500474
475 VkDescriptorSetObj descriptorSet(m_device);
Karl Schultz6addd812016-02-02 17:17:23 -0700476 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
477 constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500478
479 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600480 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500481
Tony Barbourfe3351b2015-07-28 10:17:20 -0600482 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500483
484 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600485 Draw(3, 1, 0, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500486
487 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600488 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500489
Tony Barbourfe3351b2015-07-28 10:17:20 -0600490 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500491}
492
Karl Schultz6addd812016-02-02 17:17:23 -0700493void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
494 VkPipelineObj &pipelineobj,
495 VkDescriptorSetObj &descriptorSet,
496 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500497 if (m_depthStencil->Initialized()) {
Karl Schultz6addd812016-02-02 17:17:23 -0700498 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
499 m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500 } else {
Karl Schultz6addd812016-02-02 17:17:23 -0700501 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
502 m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503 }
504
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800505 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700506 // Make sure depthWriteEnable is set so that Depth fail test will work
507 // correctly
508 // Make sure stencilTestEnable is set so that Stencil fail test will work
509 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600510 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800511 stencil.failOp = VK_STENCIL_OP_KEEP;
512 stencil.passOp = VK_STENCIL_OP_KEEP;
513 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
514 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600515
516 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
517 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600518 ds_ci.pNext = NULL;
519 ds_ci.depthTestEnable = VK_FALSE;
520 ds_ci.depthWriteEnable = VK_TRUE;
521 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
522 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600523 if (failMask & BsoFailDepthBounds) {
524 ds_ci.depthBoundsTestEnable = VK_TRUE;
525 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600526 ds_ci.stencilTestEnable = VK_TRUE;
527 ds_ci.front = stencil;
528 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600529
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600530 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600531 pipelineobj.SetViewport(m_viewports);
532 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800533 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700534 VkResult err = pipelineobj.CreateVKPipeline(
535 descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600536 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800537 commandBuffer->BindPipeline(pipelineobj);
538 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500539}
540
Ian Elliott2c1daf52016-05-12 09:41:46 -0600541class VkWsiEnabledLayerTest : public VkLayerTest {
542 public:
543protected:
544 VkWsiEnabledLayerTest() {
545 m_enableWSI = true;
546 }
547};
548
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500549// ********************************************************************************************************************
550// ********************************************************************************************************************
551// ********************************************************************************************************************
552// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600553#if PARAMETER_VALIDATION_TESTS
554TEST_F(VkLayerTest, RequiredParameter) {
555 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
556 "pointer, array, and array count parameters");
557
558 ASSERT_NO_FATAL_FAILURE(InitState());
559
560 m_errorMonitor->SetDesiredFailureMsg(
561 VK_DEBUG_REPORT_ERROR_BIT_EXT,
562 "required parameter pFeatures specified as NULL");
563 // Specify NULL for a pointer to a handle
564 // Expected to trigger an error with
565 // parameter_validation::validate_required_pointer
566 vkGetPhysicalDeviceFeatures(gpu(), NULL);
567 m_errorMonitor->VerifyFound();
568
569 m_errorMonitor->SetDesiredFailureMsg(
570 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600571 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600572 // Specify NULL for pointer to array count
573 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600574 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600575 m_errorMonitor->VerifyFound();
576
577 m_errorMonitor->SetDesiredFailureMsg(
578 VK_DEBUG_REPORT_ERROR_BIT_EXT,
579 "parameter viewportCount must be greater than 0");
580 // Specify 0 for a required array count
581 // Expected to trigger an error with parameter_validation::validate_array
582 VkViewport view_port = {};
583 m_commandBuffer->SetViewport(0, 0, &view_port);
584 m_errorMonitor->VerifyFound();
585
586 m_errorMonitor->SetDesiredFailureMsg(
587 VK_DEBUG_REPORT_ERROR_BIT_EXT,
588 "required parameter pViewports specified as NULL");
589 // Specify NULL for a required array
590 // Expected to trigger an error with parameter_validation::validate_array
591 m_commandBuffer->SetViewport(0, 1, NULL);
592 m_errorMonitor->VerifyFound();
593
594 m_errorMonitor->SetDesiredFailureMsg(
595 VK_DEBUG_REPORT_ERROR_BIT_EXT,
596 "required parameter memory specified as VK_NULL_HANDLE");
597 // Specify VK_NULL_HANDLE for a required handle
598 // Expected to trigger an error with
599 // parameter_validation::validate_required_handle
600 vkUnmapMemory(device(), VK_NULL_HANDLE);
601 m_errorMonitor->VerifyFound();
602
603 m_errorMonitor->SetDesiredFailureMsg(
604 VK_DEBUG_REPORT_ERROR_BIT_EXT,
605 "required parameter pFences[0] specified as VK_NULL_HANDLE");
606 // Specify VK_NULL_HANDLE for a required handle array entry
607 // Expected to trigger an error with
608 // parameter_validation::validate_required_handle_array
609 VkFence fence = VK_NULL_HANDLE;
610 vkResetFences(device(), 1, &fence);
611 m_errorMonitor->VerifyFound();
612
613 m_errorMonitor->SetDesiredFailureMsg(
614 VK_DEBUG_REPORT_ERROR_BIT_EXT,
615 "required parameter pAllocateInfo specified as NULL");
616 // Specify NULL for a required struct pointer
617 // Expected to trigger an error with
618 // parameter_validation::validate_struct_type
619 VkDeviceMemory memory = VK_NULL_HANDLE;
620 vkAllocateMemory(device(), NULL, NULL, &memory);
621 m_errorMonitor->VerifyFound();
622
623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
624 "value of faceMask must not be 0");
625 // Specify 0 for a required VkFlags parameter
626 // Expected to trigger an error with parameter_validation::validate_flags
627 m_commandBuffer->SetStencilReference(0, 0);
628 m_errorMonitor->VerifyFound();
629
630 m_errorMonitor->SetDesiredFailureMsg(
631 VK_DEBUG_REPORT_ERROR_BIT_EXT,
632 "value of pSubmits[i].pWaitDstStageMask[0] must not be 0");
633 // Specify 0 for a required VkFlags array entry
634 // Expected to trigger an error with
635 // parameter_validation::validate_flags_array
636 VkSemaphore semaphore = VK_NULL_HANDLE;
637 VkPipelineStageFlags stageFlags = 0;
638 VkSubmitInfo submitInfo = {};
639 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
640 submitInfo.waitSemaphoreCount = 1;
641 submitInfo.pWaitSemaphores = &semaphore;
642 submitInfo.pWaitDstStageMask = &stageFlags;
643 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
644 m_errorMonitor->VerifyFound();
645}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600646
Dustin Gravesfce74c02016-05-10 11:42:58 -0600647TEST_F(VkLayerTest, ReservedParameter) {
648 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
649
650 ASSERT_NO_FATAL_FAILURE(InitState());
651
652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
653 " must be 0");
654 // Specify 0 for a reserved VkFlags parameter
655 // Expected to trigger an error with
656 // parameter_validation::validate_reserved_flags
657 VkEvent event_handle = VK_NULL_HANDLE;
658 VkEventCreateInfo event_info = {};
659 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
660 event_info.flags = 1;
661 vkCreateEvent(device(), &event_info, NULL, &event_handle);
662 m_errorMonitor->VerifyFound();
663}
664
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600665TEST_F(VkLayerTest, InvalidStructSType) {
666 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
667 "structure's sType field");
668
669 ASSERT_NO_FATAL_FAILURE(InitState());
670
671 m_errorMonitor->SetDesiredFailureMsg(
672 VK_DEBUG_REPORT_ERROR_BIT_EXT,
673 "parameter pAllocateInfo->sType must be");
674 // Zero struct memory, effectively setting sType to
675 // VK_STRUCTURE_TYPE_APPLICATION_INFO
676 // Expected to trigger an error with
677 // parameter_validation::validate_struct_type
678 VkMemoryAllocateInfo alloc_info = {};
679 VkDeviceMemory memory = VK_NULL_HANDLE;
680 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
681 m_errorMonitor->VerifyFound();
682
683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
684 "parameter pSubmits[0].sType must be");
685 // Zero struct memory, effectively setting sType to
686 // VK_STRUCTURE_TYPE_APPLICATION_INFO
687 // Expected to trigger an error with
688 // parameter_validation::validate_struct_type_array
689 VkSubmitInfo submit_info = {};
690 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
691 m_errorMonitor->VerifyFound();
692}
693
694TEST_F(VkLayerTest, InvalidStructPNext) {
695 TEST_DESCRIPTION(
696 "Specify an invalid value for a Vulkan structure's pNext field");
697
698 ASSERT_NO_FATAL_FAILURE(InitState());
699
700 m_errorMonitor->SetDesiredFailureMsg(
701 VK_DEBUG_REPORT_ERROR_BIT_EXT,
702 "value of pAllocateInfo->pNext must be NULL");
703 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
704 // NULL
705 // Expected to trigger an error with
706 // parameter_validation::validate_struct_pnext
707 VkDeviceMemory memory = VK_NULL_HANDLE;
708 // Zero-initialization will provide the correct sType
709 VkApplicationInfo app_info = {};
Dustin Graves47b6cba2016-05-10 17:34:38 -0600710 VkMemoryAllocateInfo memory_alloc_info = {};
711 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
712 memory_alloc_info.pNext = &app_info;
713 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600714 m_errorMonitor->VerifyFound();
715
Dustin Graves47b6cba2016-05-10 17:34:38 -0600716 m_errorMonitor->SetDesiredFailureMsg(
717 VK_DEBUG_REPORT_ERROR_BIT_EXT,
718 " chain includes a structure with unexpected VkStructureType ");
719 // Set VkGraphicsPipelineCreateInfo::VkPipelineRasterizationStateCreateInfo::pNext to an invalid structure, when pNext is allowed to be a non-NULL value
720 // Expected to trigger an error with
721 // parameter_validation::validate_struct_pnext
722 VkDescriptorPoolSize ds_type_count = {};
723 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
724 ds_type_count.descriptorCount = 1;
725
726 VkDescriptorPoolCreateInfo ds_pool_ci = {};
727 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
728 ds_pool_ci.pNext = NULL;
729 ds_pool_ci.maxSets = 1;
730 ds_pool_ci.poolSizeCount = 1;
731 ds_pool_ci.pPoolSizes = &ds_type_count;
732
733 VkDescriptorPool ds_pool;
734 VkResult err =
735 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
736 ASSERT_VK_SUCCESS(err);
737
738 VkDescriptorSetLayoutBinding dsl_binding = {};
739 dsl_binding.binding = 0;
740 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
741 dsl_binding.descriptorCount = 1;
742 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
743 dsl_binding.pImmutableSamplers = NULL;
744
745 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
746 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
747 ds_layout_ci.pNext = NULL;
748 ds_layout_ci.bindingCount = 1;
749 ds_layout_ci.pBindings = &dsl_binding;
750
751 VkDescriptorSetLayout ds_layout;
752 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
753 &ds_layout);
754 ASSERT_VK_SUCCESS(err);
755
756 VkDescriptorSet descriptorSet;
757 VkDescriptorSetAllocateInfo ds_alloc_info = {};
758 ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
759 ds_alloc_info.descriptorSetCount = 1;
760 ds_alloc_info.descriptorPool = ds_pool;
761 ds_alloc_info.pSetLayouts = &ds_layout;
762 err = vkAllocateDescriptorSets(m_device->device(), &ds_alloc_info,
763 &descriptorSet);
764 ASSERT_VK_SUCCESS(err);
765
766 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
767 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
768 pipeline_layout_ci.setLayoutCount = 1;
769 pipeline_layout_ci.pSetLayouts = &ds_layout;
770
771 VkPipelineLayout pipeline_layout;
772 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
773 &pipeline_layout);
774 ASSERT_VK_SUCCESS(err);
775
776 VkViewport vp = {}; // Just need dummy vp to point to
777 VkRect2D sc = {}; // dummy scissor to point to
778
779 VkPipelineViewportStateCreateInfo vp_state_ci = {};
780 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
781 vp_state_ci.scissorCount = 1;
782 vp_state_ci.pScissors = &sc;
783 vp_state_ci.viewportCount = 1;
784 vp_state_ci.pViewports = &vp;
785
786 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
787 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
788 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
789 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
790 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
791 rs_state_ci.depthClampEnable = VK_FALSE;
792 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
793 rs_state_ci.depthBiasEnable = VK_FALSE;
794
795 VkGraphicsPipelineCreateInfo gp_ci = {};
796 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
797 gp_ci.pViewportState = &vp_state_ci;
798 gp_ci.pRasterizationState = &rs_state_ci;
799 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
800 gp_ci.layout = pipeline_layout;
801 gp_ci.renderPass = renderPass();
802
803 VkPipelineCacheCreateInfo pc_ci = {};
804 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
805 pc_ci.initialDataSize = 0;
806 pc_ci.pInitialData = 0;
807
808 VkPipeline pipeline;
809 VkPipelineCache pipelineCache;
810
811 err =
812 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
813 ASSERT_VK_SUCCESS(err);
814
815 // Set VkPipelineRasterizationStateCreateInfo::pNext to an invalid value
816 VkApplicationInfo invalid_pnext_struct = {};
817 rs_state_ci.pNext = &invalid_pnext_struct;
818
819 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
820 &gp_ci, NULL, &pipeline);
821 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600822}
Dustin Graves5d33d532016-05-09 16:21:12 -0600823
824TEST_F(VkLayerTest, UnrecognizedValue) {
825 TEST_DESCRIPTION(
826 "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
827
828 ASSERT_NO_FATAL_FAILURE(InitState());
829
830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
831 "does not fall within the begin..end "
832 "range of the core VkFormat "
833 "enumeration tokens");
834 // Specify an invalid VkFormat value
835 // Expected to trigger an error with
836 // parameter_validation::validate_ranged_enum
837 VkFormatProperties format_properties;
838 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000),
839 &format_properties);
840 m_errorMonitor->VerifyFound();
841
842 m_errorMonitor->SetDesiredFailureMsg(
843 VK_DEBUG_REPORT_ERROR_BIT_EXT,
844 "contains flag bits that are not recognized members of");
845 // Specify an invalid VkFlags bitmask value
846 // Expected to trigger an error with parameter_validation::validate_flags
847 VkImageFormatProperties image_format_properties;
848 vkGetPhysicalDeviceImageFormatProperties(
849 gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D,
850 VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0,
851 &image_format_properties);
852 m_errorMonitor->VerifyFound();
853
854 m_errorMonitor->SetDesiredFailureMsg(
855 VK_DEBUG_REPORT_ERROR_BIT_EXT,
856 "contains flag bits that are not recognized members of");
857 // Specify an invalid VkFlags array entry
858 // Expected to trigger an error with
859 // parameter_validation::validate_flags_array
860 VkSemaphore semaphore = VK_NULL_HANDLE;
861 VkPipelineStageFlags stage_flags =
862 static_cast<VkPipelineStageFlags>(1 << 25);
863 VkSubmitInfo submit_info = {};
864 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
865 submit_info.waitSemaphoreCount = 1;
866 submit_info.pWaitSemaphores = &semaphore;
867 submit_info.pWaitDstStageMask = &stage_flags;
868 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
869 m_errorMonitor->VerifyFound();
870
871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
872 "is neither VK_TRUE nor VK_FALSE");
873 // Specify an invalid VkBool32 value
874 // Expected to trigger a warning with
875 // parameter_validation::validate_bool32
876 VkSampler sampler = VK_NULL_HANDLE;
877 VkSamplerCreateInfo sampler_info = {};
878 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
879 sampler_info.pNext = NULL;
880 sampler_info.magFilter = VK_FILTER_NEAREST;
881 sampler_info.minFilter = VK_FILTER_NEAREST;
882 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
883 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
884 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
885 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
886 sampler_info.mipLodBias = 1.0;
887 sampler_info.maxAnisotropy = 1;
888 sampler_info.compareEnable = VK_FALSE;
889 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
890 sampler_info.minLod = 1.0;
891 sampler_info.maxLod = 1.0;
892 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
893 sampler_info.unnormalizedCoordinates = VK_FALSE;
894 // Not VK_TRUE or VK_FALSE
895 sampler_info.anisotropyEnable = 3;
896 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
897 m_errorMonitor->VerifyFound();
898}
Dustin Gravesfce74c02016-05-10 11:42:58 -0600899
900TEST_F(VkLayerTest, FailedReturnValue) {
901 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
902
903 ASSERT_NO_FATAL_FAILURE(InitState());
904
Dustin Graves13c1e2b2016-05-16 15:31:02 -0600905 // Find an unsupported image format
906 VkFormat unsupported = VK_FORMAT_UNDEFINED;
907 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
908 VkFormat format = static_cast<VkFormat>(f);
909 VkFormatProperties fProps = m_device->format_properties(format);
910 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
911 fProps.optimalTilingFeatures == 0) {
912 unsupported = format;
913 break;
914 }
915 }
916
917 if (unsupported != VK_FORMAT_UNDEFINED) {
918 m_errorMonitor->SetDesiredFailureMsg(
919 VK_DEBUG_REPORT_WARNING_BIT_EXT,
920 "the requested format is not supported on this device");
921 // Specify an unsupported VkFormat value to generate a
922 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
923 // Expected to trigger a warning from
924 // parameter_validation::validate_result
925 VkImageFormatProperties image_format_properties;
926 VkResult err = vkGetPhysicalDeviceImageFormatProperties(
927 gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
928 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
929 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
930 m_errorMonitor->VerifyFound();
931 }
Dustin Gravesfce74c02016-05-10 11:42:58 -0600932}
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600933#endif // PARAMETER_VALIDATION_TESTS
934
Tobin Ehlis0788f522015-05-26 16:11:58 -0600935#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -0700936#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800937TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500938{
939 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500940 VkFenceCreateInfo fenceInfo = {};
941 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
942 fenceInfo.pNext = NULL;
943 fenceInfo.flags = 0;
944
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600946
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500947 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -0600948
949 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
950 vk_testing::Buffer buffer;
951 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500952
Tony Barbourfe3351b2015-07-28 10:17:20 -0600953 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800954 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600955 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500956
957 testFence.init(*m_device, fenceInfo);
958
959 // Bypass framework since it does the waits automatically
960 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600961 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800962 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
963 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800964 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600965 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -0700966 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800967 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800968 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800969 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600970 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600971
972 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500973 ASSERT_VK_SUCCESS( err );
974
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500975 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800976 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500977
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200978 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500979}
980
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800981TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500982{
983 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500984 VkFenceCreateInfo fenceInfo = {};
985 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
986 fenceInfo.pNext = NULL;
987 fenceInfo.flags = 0;
988
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600990
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500991 ASSERT_NO_FATAL_FAILURE(InitState());
992 ASSERT_NO_FATAL_FAILURE(InitViewport());
993 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
994
Tony Barbourfe3351b2015-07-28 10:17:20 -0600995 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800996 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600997 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500998
999 testFence.init(*m_device, fenceInfo);
1000
1001 // Bypass framework since it does the waits automatically
1002 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001003 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001004 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1005 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001006 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001007 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001008 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001009 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001010 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001011 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001012 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001013
1014 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001015 ASSERT_VK_SUCCESS( err );
1016
Jon Ashburnf19916e2016-01-11 13:12:43 -07001017 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001018 VkCommandBufferBeginInfo info = {};
1019 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1020 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001021 info.renderPass = VK_NULL_HANDLE;
1022 info.subpass = 0;
1023 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001024 info.occlusionQueryEnable = VK_FALSE;
1025 info.queryFlags = 0;
1026 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001027
1028 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001029 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001030
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001031 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001032}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001033#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001034
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001035// This is a positive test. No failures are expected.
1036TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1037 VkResult err;
1038 bool pass;
1039
1040 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1041 "the buffer, create an image, and bind the same memory to "
1042 "it");
1043
1044 m_errorMonitor->ExpectSuccess();
1045
1046 ASSERT_NO_FATAL_FAILURE(InitState());
1047
1048 VkBuffer buffer;
1049 VkImage image;
1050 VkDeviceMemory mem;
1051 VkMemoryRequirements mem_reqs;
1052
1053 VkBufferCreateInfo buf_info = {};
1054 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1055 buf_info.pNext = NULL;
1056 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1057 buf_info.size = 256;
1058 buf_info.queueFamilyIndexCount = 0;
1059 buf_info.pQueueFamilyIndices = NULL;
1060 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1061 buf_info.flags = 0;
1062 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1063 ASSERT_VK_SUCCESS(err);
1064
1065 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1066
1067 VkMemoryAllocateInfo alloc_info = {};
1068 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1069 alloc_info.pNext = NULL;
1070 alloc_info.memoryTypeIndex = 0;
1071
1072 // Ensure memory is big enough for both bindings
1073 alloc_info.allocationSize = 0x10000;
1074
1075 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1076 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1077 if (!pass) {
1078 vkDestroyBuffer(m_device->device(), buffer, NULL);
1079 return;
1080 }
1081
1082 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1083 ASSERT_VK_SUCCESS(err);
1084
1085 uint8_t *pData;
1086 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1087 (void **)&pData);
1088 ASSERT_VK_SUCCESS(err);
1089
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001090 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001091
1092 vkUnmapMemory(m_device->device(), mem);
1093
1094 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1095 ASSERT_VK_SUCCESS(err);
1096
1097 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1098 // memory. In fact, it was never used by the GPU.
1099 // Just be be sure, wait for idle.
1100 vkDestroyBuffer(m_device->device(), buffer, NULL);
1101 vkDeviceWaitIdle(m_device->device());
1102
1103 VkImageCreateInfo image_create_info = {};
1104 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1105 image_create_info.pNext = NULL;
1106 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1107 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1108 image_create_info.extent.width = 64;
1109 image_create_info.extent.height = 64;
1110 image_create_info.extent.depth = 1;
1111 image_create_info.mipLevels = 1;
1112 image_create_info.arrayLayers = 1;
1113 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1114 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1115 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1116 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1117 image_create_info.queueFamilyIndexCount = 0;
1118 image_create_info.pQueueFamilyIndices = NULL;
1119 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1120 image_create_info.flags = 0;
1121
1122 VkMemoryAllocateInfo mem_alloc = {};
1123 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1124 mem_alloc.pNext = NULL;
1125 mem_alloc.allocationSize = 0;
1126 mem_alloc.memoryTypeIndex = 0;
1127
1128 /* Create a mappable image. It will be the texture if linear images are ok
1129 * to be textures or it will be the staging image if they are not.
1130 */
1131 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1132 ASSERT_VK_SUCCESS(err);
1133
1134 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1135
1136 mem_alloc.allocationSize = mem_reqs.size;
1137
1138 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc,
1139 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1140 if (!pass) {
1141 vkDestroyImage(m_device->device(), image, NULL);
1142 return;
1143 }
1144
Tobin Ehlis077ded32016-05-12 17:39:13 -06001145 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001146 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1147 ASSERT_VK_SUCCESS(err);
1148
1149 m_errorMonitor->VerifyNotFound();
1150
1151 vkDestroyBuffer(m_device->device(), buffer, NULL);
1152 vkDestroyImage(m_device->device(), image, NULL);
1153}
1154
Tobin Ehlisf11be982016-05-11 13:52:53 -06001155TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1156 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1157 "buffer and image to memory such that they will alias.");
1158 VkResult err;
1159 bool pass;
1160 ASSERT_NO_FATAL_FAILURE(InitState());
1161
Tobin Ehlis077ded32016-05-12 17:39:13 -06001162 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001163 VkImage image;
1164 VkDeviceMemory mem; // buffer will be bound first
1165 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001166 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001167
1168 VkBufferCreateInfo buf_info = {};
1169 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1170 buf_info.pNext = NULL;
1171 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1172 buf_info.size = 256;
1173 buf_info.queueFamilyIndexCount = 0;
1174 buf_info.pQueueFamilyIndices = NULL;
1175 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1176 buf_info.flags = 0;
1177 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1178 ASSERT_VK_SUCCESS(err);
1179
Tobin Ehlis077ded32016-05-12 17:39:13 -06001180 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001181
1182 VkImageCreateInfo image_create_info = {};
1183 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1184 image_create_info.pNext = NULL;
1185 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1186 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1187 image_create_info.extent.width = 64;
1188 image_create_info.extent.height = 64;
1189 image_create_info.extent.depth = 1;
1190 image_create_info.mipLevels = 1;
1191 image_create_info.arrayLayers = 1;
1192 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1193 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1194 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1195 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1196 image_create_info.queueFamilyIndexCount = 0;
1197 image_create_info.pQueueFamilyIndices = NULL;
1198 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1199 image_create_info.flags = 0;
1200
Tobin Ehlisf11be982016-05-11 13:52:53 -06001201 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1202 ASSERT_VK_SUCCESS(err);
1203
Tobin Ehlis077ded32016-05-12 17:39:13 -06001204 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1205
1206 VkMemoryAllocateInfo alloc_info = {};
1207 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1208 alloc_info.pNext = NULL;
1209 alloc_info.memoryTypeIndex = 0;
1210 // Ensure memory is big enough for both bindings
1211 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
1212 pass = m_device->phy().set_memory_type(
1213 buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info,
1214 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001215 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001216 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001217 vkDestroyImage(m_device->device(), image, NULL);
1218 return;
1219 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001220 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1221 ASSERT_VK_SUCCESS(err);
1222 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1223 ASSERT_VK_SUCCESS(err);
1224
Tobin Ehlisf11be982016-05-11 13:52:53 -06001225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1226 " is aliased with buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001227 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001228 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1229 m_errorMonitor->VerifyFound();
1230
1231 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001232 // aliasing buffer2
1233 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1234 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001235 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1236 ASSERT_VK_SUCCESS(err);
1237 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1238 ASSERT_VK_SUCCESS(err);
1239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1240 " is aliased with image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001241 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001242 m_errorMonitor->VerifyFound();
1243
1244 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001245 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001246 vkDestroyImage(m_device->device(), image, NULL);
1247 vkFreeMemory(m_device->device(), mem, NULL);
1248 vkFreeMemory(m_device->device(), mem_img, NULL);
1249}
1250
Tobin Ehlis35372522016-05-12 08:32:31 -06001251TEST_F(VkLayerTest, InvalidMemoryMapping) {
1252 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1253 VkResult err;
1254 bool pass;
1255 ASSERT_NO_FATAL_FAILURE(InitState());
1256
1257 VkBuffer buffer;
1258 VkDeviceMemory mem;
1259 VkMemoryRequirements mem_reqs;
1260
1261 VkBufferCreateInfo buf_info = {};
1262 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1263 buf_info.pNext = NULL;
1264 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1265 buf_info.size = 256;
1266 buf_info.queueFamilyIndexCount = 0;
1267 buf_info.pQueueFamilyIndices = NULL;
1268 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1269 buf_info.flags = 0;
1270 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1271 ASSERT_VK_SUCCESS(err);
1272
1273 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1274 VkMemoryAllocateInfo alloc_info = {};
1275 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1276 alloc_info.pNext = NULL;
1277 alloc_info.memoryTypeIndex = 0;
1278
1279 // Ensure memory is big enough for both bindings
1280 static const VkDeviceSize allocation_size = 0x10000;
1281 alloc_info.allocationSize = allocation_size;
1282 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1283 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1284 if (!pass) {
1285 vkDestroyBuffer(m_device->device(), buffer, NULL);
1286 return;
1287 }
1288 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1289 ASSERT_VK_SUCCESS(err);
1290
1291 uint8_t *pData;
1292 // Attempt to map memory size 0 is invalid
1293 m_errorMonitor->SetDesiredFailureMsg(
1294 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1295 "VkMapMemory: Attempting to map memory range of size zero");
1296 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1297 m_errorMonitor->VerifyFound();
1298 // Map memory twice
1299 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1300 (void **)&pData);
1301 ASSERT_VK_SUCCESS(err);
1302 m_errorMonitor->SetDesiredFailureMsg(
1303 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1304 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1305 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1306 (void **)&pData);
1307 m_errorMonitor->VerifyFound();
1308
1309 // Unmap the memory to avoid re-map error
1310 vkUnmapMemory(m_device->device(), mem);
1311 // overstep allocation with VK_WHOLE_SIZE
1312 m_errorMonitor->SetDesiredFailureMsg(
1313 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1314 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1315 err = vkMapMemory(m_device->device(), mem, allocation_size + 1,
1316 VK_WHOLE_SIZE, 0, (void **)&pData);
1317 m_errorMonitor->VerifyFound();
1318 // overstep allocation w/o VK_WHOLE_SIZE
1319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1320 " oversteps total array size 0x");
1321 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0,
1322 (void **)&pData);
1323 m_errorMonitor->VerifyFound();
1324 // Now error due to unmapping memory that's not mapped
1325 m_errorMonitor->SetDesiredFailureMsg(
1326 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1327 "Unmapping Memory without memory being mapped: ");
1328 vkUnmapMemory(m_device->device(), mem);
1329 m_errorMonitor->VerifyFound();
1330 // Now map memory and cause errors due to flushing invalid ranges
1331 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0,
1332 (void **)&pData);
1333 ASSERT_VK_SUCCESS(err);
1334 VkMappedMemoryRange mmr = {};
1335 mmr.memory = mem;
1336 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
1337 m_errorMonitor->SetDesiredFailureMsg(
1338 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1339 ") is less than Memory Object's offset (");
1340 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1341 m_errorMonitor->VerifyFound();
1342 // Now flush range that oversteps mapped range
1343 vkUnmapMemory(m_device->device(), mem);
1344 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1345 ASSERT_VK_SUCCESS(err);
1346 mmr.offset = 16;
1347 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
1348 m_errorMonitor->SetDesiredFailureMsg(
1349 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1350 ") exceeds the Memory Object's upper-bound (");
1351 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1352 m_errorMonitor->VerifyFound();
1353
1354 pass =
1355 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1356 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1357 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
1358 if (!pass) {
1359 vkFreeMemory(m_device->device(), mem, NULL);
1360 vkDestroyBuffer(m_device->device(), buffer, NULL);
1361 return;
1362 }
1363 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1364 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1365
1366 vkDestroyBuffer(m_device->device(), buffer, NULL);
1367 vkFreeMemory(m_device->device(), mem, NULL);
1368}
1369
Ian Elliott1c32c772016-04-28 14:47:13 -06001370TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1371 VkResult err;
1372 bool pass;
1373
Ian Elliott489eec02016-05-05 14:12:44 -06001374// FIXME: After we turn on this code for non-Linux platforms, uncomment the
1375// following declaration (which is temporarily being moved below):
1376// VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001377 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1378 VkSwapchainCreateInfoKHR swapchain_create_info = {};
1379 uint32_t swapchain_image_count = 0;
1380// VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1381 uint32_t image_index = 0;
1382// VkPresentInfoKHR present_info = {};
1383
1384 ASSERT_NO_FATAL_FAILURE(InitState());
1385
Ian Elliott3f06ce52016-04-29 14:46:21 -06001386#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1387#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1388 // Use the functions from the VK_KHR_android_surface extension without
1389 // enabling that extension:
1390
1391 // Create a surface:
1392 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001393 m_errorMonitor->SetDesiredFailureMsg(
1394 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1395 "extension was not enabled for this");
1396 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL,
1397 &surface);
1398 pass = (err != VK_SUCCESS);
1399 ASSERT_TRUE(pass);
1400 m_errorMonitor->VerifyFound();
1401#endif // VK_USE_PLATFORM_ANDROID_KHR
1402
1403
1404#if defined(VK_USE_PLATFORM_MIR_KHR)
1405 // Use the functions from the VK_KHR_mir_surface extension without enabling
1406 // that extension:
1407
1408 // Create a surface:
1409 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001410 m_errorMonitor->SetDesiredFailureMsg(
1411 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1412 "extension was not enabled for this");
1413 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1414 pass = (err != VK_SUCCESS);
1415 ASSERT_TRUE(pass);
1416 m_errorMonitor->VerifyFound();
1417
1418 // Tell whether an mir_connection supports presentation:
1419 MirConnection *mir_connection = NULL;
1420 m_errorMonitor->SetDesiredFailureMsg(
1421 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1422 "extension was not enabled for this");
1423 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection,
1424 visual_id);
1425 m_errorMonitor->VerifyFound();
1426#endif // VK_USE_PLATFORM_MIR_KHR
1427
1428
1429#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1430 // Use the functions from the VK_KHR_wayland_surface extension without
1431 // enabling that extension:
1432
1433 // Create a surface:
1434 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001435 m_errorMonitor->SetDesiredFailureMsg(
1436 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1437 "extension was not enabled for this");
1438 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL,
1439 &surface);
1440 pass = (err != VK_SUCCESS);
1441 ASSERT_TRUE(pass);
1442 m_errorMonitor->VerifyFound();
1443
1444 // Tell whether an wayland_display supports presentation:
1445 struct wl_display wayland_display = {};
1446 m_errorMonitor->SetDesiredFailureMsg(
1447 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1448 "extension was not enabled for this");
1449 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0,
1450 &wayland_display);
1451 m_errorMonitor->VerifyFound();
1452#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001453#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001454
1455
1456#if defined(VK_USE_PLATFORM_WIN32_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001457// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1458// TO NON-LINUX PLATFORMS:
1459VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001460 // Use the functions from the VK_KHR_win32_surface extension without
1461 // enabling that extension:
1462
1463 // Create a surface:
1464 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001465 m_errorMonitor->SetDesiredFailureMsg(
1466 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1467 "extension was not enabled for this");
1468 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL,
1469 &surface);
1470 pass = (err != VK_SUCCESS);
1471 ASSERT_TRUE(pass);
1472 m_errorMonitor->VerifyFound();
1473
1474 // Tell whether win32 supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001475 m_errorMonitor->SetDesiredFailureMsg(
1476 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1477 "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001478 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001479 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001480// Set this (for now, until all platforms are supported and tested):
1481#define NEED_TO_TEST_THIS_ON_PLATFORM
1482#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001483
1484
Ian Elliott1c32c772016-04-28 14:47:13 -06001485#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001486// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1487// TO NON-LINUX PLATFORMS:
1488VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001489 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1490 // that extension:
1491
1492 // Create a surface:
1493 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001494 m_errorMonitor->SetDesiredFailureMsg(
1495 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1496 "extension was not enabled for this");
1497 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1498 pass = (err != VK_SUCCESS);
1499 ASSERT_TRUE(pass);
1500 m_errorMonitor->VerifyFound();
1501
1502 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001503 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001504 xcb_visualid_t visual_id = 0;
1505 m_errorMonitor->SetDesiredFailureMsg(
1506 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1507 "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001508 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection,
Ian Elliott1c32c772016-04-28 14:47:13 -06001509 visual_id);
1510 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001511// Set this (for now, until all platforms are supported and tested):
1512#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001513#endif // VK_USE_PLATFORM_XCB_KHR
1514
1515
Ian Elliott12630812016-04-29 14:35:43 -06001516#if defined(VK_USE_PLATFORM_XLIB_KHR)
1517 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1518 // that extension:
1519
1520 // Create a surface:
1521 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Ian Elliott12630812016-04-29 14:35:43 -06001522 m_errorMonitor->SetDesiredFailureMsg(
1523 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1524 "extension was not enabled for this");
1525 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1526 pass = (err != VK_SUCCESS);
1527 ASSERT_TRUE(pass);
1528 m_errorMonitor->VerifyFound();
1529
1530 // Tell whether an Xlib VisualID supports presentation:
1531 Display *dpy = NULL;
1532 VisualID visual = 0;
1533 m_errorMonitor->SetDesiredFailureMsg(
1534 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1535 "extension was not enabled for this");
1536 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1537 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001538// Set this (for now, until all platforms are supported and tested):
1539#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001540#endif // VK_USE_PLATFORM_XLIB_KHR
1541
1542
Ian Elliott1c32c772016-04-28 14:47:13 -06001543 // Use the functions from the VK_KHR_surface extension without enabling
1544 // that extension:
1545
Ian Elliott489eec02016-05-05 14:12:44 -06001546#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001547 // Destroy a surface:
1548 m_errorMonitor->SetDesiredFailureMsg(
1549 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1550 "extension was not enabled for this");
1551 vkDestroySurfaceKHR(instance(), surface, NULL);
1552 m_errorMonitor->VerifyFound();
1553
1554 // Check if surface supports presentation:
1555 VkBool32 supported = false;
1556 m_errorMonitor->SetDesiredFailureMsg(
1557 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1558 "extension was not enabled for this");
1559 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1560 pass = (err != VK_SUCCESS);
1561 ASSERT_TRUE(pass);
1562 m_errorMonitor->VerifyFound();
1563
1564 // Check surface capabilities:
1565 VkSurfaceCapabilitiesKHR capabilities = {};
1566 m_errorMonitor->SetDesiredFailureMsg(
1567 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1568 "extension was not enabled for this");
1569 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1570 &capabilities);
1571 pass = (err != VK_SUCCESS);
1572 ASSERT_TRUE(pass);
1573 m_errorMonitor->VerifyFound();
1574
1575 // Check surface formats:
1576 uint32_t format_count = 0;
1577 VkSurfaceFormatKHR *formats = NULL;
1578 m_errorMonitor->SetDesiredFailureMsg(
1579 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1580 "extension was not enabled for this");
1581 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1582 &format_count, formats);
1583 pass = (err != VK_SUCCESS);
1584 ASSERT_TRUE(pass);
1585 m_errorMonitor->VerifyFound();
1586
1587 // Check surface present modes:
1588 uint32_t present_mode_count = 0;
1589 VkSurfaceFormatKHR *present_modes = NULL;
1590 m_errorMonitor->SetDesiredFailureMsg(
1591 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1592 "extension was not enabled for this");
1593 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1594 &present_mode_count, present_modes);
1595 pass = (err != VK_SUCCESS);
1596 ASSERT_TRUE(pass);
1597 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001598#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001599
1600
1601 // Use the functions from the VK_KHR_swapchain extension without enabling
1602 // that extension:
1603
1604 // Create a swapchain:
1605 m_errorMonitor->SetDesiredFailureMsg(
1606 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1607 "extension was not enabled for this");
1608 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1609 swapchain_create_info.pNext = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001610 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info,
1611 NULL, &swapchain);
1612 pass = (err != VK_SUCCESS);
1613 ASSERT_TRUE(pass);
1614 m_errorMonitor->VerifyFound();
1615
1616 // Get the images from the swapchain:
1617 m_errorMonitor->SetDesiredFailureMsg(
1618 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1619 "extension was not enabled for this");
1620 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain,
1621 &swapchain_image_count, NULL);
1622 pass = (err != VK_SUCCESS);
1623 ASSERT_TRUE(pass);
1624 m_errorMonitor->VerifyFound();
1625
1626 // Try to acquire an image:
1627 m_errorMonitor->SetDesiredFailureMsg(
1628 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1629 "extension was not enabled for this");
1630 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0,
1631 VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index);
1632 pass = (err != VK_SUCCESS);
1633 ASSERT_TRUE(pass);
1634 m_errorMonitor->VerifyFound();
1635
1636 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001637 //
1638 // NOTE: Currently can't test this because a real swapchain is needed (as
1639 // opposed to the fake one we created) in order for the layer to lookup the
1640 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001641
1642 // Destroy the swapchain:
1643 m_errorMonitor->SetDesiredFailureMsg(
1644 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1645 "extension was not enabled for this");
1646 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1647 m_errorMonitor->VerifyFound();
1648}
1649
Ian Elliott2c1daf52016-05-12 09:41:46 -06001650TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06001651
Dustin Graves6c6d8982016-05-17 10:09:21 -06001652#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06001653 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001654
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001655 VkResult err;
1656 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06001657 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1658 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001659 // uint32_t swapchain_image_count = 0;
1660 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1661 // uint32_t image_index = 0;
1662 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06001663
1664 ASSERT_NO_FATAL_FAILURE(InitState());
1665
1666 // Use the create function from one of the VK_KHR_*_surface extension in
1667 // order to create a surface, testing all known errors in the process,
1668 // before successfully creating a surface:
1669 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1671 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001672 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
1673 pass = (err != VK_SUCCESS);
1674 ASSERT_TRUE(pass);
1675 m_errorMonitor->VerifyFound();
1676
1677 // Next, try to create a surface with the wrong
1678 // VkXcbSurfaceCreateInfoKHR::sType:
1679 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
1680 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1682 "called with the wrong value for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001683 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1684 pass = (err != VK_SUCCESS);
1685 ASSERT_TRUE(pass);
1686 m_errorMonitor->VerifyFound();
1687
Ian Elliott2c1daf52016-05-12 09:41:46 -06001688 // Create a native window, and then correctly create a surface:
1689 xcb_connection_t *connection;
1690 xcb_screen_t *screen;
1691 xcb_window_t xcb_window;
1692 xcb_intern_atom_reply_t *atom_wm_delete_window;
1693
1694 const xcb_setup_t *setup;
1695 xcb_screen_iterator_t iter;
1696 int scr;
1697 uint32_t value_mask, value_list[32];
1698 int width = 1;
1699 int height = 1;
1700
1701 connection = xcb_connect(NULL, &scr);
1702 ASSERT_TRUE(connection != NULL);
1703 setup = xcb_get_setup(connection);
1704 iter = xcb_setup_roots_iterator(setup);
1705 while (scr-- > 0)
1706 xcb_screen_next(&iter);
1707 screen = iter.data;
1708
1709 xcb_window = xcb_generate_id(connection);
1710
1711 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
1712 value_list[0] = screen->black_pixel;
1713 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE |
1714 XCB_EVENT_MASK_STRUCTURE_NOTIFY;
1715
1716 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window,
1717 screen->root, 0, 0, width, height, 0,
1718 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual,
1719 value_mask, value_list);
1720
1721 /* Magic code that will send notification when window is destroyed */
1722 xcb_intern_atom_cookie_t cookie =
1723 xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
1724 xcb_intern_atom_reply_t *reply =
1725 xcb_intern_atom_reply(connection, cookie, 0);
1726
1727 xcb_intern_atom_cookie_t cookie2 =
1728 xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001729 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001730 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window,
1731 (*reply).atom, 4, 32, 1,
1732 &(*atom_wm_delete_window).atom);
1733 free(reply);
1734
1735 xcb_map_window(connection, xcb_window);
1736
1737 // Force the x/y coordinates to 100,100 results are identical in consecutive
1738 // runs
1739 const uint32_t coords[] = {100, 100};
1740 xcb_configure_window(connection, xcb_window,
1741 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
1742
Ian Elliott2c1daf52016-05-12 09:41:46 -06001743 // Finally, try to correctly create a surface:
1744 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
1745 xcb_create_info.pNext = NULL;
1746 xcb_create_info.flags = 0;
1747 xcb_create_info.connection = connection;
1748 xcb_create_info.window = xcb_window;
1749 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1750 pass = (err == VK_SUCCESS);
1751 ASSERT_TRUE(pass);
1752
Ian Elliott2c1daf52016-05-12 09:41:46 -06001753 // Check if surface supports presentation:
1754
1755 // 1st, do so without having queried the queue families:
1756 VkBool32 supported = false;
1757 // TODO: Get the following error to come out:
1758 m_errorMonitor->SetDesiredFailureMsg(
1759 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1760 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
1761 "function");
1762 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1763 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001764 // ASSERT_TRUE(pass);
1765 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06001766
1767 // Next, query a queue family index that's too large:
1768 m_errorMonitor->SetDesiredFailureMsg(
1769 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1770 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001771 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface,
1772 &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001773 pass = (err != VK_SUCCESS);
1774 ASSERT_TRUE(pass);
1775 m_errorMonitor->VerifyFound();
1776
1777 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001778 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
1779 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06001780 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1781 pass = (err == VK_SUCCESS);
1782 ASSERT_TRUE(pass);
1783
Ian Elliott2c1daf52016-05-12 09:41:46 -06001784 // Before proceeding, try to create a swapchain without having called
1785 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
1786 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1787 swapchain_create_info.pNext = NULL;
1788 swapchain_create_info.flags = 0;
1789 m_errorMonitor->SetDesiredFailureMsg(
1790 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1791 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001792 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1793 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001794 pass = (err != VK_SUCCESS);
1795 ASSERT_TRUE(pass);
1796 m_errorMonitor->VerifyFound();
1797
Ian Elliott2c1daf52016-05-12 09:41:46 -06001798 // Get the surface capabilities:
1799 VkSurfaceCapabilitiesKHR surface_capabilities;
1800
1801 // Do so correctly (only error logged by this entrypoint is if the
1802 // extension isn't enabled):
1803 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1804 &surface_capabilities);
1805 pass = (err == VK_SUCCESS);
1806 ASSERT_TRUE(pass);
1807
Ian Elliott2c1daf52016-05-12 09:41:46 -06001808 // Get the surface formats:
1809 uint32_t surface_format_count;
1810
1811 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1813 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001814 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
1815 pass = (err == VK_SUCCESS);
1816 ASSERT_TRUE(pass);
1817 m_errorMonitor->VerifyFound();
1818
1819 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
1820 // correctly done a 1st try (to get the count):
1821 m_errorMonitor->SetDesiredFailureMsg(
1822 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1823 "but no prior positive value has been seen for");
1824 surface_format_count = 0;
1825 vkGetPhysicalDeviceSurfaceFormatsKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001826 gpu(), surface, &surface_format_count,
1827 (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001828 pass = (err == VK_SUCCESS);
1829 ASSERT_TRUE(pass);
1830 m_errorMonitor->VerifyFound();
1831
1832 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001833 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1834 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001835 pass = (err == VK_SUCCESS);
1836 ASSERT_TRUE(pass);
1837
1838 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001839 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(
1840 surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001841
1842 // Next, do a 2nd try with surface_format_count being set too high:
1843 surface_format_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1845 "that is greater than the value");
1846 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001847 surface_formats);
1848 pass = (err == VK_SUCCESS);
1849 ASSERT_TRUE(pass);
1850 m_errorMonitor->VerifyFound();
1851
1852 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001853 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1854 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001855 pass = (err == VK_SUCCESS);
1856 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001857 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001858 surface_formats);
1859 pass = (err == VK_SUCCESS);
1860 ASSERT_TRUE(pass);
1861
Ian Elliott2c1daf52016-05-12 09:41:46 -06001862 // Get the surface present modes:
1863 uint32_t surface_present_mode_count;
1864
1865 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1867 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001868 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
1869 pass = (err == VK_SUCCESS);
1870 ASSERT_TRUE(pass);
1871 m_errorMonitor->VerifyFound();
1872
1873 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
1874 // correctly done a 1st try (to get the count):
1875 m_errorMonitor->SetDesiredFailureMsg(
1876 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1877 "but no prior positive value has been seen for");
1878 surface_present_mode_count = 0;
1879 vkGetPhysicalDeviceSurfacePresentModesKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001880 gpu(), surface, &surface_present_mode_count,
1881 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001882 pass = (err == VK_SUCCESS);
1883 ASSERT_TRUE(pass);
1884 m_errorMonitor->VerifyFound();
1885
1886 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001887 vkGetPhysicalDeviceSurfacePresentModesKHR(
1888 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001889 pass = (err == VK_SUCCESS);
1890 ASSERT_TRUE(pass);
1891
1892 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001893 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(
1894 surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001895
1896 // Next, do a 2nd try with surface_format_count being set too high:
1897 surface_present_mode_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1899 "that is greater than the value");
1900 vkGetPhysicalDeviceSurfacePresentModesKHR(
1901 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001902 pass = (err == VK_SUCCESS);
1903 ASSERT_TRUE(pass);
1904 m_errorMonitor->VerifyFound();
1905
1906 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001907 vkGetPhysicalDeviceSurfacePresentModesKHR(
1908 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001909 pass = (err == VK_SUCCESS);
1910 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001911 vkGetPhysicalDeviceSurfacePresentModesKHR(
1912 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001913 pass = (err == VK_SUCCESS);
1914 ASSERT_TRUE(pass);
1915
Ian Elliott2c1daf52016-05-12 09:41:46 -06001916 // Create a swapchain:
1917
1918 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1920 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001921 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
1922 pass = (err != VK_SUCCESS);
1923 ASSERT_TRUE(pass);
1924 m_errorMonitor->VerifyFound();
1925
1926 // Next, call with a non-NULL swapchain_create_info, that has the wrong
1927 // sType:
1928 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1930 "called with the wrong value for");
1931 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1932 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001933 pass = (err != VK_SUCCESS);
1934 ASSERT_TRUE(pass);
1935 m_errorMonitor->VerifyFound();
1936
1937 // Next, call with a NULL swapchain pointer:
1938 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1939 swapchain_create_info.pNext = NULL;
1940 swapchain_create_info.flags = 0;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1942 "called with NULL pointer");
1943 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1944 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001945 pass = (err != VK_SUCCESS);
1946 ASSERT_TRUE(pass);
1947 m_errorMonitor->VerifyFound();
1948
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001949 // TODO: Enhance swapchain layer so that
1950 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06001951
1952 // Next, call with a queue family index that's too large:
1953 uint32_t queueFamilyIndex[2] = {100000, 0};
1954 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
1955 swapchain_create_info.queueFamilyIndexCount = 2;
1956 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
1957 m_errorMonitor->SetDesiredFailureMsg(
1958 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1959 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001960 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1961 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001962 pass = (err != VK_SUCCESS);
1963 ASSERT_TRUE(pass);
1964 m_errorMonitor->VerifyFound();
1965
1966 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
1967 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
1968 swapchain_create_info.queueFamilyIndexCount = 1;
1969 m_errorMonitor->SetDesiredFailureMsg(
1970 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1971 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
1972 "pCreateInfo->pQueueFamilyIndices).");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001973 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1974 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001975 pass = (err != VK_SUCCESS);
1976 ASSERT_TRUE(pass);
1977 m_errorMonitor->VerifyFound();
1978
1979 // Next, call with an invalid imageSharingMode:
1980 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
1981 swapchain_create_info.queueFamilyIndexCount = 1;
1982 m_errorMonitor->SetDesiredFailureMsg(
1983 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1984 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001985 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1986 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001987 pass = (err != VK_SUCCESS);
1988 ASSERT_TRUE(pass);
1989 m_errorMonitor->VerifyFound();
1990 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001991 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
1992 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06001993 swapchain_create_info.queueFamilyIndexCount = 0;
1994 queueFamilyIndex[0] = 0;
1995 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
1996
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001997 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06001998 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001999 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002000 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002001 // Destroy the swapchain:
2002
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002003 // TODOs:
2004 //
2005 // - Try destroying the device without first destroying the swapchain
2006 //
2007 // - Try destroying the device without first destroying the surface
2008 //
2009 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002010
2011 // Destroy the surface:
2012 vkDestroySurfaceKHR(instance(), surface, NULL);
2013
Ian Elliott2c1daf52016-05-12 09:41:46 -06002014 // Tear down the window:
2015 xcb_destroy_window(connection, xcb_window);
2016 xcb_disconnect(connection);
2017
2018#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002019 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002020#endif // VK_USE_PLATFORM_XCB_KHR
2021}
2022
Karl Schultz6addd812016-02-02 17:17:23 -07002023TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2024 VkResult err;
2025 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002026
Karl Schultz6addd812016-02-02 17:17:23 -07002027 m_errorMonitor->SetDesiredFailureMsg(
2028 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002029 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
2030
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002031 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002032
2033 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002034 VkImage image;
2035 VkDeviceMemory mem;
2036 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002037
Karl Schultz6addd812016-02-02 17:17:23 -07002038 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2039 const int32_t tex_width = 32;
2040 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002041
Tony Barboureb254902015-07-15 12:50:33 -06002042 VkImageCreateInfo image_create_info = {};
2043 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002044 image_create_info.pNext = NULL;
2045 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2046 image_create_info.format = tex_format;
2047 image_create_info.extent.width = tex_width;
2048 image_create_info.extent.height = tex_height;
2049 image_create_info.extent.depth = 1;
2050 image_create_info.mipLevels = 1;
2051 image_create_info.arrayLayers = 1;
2052 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2053 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2054 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2055 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002056
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002057 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002058 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002059 mem_alloc.pNext = NULL;
2060 mem_alloc.allocationSize = 0;
2061 // Introduce failure, do NOT set memProps to
2062 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
2063 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002064
Chia-I Wuf7458c52015-10-26 21:10:41 +08002065 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002066 ASSERT_VK_SUCCESS(err);
2067
Karl Schultz6addd812016-02-02 17:17:23 -07002068 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002069
Mark Lobodzinski23065352015-05-29 09:32:35 -05002070 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002071
Karl Schultz6addd812016-02-02 17:17:23 -07002072 pass =
2073 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0,
2074 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
2075 if (!pass) { // If we can't find any unmappable memory this test doesn't
2076 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002077 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002078 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002079 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002080
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002081 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002082 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002083 ASSERT_VK_SUCCESS(err);
2084
2085 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002086 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002087 ASSERT_VK_SUCCESS(err);
2088
2089 // Map memory as if to initialize the image
2090 void *mappedAddress = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07002091 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0,
2092 &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002093
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002094 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002095
Chia-I Wuf7458c52015-10-26 21:10:41 +08002096 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002097}
2098
Karl Schultz6addd812016-02-02 17:17:23 -07002099TEST_F(VkLayerTest, RebindMemory) {
2100 VkResult err;
2101 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002102
Karl Schultz6addd812016-02-02 17:17:23 -07002103 m_errorMonitor->SetDesiredFailureMsg(
2104 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002105 "which has already been bound to mem object");
2106
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002107 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002108
2109 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002110 VkImage image;
2111 VkDeviceMemory mem1;
2112 VkDeviceMemory mem2;
2113 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002114
Karl Schultz6addd812016-02-02 17:17:23 -07002115 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2116 const int32_t tex_width = 32;
2117 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002118
Tony Barboureb254902015-07-15 12:50:33 -06002119 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002120 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2121 image_create_info.pNext = NULL;
2122 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2123 image_create_info.format = tex_format;
2124 image_create_info.extent.width = tex_width;
2125 image_create_info.extent.height = tex_height;
2126 image_create_info.extent.depth = 1;
2127 image_create_info.mipLevels = 1;
2128 image_create_info.arrayLayers = 1;
2129 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2130 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2131 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2132 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002133
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002134 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002135 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2136 mem_alloc.pNext = NULL;
2137 mem_alloc.allocationSize = 0;
2138 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002139
Karl Schultz6addd812016-02-02 17:17:23 -07002140 // Introduce failure, do NOT set memProps to
2141 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002142 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002143 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002144 ASSERT_VK_SUCCESS(err);
2145
Karl Schultz6addd812016-02-02 17:17:23 -07002146 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002147
2148 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002149 pass =
2150 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002151 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002152
2153 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002154 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002155 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002156 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002157 ASSERT_VK_SUCCESS(err);
2158
2159 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002160 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002161 ASSERT_VK_SUCCESS(err);
2162
Karl Schultz6addd812016-02-02 17:17:23 -07002163 // Introduce validation failure, try to bind a different memory object to
2164 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002165 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002166
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002167 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002168
Chia-I Wuf7458c52015-10-26 21:10:41 +08002169 vkDestroyImage(m_device->device(), image, NULL);
2170 vkFreeMemory(m_device->device(), mem1, NULL);
2171 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002172}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002173
Karl Schultz6addd812016-02-02 17:17:23 -07002174TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002175 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002176
Karl Schultz6addd812016-02-02 17:17:23 -07002177 m_errorMonitor->SetDesiredFailureMsg(
2178 VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2179 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002180
2181 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002182 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2183 fenceInfo.pNext = NULL;
2184 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002185
Tony Barbour300a6082015-04-07 13:44:53 -06002186 ASSERT_NO_FATAL_FAILURE(InitState());
2187 ASSERT_NO_FATAL_FAILURE(InitViewport());
2188 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2189
Tony Barbourfe3351b2015-07-28 10:17:20 -06002190 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002191 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
2192 m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002193 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002194
2195 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002196
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002197 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002198 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2199 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002200 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002201 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002202 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002203 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002204 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002205 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002206 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002207
2208 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002209 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002210
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002211 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002212}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002213// This is a positive test. We used to expect error in this case but spec now
2214// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002215TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002216 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002217 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002218 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002219 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2220 fenceInfo.pNext = NULL;
2221
Tony Barbour0b4d9562015-04-09 10:48:04 -06002222 ASSERT_NO_FATAL_FAILURE(InitState());
2223 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002224 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002225 VkResult result = vkResetFences(m_device->device(), 1, fences);
2226 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002227
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002228 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002229}
Tobin Ehlis41376e12015-07-03 08:45:14 -06002230
2231TEST_F(VkLayerTest, InvalidUsageBits)
2232{
Tony Barbourf92621a2016-05-02 14:28:12 -06002233 TEST_DESCRIPTION(
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002234 "Specify wrong usage for image then create conflicting view of image "
Tony Barbourf92621a2016-05-02 14:28:12 -06002235 "Initialize buffer with wrong usage then perform copy expecting errors "
2236 "from both the image and the buffer (2 calls)");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002238 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002239
2240 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002241 VkImageObj image(m_device);
2242 // Initialize image with USAGE_INPUT_ATTACHMENT
Tobin Ehlis8b313c02016-05-25 15:01:52 -06002243 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT,
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002244 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
2245 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002246
Tony Barbourf92621a2016-05-02 14:28:12 -06002247 VkImageView dsv;
2248 VkImageViewCreateInfo dsvci = {};
2249 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2250 dsvci.image = image.handle();
2251 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2252 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2253 dsvci.subresourceRange.layerCount = 1;
2254 dsvci.subresourceRange.baseMipLevel = 0;
2255 dsvci.subresourceRange.levelCount = 1;
2256 dsvci.subresourceRange.aspectMask =
2257 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002258
Tony Barbourf92621a2016-05-02 14:28:12 -06002259 // Create a view with depth / stencil aspect for image with different usage
2260 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002261
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002262 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002263
2264 // Initialize buffer with TRANSFER_DST usage
2265 vk_testing::Buffer buffer;
2266 VkMemoryPropertyFlags reqs = 0;
2267 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2268 VkBufferImageCopy region = {};
2269 region.bufferRowLength = 128;
2270 region.bufferImageHeight = 128;
2271 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2272 region.imageSubresource.layerCount = 1;
2273 region.imageExtent.height = 16;
2274 region.imageExtent.width = 16;
2275 region.imageExtent.depth = 1;
2276
2277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2278 "Invalid usage flag for buffer ");
2279 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2280 // TRANSFER_DST
2281 BeginCommandBuffer();
2282 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2283 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2284 1, &region);
2285 m_errorMonitor->VerifyFound();
2286
2287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2288 "Invalid usage flag for image ");
2289 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2290 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2291 1, &region);
2292 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002293}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002294#endif // MEM_TRACKER_TESTS
2295
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002296#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002297
2298TEST_F(VkLayerTest, LeakAnObject) {
2299 VkResult err;
2300
2301 TEST_DESCRIPTION(
2302 "Create a fence and destroy its device without first destroying the fence.");
2303
2304 // Note that we have to create a new device since destroying the
2305 // framework's device causes Teardown() to fail and just calling Teardown
2306 // will destroy the errorMonitor.
2307
2308 m_errorMonitor->SetDesiredFailureMsg(
2309 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2310 "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object");
2311
2312 ASSERT_NO_FATAL_FAILURE(InitState());
2313
2314 const std::vector<VkQueueFamilyProperties> queue_props =
2315 m_device->queue_props;
2316 std::vector<VkDeviceQueueCreateInfo> queue_info;
2317 queue_info.reserve(queue_props.size());
2318 std::vector<std::vector<float>> queue_priorities;
2319 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2320 VkDeviceQueueCreateInfo qi = {};
2321 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2322 qi.pNext = NULL;
2323 qi.queueFamilyIndex = i;
2324 qi.queueCount = queue_props[i].queueCount;
2325 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2326 qi.pQueuePriorities = queue_priorities[i].data();
2327 queue_info.push_back(qi);
2328 }
2329
2330 std::vector<const char *> device_layer_names;
2331 std::vector<const char *> device_extension_names;
2332 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
2333 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
2334 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
2335 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
2336 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
2337 device_layer_names.push_back("VK_LAYER_LUNARG_image");
2338 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
2339
2340 // The sacrificial device object
2341 VkDevice testDevice;
2342 VkDeviceCreateInfo device_create_info = {};
2343 auto features = m_device->phy().features();
2344 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2345 device_create_info.pNext = NULL;
2346 device_create_info.queueCreateInfoCount = queue_info.size();
2347 device_create_info.pQueueCreateInfos = queue_info.data();
2348 device_create_info.enabledLayerCount = device_layer_names.size();
2349 device_create_info.ppEnabledLayerNames = device_layer_names.data();
2350 device_create_info.pEnabledFeatures = &features;
2351 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2352 ASSERT_VK_SUCCESS(err);
2353
2354 VkFence fence;
2355 VkFenceCreateInfo fence_create_info = {};
2356 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2357 fence_create_info.pNext = NULL;
2358 fence_create_info.flags = 0;
2359 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2360 ASSERT_VK_SUCCESS(err);
2361
2362 // Induce failure by not calling vkDestroyFence
2363 vkDestroyDevice(testDevice, NULL);
2364 m_errorMonitor->VerifyFound();
2365}
2366
2367TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2368
2369 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2370 "attempt to delete them from another.");
2371
2372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2373 "FreeCommandBuffers is attempting to free Command Buffer");
2374
2375 VkCommandPool command_pool_one;
2376 VkCommandPool command_pool_two;
2377
2378 VkCommandPoolCreateInfo pool_create_info{};
2379 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2380 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2381 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2382
2383 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2384 &command_pool_one);
2385
2386 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2387 &command_pool_two);
2388
2389 VkCommandBuffer command_buffer[9];
2390 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2391 command_buffer_allocate_info.sType =
2392 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2393 command_buffer_allocate_info.commandPool = command_pool_one;
2394 command_buffer_allocate_info.commandBufferCount = 9;
2395 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2396 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2397 command_buffer);
2398
2399 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4,
2400 &command_buffer[3]);
2401
2402 m_errorMonitor->VerifyFound();
2403
2404 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2405 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2406}
2407
2408TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2409 VkResult err;
2410
2411 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
2412 "attempt to delete them from another.");
2413
2414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2415 "FreeDescriptorSets is attempting to free descriptorSet");
2416
2417 ASSERT_NO_FATAL_FAILURE(InitState());
2418 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2419
2420 VkDescriptorPoolSize ds_type_count = {};
2421 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2422 ds_type_count.descriptorCount = 1;
2423
2424 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2425 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2426 ds_pool_ci.pNext = NULL;
2427 ds_pool_ci.flags = 0;
2428 ds_pool_ci.maxSets = 1;
2429 ds_pool_ci.poolSizeCount = 1;
2430 ds_pool_ci.pPoolSizes = &ds_type_count;
2431
2432 VkDescriptorPool ds_pool_one;
2433 err =
2434 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
2435 ASSERT_VK_SUCCESS(err);
2436
2437 // Create a second descriptor pool
2438 VkDescriptorPool ds_pool_two;
2439 err =
2440 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
2441 ASSERT_VK_SUCCESS(err);
2442
2443 VkDescriptorSetLayoutBinding dsl_binding = {};
2444 dsl_binding.binding = 0;
2445 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2446 dsl_binding.descriptorCount = 1;
2447 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2448 dsl_binding.pImmutableSamplers = NULL;
2449
2450 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2451 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2452 ds_layout_ci.pNext = NULL;
2453 ds_layout_ci.bindingCount = 1;
2454 ds_layout_ci.pBindings = &dsl_binding;
2455
2456 VkDescriptorSetLayout ds_layout;
2457 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2458 &ds_layout);
2459 ASSERT_VK_SUCCESS(err);
2460
2461 VkDescriptorSet descriptorSet;
2462 VkDescriptorSetAllocateInfo alloc_info = {};
2463 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2464 alloc_info.descriptorSetCount = 1;
2465 alloc_info.descriptorPool = ds_pool_one;
2466 alloc_info.pSetLayouts = &ds_layout;
2467 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2468 &descriptorSet);
2469 ASSERT_VK_SUCCESS(err);
2470
2471 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2472
2473 m_errorMonitor->VerifyFound();
2474
2475 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2476 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2477 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2478}
2479
2480TEST_F(VkLayerTest, CreateUnknownObject) {
2481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2482 "Invalid VkImage Object ");
2483
2484 TEST_DESCRIPTION(
2485 "Pass an invalid image object handle into a Vulkan API call.");
2486
2487 ASSERT_NO_FATAL_FAILURE(InitState());
2488
2489 // Pass bogus handle into GetImageMemoryRequirements
2490 VkMemoryRequirements mem_reqs;
2491 uint64_t fakeImageHandle = 0xCADECADE;
2492 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2493
2494 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2495
2496 m_errorMonitor->VerifyFound();
2497}
2498
Karl Schultz6addd812016-02-02 17:17:23 -07002499TEST_F(VkLayerTest, PipelineNotBound) {
2500 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002501
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002502 TEST_DESCRIPTION(
2503 "Pass in an invalid pipeline object handle into a Vulkan API call.");
2504
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002506 "Invalid VkPipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002507
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002508 ASSERT_NO_FATAL_FAILURE(InitState());
2509 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002510
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002511 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002512 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2513 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002514
2515 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002516 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2517 ds_pool_ci.pNext = NULL;
2518 ds_pool_ci.maxSets = 1;
2519 ds_pool_ci.poolSizeCount = 1;
2520 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002521
2522 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002523 err =
2524 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002525 ASSERT_VK_SUCCESS(err);
2526
2527 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002528 dsl_binding.binding = 0;
2529 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2530 dsl_binding.descriptorCount = 1;
2531 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2532 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002533
2534 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002535 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2536 ds_layout_ci.pNext = NULL;
2537 ds_layout_ci.bindingCount = 1;
2538 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002539
2540 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002541 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2542 &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002543 ASSERT_VK_SUCCESS(err);
2544
2545 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002546 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002547 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002548 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002549 alloc_info.descriptorPool = ds_pool;
2550 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002551 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2552 &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002553 ASSERT_VK_SUCCESS(err);
2554
2555 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002556 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2557 pipeline_layout_ci.pNext = NULL;
2558 pipeline_layout_ci.setLayoutCount = 1;
2559 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002560
2561 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002562 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2563 &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002564 ASSERT_VK_SUCCESS(err);
2565
Mark Youngad779052016-01-06 14:26:04 -07002566 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002567
2568 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002569 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
2570 VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002571
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002572 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002573
Chia-I Wuf7458c52015-10-26 21:10:41 +08002574 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2575 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2576 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002577}
2578
Karl Schultz6addd812016-02-02 17:17:23 -07002579TEST_F(VkLayerTest, BindInvalidMemory) {
2580 VkResult err;
2581 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002582
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002584 "Invalid VkDeviceMemory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002585
Tobin Ehlisec598302015-09-15 15:02:17 -06002586 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002587
2588 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002589 VkImage image;
2590 VkDeviceMemory mem;
2591 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002592
Karl Schultz6addd812016-02-02 17:17:23 -07002593 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2594 const int32_t tex_width = 32;
2595 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002596
2597 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002598 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2599 image_create_info.pNext = NULL;
2600 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2601 image_create_info.format = tex_format;
2602 image_create_info.extent.width = tex_width;
2603 image_create_info.extent.height = tex_height;
2604 image_create_info.extent.depth = 1;
2605 image_create_info.mipLevels = 1;
2606 image_create_info.arrayLayers = 1;
2607 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2608 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2609 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2610 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002611
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002612 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002613 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2614 mem_alloc.pNext = NULL;
2615 mem_alloc.allocationSize = 0;
2616 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002617
Chia-I Wuf7458c52015-10-26 21:10:41 +08002618 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002619 ASSERT_VK_SUCCESS(err);
2620
Karl Schultz6addd812016-02-02 17:17:23 -07002621 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002622
2623 mem_alloc.allocationSize = mem_reqs.size;
2624
Karl Schultz6addd812016-02-02 17:17:23 -07002625 pass =
2626 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002627 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002628
2629 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002630 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002631 ASSERT_VK_SUCCESS(err);
2632
2633 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002634 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002635
2636 // Try to bind free memory that has been freed
2637 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2638 // This may very well return an error.
2639 (void)err;
2640
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002641 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002642
Chia-I Wuf7458c52015-10-26 21:10:41 +08002643 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002644}
2645
Karl Schultz6addd812016-02-02 17:17:23 -07002646TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2647 VkResult err;
2648 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002649
Karl Schultz6addd812016-02-02 17:17:23 -07002650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2651 "Invalid VkImage Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002652
Tobin Ehlisec598302015-09-15 15:02:17 -06002653 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002654
Karl Schultz6addd812016-02-02 17:17:23 -07002655 // Create an image object, allocate memory, destroy the object and then try
2656 // to bind it
2657 VkImage image;
2658 VkDeviceMemory mem;
2659 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002660
Karl Schultz6addd812016-02-02 17:17:23 -07002661 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2662 const int32_t tex_width = 32;
2663 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002664
2665 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002666 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2667 image_create_info.pNext = NULL;
2668 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2669 image_create_info.format = tex_format;
2670 image_create_info.extent.width = tex_width;
2671 image_create_info.extent.height = tex_height;
2672 image_create_info.extent.depth = 1;
2673 image_create_info.mipLevels = 1;
2674 image_create_info.arrayLayers = 1;
2675 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2676 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2677 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2678 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002679
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002680 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002681 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2682 mem_alloc.pNext = NULL;
2683 mem_alloc.allocationSize = 0;
2684 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002685
Chia-I Wuf7458c52015-10-26 21:10:41 +08002686 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002687 ASSERT_VK_SUCCESS(err);
2688
Karl Schultz6addd812016-02-02 17:17:23 -07002689 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002690
2691 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002692 pass =
2693 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002694 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002695
2696 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002697 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002698 ASSERT_VK_SUCCESS(err);
2699
2700 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002701 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002702 ASSERT_VK_SUCCESS(err);
2703
2704 // Now Try to bind memory to this destroyed object
2705 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2706 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002707 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002708
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002709 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002710
Chia-I Wuf7458c52015-10-26 21:10:41 +08002711 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002712}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002713
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002714#endif // OBJ_TRACKER_TESTS
2715
Tobin Ehlis0788f522015-05-26 16:11:58 -06002716#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002717
2718// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05002719TEST_F(VkLayerTest, WaitEventThenSet) {
2720 TEST_DESCRIPTION(
2721 "Wait on a event then set it after the wait has been submitted.");
2722
2723 if ((m_device->queue_props.empty()) ||
2724 (m_device->queue_props[0].queueCount < 2))
2725 return;
2726
2727 m_errorMonitor->ExpectSuccess();
2728
2729 VkEvent event;
2730 VkEventCreateInfo event_create_info{};
2731 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2732 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
2733
2734 VkCommandPool command_pool;
2735 VkCommandPoolCreateInfo pool_create_info{};
2736 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2737 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2738 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2739 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2740 &command_pool);
2741
2742 VkCommandBuffer command_buffer;
2743 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2744 command_buffer_allocate_info.sType =
2745 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2746 command_buffer_allocate_info.commandPool = command_pool;
2747 command_buffer_allocate_info.commandBufferCount = 1;
2748 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2749 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2750 &command_buffer);
2751
2752 VkQueue queue = VK_NULL_HANDLE;
2753 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2754 1, &queue);
2755
2756 {
2757 VkCommandBufferBeginInfo begin_info{};
2758 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2759 vkBeginCommandBuffer(command_buffer, &begin_info);
2760
2761 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT,
2762 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
2763 nullptr, 0, nullptr);
2764 vkCmdResetEvent(command_buffer, event,
2765 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
2766 vkEndCommandBuffer(command_buffer);
2767 }
2768 {
2769 VkSubmitInfo submit_info{};
2770 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2771 submit_info.commandBufferCount = 1;
2772 submit_info.pCommandBuffers = &command_buffer;
2773 submit_info.signalSemaphoreCount = 0;
2774 submit_info.pSignalSemaphores = nullptr;
2775 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2776 }
2777 { vkSetEvent(m_device->device(), event); }
2778
2779 vkQueueWaitIdle(queue);
2780
2781 vkDestroyEvent(m_device->device(), event, nullptr);
2782 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
2783 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2784
2785 m_errorMonitor->VerifyNotFound();
2786}
Michael Lentine5627e692016-05-20 17:45:02 -05002787// This is a positive test. No errors should be generated.
2788TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
2789 TEST_DESCRIPTION(
2790 "Issue a query and copy from it on a second command buffer.");
2791
2792 if ((m_device->queue_props.empty()) ||
2793 (m_device->queue_props[0].queueCount < 2))
2794 return;
2795
2796 m_errorMonitor->ExpectSuccess();
2797
2798 VkQueryPool query_pool;
2799 VkQueryPoolCreateInfo query_pool_create_info{};
2800 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
2801 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
2802 query_pool_create_info.queryCount = 1;
2803 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr,
2804 &query_pool);
2805
2806 VkCommandPool command_pool;
2807 VkCommandPoolCreateInfo pool_create_info{};
2808 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2809 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2810 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2811 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2812 &command_pool);
2813
2814 VkCommandBuffer command_buffer[2];
2815 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2816 command_buffer_allocate_info.sType =
2817 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2818 command_buffer_allocate_info.commandPool = command_pool;
2819 command_buffer_allocate_info.commandBufferCount = 2;
2820 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2821 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2822 command_buffer);
2823
2824 VkQueue queue = VK_NULL_HANDLE;
2825 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2826 1, &queue);
2827
2828 uint32_t qfi = 0;
2829 VkBufferCreateInfo buff_create_info = {};
2830 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2831 buff_create_info.size = 1024;
2832 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
2833 buff_create_info.queueFamilyIndexCount = 1;
2834 buff_create_info.pQueueFamilyIndices = &qfi;
2835
2836 VkResult err;
2837 VkBuffer buffer;
2838 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
2839 ASSERT_VK_SUCCESS(err);
2840 VkMemoryAllocateInfo mem_alloc = {};
2841 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2842 mem_alloc.pNext = NULL;
2843 mem_alloc.allocationSize = 1024;
2844 mem_alloc.memoryTypeIndex = 0;
2845
2846 VkMemoryRequirements memReqs;
2847 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
2848 bool pass =
2849 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
2850 if (!pass) {
2851 vkDestroyBuffer(m_device->device(), buffer, NULL);
2852 return;
2853 }
2854
2855 VkDeviceMemory mem;
2856 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2857 ASSERT_VK_SUCCESS(err);
2858 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
2859 ASSERT_VK_SUCCESS(err);
2860
2861 {
2862 VkCommandBufferBeginInfo begin_info{};
2863 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2864 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2865
2866 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
2867 vkCmdWriteTimestamp(command_buffer[0],
2868 VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
2869
2870 vkEndCommandBuffer(command_buffer[0]);
2871
2872 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2873
2874 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer,
2875 0, 0, 0);
2876
2877 vkEndCommandBuffer(command_buffer[1]);
2878 }
2879 {
2880 VkSubmitInfo submit_info{};
2881 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2882 submit_info.commandBufferCount = 2;
2883 submit_info.pCommandBuffers = command_buffer;
2884 submit_info.signalSemaphoreCount = 0;
2885 submit_info.pSignalSemaphores = nullptr;
2886 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2887 }
2888
2889 vkQueueWaitIdle(queue);
2890
2891 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
2892 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
2893 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2894
2895 m_errorMonitor->VerifyNotFound();
2896}
Michael Lentine860b0fe2016-05-20 10:14:00 -05002897
2898TEST_F(VkLayerTest, ResetEventThenSet) {
2899 TEST_DESCRIPTION(
2900 "Reset an event then set it after the reset has been submitted.");
2901
2902 if ((m_device->queue_props.empty()) ||
2903 (m_device->queue_props[0].queueCount < 2))
2904 return;
2905
2906 m_errorMonitor->ExpectSuccess();
2907
2908 VkEvent event;
2909 VkEventCreateInfo event_create_info{};
2910 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2911 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
2912
2913 VkCommandPool command_pool;
2914 VkCommandPoolCreateInfo pool_create_info{};
2915 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2916 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2917 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2918 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2919 &command_pool);
2920
2921 VkCommandBuffer command_buffer;
2922 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2923 command_buffer_allocate_info.sType =
2924 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2925 command_buffer_allocate_info.commandPool = command_pool;
2926 command_buffer_allocate_info.commandBufferCount = 1;
2927 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2928 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2929 &command_buffer);
2930
2931 VkQueue queue = VK_NULL_HANDLE;
2932 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2933 1, &queue);
2934
2935 {
2936 VkCommandBufferBeginInfo begin_info{};
2937 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2938 vkBeginCommandBuffer(command_buffer, &begin_info);
2939
2940 vkCmdResetEvent(command_buffer, event,
2941 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
2942 vkCmdWaitEvents(command_buffer, 1, &event,
2943 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2944 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
2945 nullptr, 0, nullptr);
2946 vkEndCommandBuffer(command_buffer);
2947 }
2948 {
2949 VkSubmitInfo submit_info{};
2950 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2951 submit_info.commandBufferCount = 1;
2952 submit_info.pCommandBuffers = &command_buffer;
2953 submit_info.signalSemaphoreCount = 0;
2954 submit_info.pSignalSemaphores = nullptr;
2955 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2956 }
2957 {
2958 m_errorMonitor->SetDesiredFailureMsg(
2959 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event "
2960 "0x1 that is already in use by a "
2961 "command buffer.");
2962 vkSetEvent(m_device->device(), event);
2963 m_errorMonitor->VerifyFound();
2964 }
2965
2966 vkQueueWaitIdle(queue);
2967
2968 vkDestroyEvent(m_device->device(), event, nullptr);
2969 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
2970 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2971}
2972
2973// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06002974TEST_F(VkLayerTest, TwoFencesThreeFrames) {
2975 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
2976 "run through a Submit & WaitForFences cycle 3 times. This "
2977 "previously revealed a bug so running this positive test "
2978 "to prevent a regression.");
2979 m_errorMonitor->ExpectSuccess();
2980
2981 ASSERT_NO_FATAL_FAILURE(InitState());
2982 VkQueue queue = VK_NULL_HANDLE;
2983 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2984 0, &queue);
2985
2986 static const uint32_t NUM_OBJECTS = 2;
2987 static const uint32_t NUM_FRAMES = 3;
2988 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
2989 VkFence fences[NUM_OBJECTS] = {};
2990
2991 VkCommandPool cmd_pool;
2992 VkCommandPoolCreateInfo cmd_pool_ci = {};
2993 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2994 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
2995 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2996 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci,
2997 nullptr, &cmd_pool);
2998 ASSERT_VK_SUCCESS(err);
2999
3000 VkCommandBufferAllocateInfo cmd_buf_info = {};
3001 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3002 cmd_buf_info.commandPool = cmd_pool;
3003 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3004 cmd_buf_info.commandBufferCount = 1;
3005
3006 VkFenceCreateInfo fence_ci = {};
3007 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3008 fence_ci.pNext = nullptr;
3009 fence_ci.flags = 0;
3010
3011 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3012 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info,
3013 &cmd_buffers[i]);
3014 ASSERT_VK_SUCCESS(err);
3015 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
3016 ASSERT_VK_SUCCESS(err);
3017 }
3018
3019 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06003020 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
3021 // Create empty cmd buffer
3022 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3023 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003024
Tobin Ehlisf9025162016-05-26 06:55:21 -06003025 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
3026 ASSERT_VK_SUCCESS(err);
3027 err = vkEndCommandBuffer(cmd_buffers[obj]);
3028 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003029
Tobin Ehlisf9025162016-05-26 06:55:21 -06003030 VkSubmitInfo submit_info = {};
3031 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3032 submit_info.commandBufferCount = 1;
3033 submit_info.pCommandBuffers = &cmd_buffers[obj];
3034 // Submit cmd buffer and wait for fence
3035 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
3036 ASSERT_VK_SUCCESS(err);
3037 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE,
3038 UINT64_MAX);
3039 ASSERT_VK_SUCCESS(err);
3040 err = vkResetFences(m_device->device(), 1, &fences[obj]);
3041 ASSERT_VK_SUCCESS(err);
3042 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003043 }
3044 m_errorMonitor->VerifyNotFound();
3045}
3046// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003047TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
3048
3049 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3050 "submitted on separate queues followed by a QueueWaitIdle.");
3051
Dustin Graves48458142016-04-29 16:11:55 -06003052 if ((m_device->queue_props.empty()) ||
3053 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003054 return;
3055
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003056 m_errorMonitor->ExpectSuccess();
3057
3058 VkSemaphore semaphore;
3059 VkSemaphoreCreateInfo semaphore_create_info{};
3060 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3061 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3062 &semaphore);
3063
3064 VkCommandPool command_pool;
3065 VkCommandPoolCreateInfo pool_create_info{};
3066 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3067 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3068 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3069 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3070 &command_pool);
3071
3072 VkCommandBuffer command_buffer[2];
3073 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3074 command_buffer_allocate_info.sType =
3075 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3076 command_buffer_allocate_info.commandPool = command_pool;
3077 command_buffer_allocate_info.commandBufferCount = 2;
3078 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3079 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3080 command_buffer);
3081
3082 VkQueue queue = VK_NULL_HANDLE;
3083 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3084 1, &queue);
3085
3086 {
3087 VkCommandBufferBeginInfo begin_info{};
3088 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3089 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3090
3091 vkCmdPipelineBarrier(command_buffer[0],
3092 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3093 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3094 0, nullptr, 0, nullptr);
3095
3096 VkViewport viewport{};
3097 viewport.maxDepth = 1.0f;
3098 viewport.minDepth = 0.0f;
3099 viewport.width = 512;
3100 viewport.height = 512;
3101 viewport.x = 0;
3102 viewport.y = 0;
3103 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3104 vkEndCommandBuffer(command_buffer[0]);
3105 }
3106 {
3107 VkCommandBufferBeginInfo begin_info{};
3108 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3109 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3110
3111 VkViewport viewport{};
3112 viewport.maxDepth = 1.0f;
3113 viewport.minDepth = 0.0f;
3114 viewport.width = 512;
3115 viewport.height = 512;
3116 viewport.x = 0;
3117 viewport.y = 0;
3118 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3119 vkEndCommandBuffer(command_buffer[1]);
3120 }
3121 {
3122 VkSubmitInfo submit_info{};
3123 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3124 submit_info.commandBufferCount = 1;
3125 submit_info.pCommandBuffers = &command_buffer[0];
3126 submit_info.signalSemaphoreCount = 1;
3127 submit_info.pSignalSemaphores = &semaphore;
3128 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3129 }
3130 {
3131 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3132 VkSubmitInfo submit_info{};
3133 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3134 submit_info.commandBufferCount = 1;
3135 submit_info.pCommandBuffers = &command_buffer[1];
3136 submit_info.waitSemaphoreCount = 1;
3137 submit_info.pWaitSemaphores = &semaphore;
3138 submit_info.pWaitDstStageMask = flags;
3139 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3140 }
3141
3142 vkQueueWaitIdle(m_device->m_queue);
3143
3144 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3145 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3146 &command_buffer[0]);
3147 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3148
3149 m_errorMonitor->VerifyNotFound();
3150}
3151
3152// This is a positive test. No errors should be generated.
3153TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
3154
3155 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3156 "submitted on separate queues, the second having a fence"
3157 "followed by a QueueWaitIdle.");
3158
Dustin Graves48458142016-04-29 16:11:55 -06003159 if ((m_device->queue_props.empty()) ||
3160 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003161 return;
3162
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003163 m_errorMonitor->ExpectSuccess();
3164
3165 VkFence fence;
3166 VkFenceCreateInfo fence_create_info{};
3167 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3168 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3169
3170 VkSemaphore semaphore;
3171 VkSemaphoreCreateInfo semaphore_create_info{};
3172 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3173 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3174 &semaphore);
3175
3176 VkCommandPool command_pool;
3177 VkCommandPoolCreateInfo pool_create_info{};
3178 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3179 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3180 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3181 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3182 &command_pool);
3183
3184 VkCommandBuffer command_buffer[2];
3185 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3186 command_buffer_allocate_info.sType =
3187 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3188 command_buffer_allocate_info.commandPool = command_pool;
3189 command_buffer_allocate_info.commandBufferCount = 2;
3190 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3191 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3192 command_buffer);
3193
3194 VkQueue queue = VK_NULL_HANDLE;
3195 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3196 1, &queue);
3197
3198 {
3199 VkCommandBufferBeginInfo begin_info{};
3200 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3201 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3202
3203 vkCmdPipelineBarrier(command_buffer[0],
3204 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3205 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3206 0, nullptr, 0, nullptr);
3207
3208 VkViewport viewport{};
3209 viewport.maxDepth = 1.0f;
3210 viewport.minDepth = 0.0f;
3211 viewport.width = 512;
3212 viewport.height = 512;
3213 viewport.x = 0;
3214 viewport.y = 0;
3215 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3216 vkEndCommandBuffer(command_buffer[0]);
3217 }
3218 {
3219 VkCommandBufferBeginInfo begin_info{};
3220 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3221 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3222
3223 VkViewport viewport{};
3224 viewport.maxDepth = 1.0f;
3225 viewport.minDepth = 0.0f;
3226 viewport.width = 512;
3227 viewport.height = 512;
3228 viewport.x = 0;
3229 viewport.y = 0;
3230 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3231 vkEndCommandBuffer(command_buffer[1]);
3232 }
3233 {
3234 VkSubmitInfo submit_info{};
3235 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3236 submit_info.commandBufferCount = 1;
3237 submit_info.pCommandBuffers = &command_buffer[0];
3238 submit_info.signalSemaphoreCount = 1;
3239 submit_info.pSignalSemaphores = &semaphore;
3240 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3241 }
3242 {
3243 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3244 VkSubmitInfo submit_info{};
3245 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3246 submit_info.commandBufferCount = 1;
3247 submit_info.pCommandBuffers = &command_buffer[1];
3248 submit_info.waitSemaphoreCount = 1;
3249 submit_info.pWaitSemaphores = &semaphore;
3250 submit_info.pWaitDstStageMask = flags;
3251 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3252 }
3253
3254 vkQueueWaitIdle(m_device->m_queue);
3255
3256 vkDestroyFence(m_device->device(), fence, nullptr);
3257 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3258 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3259 &command_buffer[0]);
3260 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3261
3262 m_errorMonitor->VerifyNotFound();
3263}
3264
3265// This is a positive test. No errors should be generated.
3266TEST_F(VkLayerTest,
3267 TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
3268
3269 TEST_DESCRIPTION(
3270 "Two command buffers, each in a separate QueueSubmit call "
3271 "submitted on separate queues, the second having a fence"
3272 "followed by two consecutive WaitForFences calls on the same fence.");
3273
Dustin Graves48458142016-04-29 16:11:55 -06003274 if ((m_device->queue_props.empty()) ||
3275 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003276 return;
3277
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003278 m_errorMonitor->ExpectSuccess();
3279
3280 VkFence fence;
3281 VkFenceCreateInfo fence_create_info{};
3282 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3283 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3284
3285 VkSemaphore semaphore;
3286 VkSemaphoreCreateInfo semaphore_create_info{};
3287 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3288 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3289 &semaphore);
3290
3291 VkCommandPool command_pool;
3292 VkCommandPoolCreateInfo pool_create_info{};
3293 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3294 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3295 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3296 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3297 &command_pool);
3298
3299 VkCommandBuffer command_buffer[2];
3300 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3301 command_buffer_allocate_info.sType =
3302 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3303 command_buffer_allocate_info.commandPool = command_pool;
3304 command_buffer_allocate_info.commandBufferCount = 2;
3305 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3306 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3307 command_buffer);
3308
3309 VkQueue queue = VK_NULL_HANDLE;
3310 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3311 1, &queue);
3312
3313 {
3314 VkCommandBufferBeginInfo begin_info{};
3315 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3316 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3317
3318 vkCmdPipelineBarrier(command_buffer[0],
3319 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3320 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3321 0, nullptr, 0, nullptr);
3322
3323 VkViewport viewport{};
3324 viewport.maxDepth = 1.0f;
3325 viewport.minDepth = 0.0f;
3326 viewport.width = 512;
3327 viewport.height = 512;
3328 viewport.x = 0;
3329 viewport.y = 0;
3330 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3331 vkEndCommandBuffer(command_buffer[0]);
3332 }
3333 {
3334 VkCommandBufferBeginInfo begin_info{};
3335 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3336 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3337
3338 VkViewport viewport{};
3339 viewport.maxDepth = 1.0f;
3340 viewport.minDepth = 0.0f;
3341 viewport.width = 512;
3342 viewport.height = 512;
3343 viewport.x = 0;
3344 viewport.y = 0;
3345 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3346 vkEndCommandBuffer(command_buffer[1]);
3347 }
3348 {
3349 VkSubmitInfo submit_info{};
3350 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3351 submit_info.commandBufferCount = 1;
3352 submit_info.pCommandBuffers = &command_buffer[0];
3353 submit_info.signalSemaphoreCount = 1;
3354 submit_info.pSignalSemaphores = &semaphore;
3355 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3356 }
3357 {
3358 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3359 VkSubmitInfo submit_info{};
3360 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3361 submit_info.commandBufferCount = 1;
3362 submit_info.pCommandBuffers = &command_buffer[1];
3363 submit_info.waitSemaphoreCount = 1;
3364 submit_info.pWaitSemaphores = &semaphore;
3365 submit_info.pWaitDstStageMask = flags;
3366 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3367 }
3368
3369 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3370 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3371
3372 vkDestroyFence(m_device->device(), fence, nullptr);
3373 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3374 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3375 &command_buffer[0]);
3376 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3377
3378 m_errorMonitor->VerifyNotFound();
3379}
3380
3381// This is a positive test. No errors should be generated.
3382TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
3383
3384 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3385 "submitted on separate queues, the second having a fence, "
3386 "followed by a WaitForFences call.");
3387
Dustin Graves48458142016-04-29 16:11:55 -06003388 if ((m_device->queue_props.empty()) ||
3389 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003390 return;
3391
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003392 m_errorMonitor->ExpectSuccess();
3393
3394 VkFence fence;
3395 VkFenceCreateInfo fence_create_info{};
3396 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3397 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3398
3399 VkSemaphore semaphore;
3400 VkSemaphoreCreateInfo semaphore_create_info{};
3401 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3402 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3403 &semaphore);
3404
3405 VkCommandPool command_pool;
3406 VkCommandPoolCreateInfo pool_create_info{};
3407 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3408 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3409 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3410 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3411 &command_pool);
3412
3413 VkCommandBuffer command_buffer[2];
3414 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3415 command_buffer_allocate_info.sType =
3416 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3417 command_buffer_allocate_info.commandPool = command_pool;
3418 command_buffer_allocate_info.commandBufferCount = 2;
3419 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3420 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3421 command_buffer);
3422
3423 VkQueue queue = VK_NULL_HANDLE;
3424 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3425 1, &queue);
3426
3427
3428 {
3429 VkCommandBufferBeginInfo begin_info{};
3430 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3431 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3432
3433 vkCmdPipelineBarrier(command_buffer[0],
3434 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3435 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3436 0, nullptr, 0, nullptr);
3437
3438 VkViewport viewport{};
3439 viewport.maxDepth = 1.0f;
3440 viewport.minDepth = 0.0f;
3441 viewport.width = 512;
3442 viewport.height = 512;
3443 viewport.x = 0;
3444 viewport.y = 0;
3445 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3446 vkEndCommandBuffer(command_buffer[0]);
3447 }
3448 {
3449 VkCommandBufferBeginInfo begin_info{};
3450 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3451 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3452
3453 VkViewport viewport{};
3454 viewport.maxDepth = 1.0f;
3455 viewport.minDepth = 0.0f;
3456 viewport.width = 512;
3457 viewport.height = 512;
3458 viewport.x = 0;
3459 viewport.y = 0;
3460 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3461 vkEndCommandBuffer(command_buffer[1]);
3462 }
3463 {
3464 VkSubmitInfo submit_info{};
3465 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3466 submit_info.commandBufferCount = 1;
3467 submit_info.pCommandBuffers = &command_buffer[0];
3468 submit_info.signalSemaphoreCount = 1;
3469 submit_info.pSignalSemaphores = &semaphore;
3470 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3471 }
3472 {
3473 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3474 VkSubmitInfo submit_info{};
3475 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3476 submit_info.commandBufferCount = 1;
3477 submit_info.pCommandBuffers = &command_buffer[1];
3478 submit_info.waitSemaphoreCount = 1;
3479 submit_info.pWaitSemaphores = &semaphore;
3480 submit_info.pWaitDstStageMask = flags;
3481 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3482 }
3483
3484 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3485
3486 vkDestroyFence(m_device->device(), fence, nullptr);
3487 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3488 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3489 &command_buffer[0]);
3490 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3491
3492 m_errorMonitor->VerifyNotFound();
3493}
3494
3495// This is a positive test. No errors should be generated.
3496TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
3497
3498 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3499 "on the same queue, sharing a signal/wait semaphore, the "
3500 "second having a fence, "
3501 "followed by a WaitForFences call.");
3502
3503 m_errorMonitor->ExpectSuccess();
3504
3505 VkFence fence;
3506 VkFenceCreateInfo fence_create_info{};
3507 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3508 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3509
3510 VkSemaphore semaphore;
3511 VkSemaphoreCreateInfo semaphore_create_info{};
3512 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3513 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3514 &semaphore);
3515
3516 VkCommandPool command_pool;
3517 VkCommandPoolCreateInfo pool_create_info{};
3518 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3519 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3520 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3521 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3522 &command_pool);
3523
3524 VkCommandBuffer command_buffer[2];
3525 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3526 command_buffer_allocate_info.sType =
3527 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3528 command_buffer_allocate_info.commandPool = command_pool;
3529 command_buffer_allocate_info.commandBufferCount = 2;
3530 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3531 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3532 command_buffer);
3533
3534 {
3535 VkCommandBufferBeginInfo begin_info{};
3536 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3537 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3538
3539 vkCmdPipelineBarrier(command_buffer[0],
3540 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3541 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3542 0, nullptr, 0, nullptr);
3543
3544 VkViewport viewport{};
3545 viewport.maxDepth = 1.0f;
3546 viewport.minDepth = 0.0f;
3547 viewport.width = 512;
3548 viewport.height = 512;
3549 viewport.x = 0;
3550 viewport.y = 0;
3551 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3552 vkEndCommandBuffer(command_buffer[0]);
3553 }
3554 {
3555 VkCommandBufferBeginInfo begin_info{};
3556 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3557 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3558
3559 VkViewport viewport{};
3560 viewport.maxDepth = 1.0f;
3561 viewport.minDepth = 0.0f;
3562 viewport.width = 512;
3563 viewport.height = 512;
3564 viewport.x = 0;
3565 viewport.y = 0;
3566 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3567 vkEndCommandBuffer(command_buffer[1]);
3568 }
3569 {
3570 VkSubmitInfo submit_info{};
3571 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3572 submit_info.commandBufferCount = 1;
3573 submit_info.pCommandBuffers = &command_buffer[0];
3574 submit_info.signalSemaphoreCount = 1;
3575 submit_info.pSignalSemaphores = &semaphore;
3576 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3577 }
3578 {
3579 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3580 VkSubmitInfo submit_info{};
3581 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3582 submit_info.commandBufferCount = 1;
3583 submit_info.pCommandBuffers = &command_buffer[1];
3584 submit_info.waitSemaphoreCount = 1;
3585 submit_info.pWaitSemaphores = &semaphore;
3586 submit_info.pWaitDstStageMask = flags;
3587 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3588 }
3589
3590 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3591
3592 vkDestroyFence(m_device->device(), fence, nullptr);
3593 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3594 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3595 &command_buffer[0]);
3596 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3597
3598 m_errorMonitor->VerifyNotFound();
3599}
3600
3601// This is a positive test. No errors should be generated.
3602TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
3603
3604 TEST_DESCRIPTION(
3605 "Two command buffers, each in a separate QueueSubmit call "
3606 "on the same queue, no fences, followed by a third QueueSubmit with NO "
3607 "SubmitInfos but with a fence, followed by a WaitForFences call.");
3608
3609 m_errorMonitor->ExpectSuccess();
3610
3611 VkFence fence;
3612 VkFenceCreateInfo fence_create_info{};
3613 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3614 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3615
3616 VkCommandPool command_pool;
3617 VkCommandPoolCreateInfo pool_create_info{};
3618 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3619 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3620 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3621 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3622 &command_pool);
3623
3624 VkCommandBuffer command_buffer[2];
3625 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3626 command_buffer_allocate_info.sType =
3627 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3628 command_buffer_allocate_info.commandPool = command_pool;
3629 command_buffer_allocate_info.commandBufferCount = 2;
3630 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3631 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3632 command_buffer);
3633
3634 {
3635 VkCommandBufferBeginInfo begin_info{};
3636 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3637 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3638
3639 vkCmdPipelineBarrier(command_buffer[0],
3640 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3641 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3642 0, nullptr, 0, nullptr);
3643
3644 VkViewport viewport{};
3645 viewport.maxDepth = 1.0f;
3646 viewport.minDepth = 0.0f;
3647 viewport.width = 512;
3648 viewport.height = 512;
3649 viewport.x = 0;
3650 viewport.y = 0;
3651 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3652 vkEndCommandBuffer(command_buffer[0]);
3653 }
3654 {
3655 VkCommandBufferBeginInfo begin_info{};
3656 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3657 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3658
3659 VkViewport viewport{};
3660 viewport.maxDepth = 1.0f;
3661 viewport.minDepth = 0.0f;
3662 viewport.width = 512;
3663 viewport.height = 512;
3664 viewport.x = 0;
3665 viewport.y = 0;
3666 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3667 vkEndCommandBuffer(command_buffer[1]);
3668 }
3669 {
3670 VkSubmitInfo submit_info{};
3671 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3672 submit_info.commandBufferCount = 1;
3673 submit_info.pCommandBuffers = &command_buffer[0];
3674 submit_info.signalSemaphoreCount = 0;
3675 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
3676 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3677 }
3678 {
3679 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3680 VkSubmitInfo submit_info{};
3681 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3682 submit_info.commandBufferCount = 1;
3683 submit_info.pCommandBuffers = &command_buffer[1];
3684 submit_info.waitSemaphoreCount = 0;
3685 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
3686 submit_info.pWaitDstStageMask = flags;
3687 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3688 }
3689
3690 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
3691
3692 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3693
3694 vkDestroyFence(m_device->device(), fence, nullptr);
3695 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3696 &command_buffer[0]);
3697 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3698
3699 m_errorMonitor->VerifyNotFound();
3700}
3701
3702// This is a positive test. No errors should be generated.
3703TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
3704
3705 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3706 "on the same queue, the second having a fence, followed "
3707 "by a WaitForFences call.");
3708
3709 m_errorMonitor->ExpectSuccess();
3710
3711 VkFence fence;
3712 VkFenceCreateInfo fence_create_info{};
3713 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3714 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3715
3716 VkCommandPool command_pool;
3717 VkCommandPoolCreateInfo pool_create_info{};
3718 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3719 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3720 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3721 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3722 &command_pool);
3723
3724 VkCommandBuffer command_buffer[2];
3725 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3726 command_buffer_allocate_info.sType =
3727 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3728 command_buffer_allocate_info.commandPool = command_pool;
3729 command_buffer_allocate_info.commandBufferCount = 2;
3730 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3731 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3732 command_buffer);
3733
3734 {
3735 VkCommandBufferBeginInfo begin_info{};
3736 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3737 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3738
3739 vkCmdPipelineBarrier(command_buffer[0],
3740 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3741 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3742 0, nullptr, 0, nullptr);
3743
3744 VkViewport viewport{};
3745 viewport.maxDepth = 1.0f;
3746 viewport.minDepth = 0.0f;
3747 viewport.width = 512;
3748 viewport.height = 512;
3749 viewport.x = 0;
3750 viewport.y = 0;
3751 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3752 vkEndCommandBuffer(command_buffer[0]);
3753 }
3754 {
3755 VkCommandBufferBeginInfo begin_info{};
3756 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3757 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3758
3759 VkViewport viewport{};
3760 viewport.maxDepth = 1.0f;
3761 viewport.minDepth = 0.0f;
3762 viewport.width = 512;
3763 viewport.height = 512;
3764 viewport.x = 0;
3765 viewport.y = 0;
3766 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3767 vkEndCommandBuffer(command_buffer[1]);
3768 }
3769 {
3770 VkSubmitInfo submit_info{};
3771 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3772 submit_info.commandBufferCount = 1;
3773 submit_info.pCommandBuffers = &command_buffer[0];
3774 submit_info.signalSemaphoreCount = 0;
3775 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
3776 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3777 }
3778 {
3779 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3780 VkSubmitInfo submit_info{};
3781 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3782 submit_info.commandBufferCount = 1;
3783 submit_info.pCommandBuffers = &command_buffer[1];
3784 submit_info.waitSemaphoreCount = 0;
3785 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
3786 submit_info.pWaitDstStageMask = flags;
3787 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3788 }
3789
3790 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3791
3792 vkDestroyFence(m_device->device(), fence, nullptr);
3793 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3794 &command_buffer[0]);
3795 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3796
3797 m_errorMonitor->VerifyNotFound();
3798}
3799
3800// This is a positive test. No errors should be generated.
3801TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
3802
3803 TEST_DESCRIPTION(
3804 "Two command buffers each in a separate SubmitInfo sent in a single "
3805 "QueueSubmit call followed by a WaitForFences call.");
3806
3807 m_errorMonitor->ExpectSuccess();
3808
3809 VkFence fence;
3810 VkFenceCreateInfo fence_create_info{};
3811 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3812 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3813
3814 VkSemaphore semaphore;
3815 VkSemaphoreCreateInfo semaphore_create_info{};
3816 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3817 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3818 &semaphore);
3819
3820 VkCommandPool command_pool;
3821 VkCommandPoolCreateInfo pool_create_info{};
3822 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3823 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3824 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3825 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3826 &command_pool);
3827
3828 VkCommandBuffer command_buffer[2];
3829 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3830 command_buffer_allocate_info.sType =
3831 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3832 command_buffer_allocate_info.commandPool = command_pool;
3833 command_buffer_allocate_info.commandBufferCount = 2;
3834 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3835 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3836 command_buffer);
3837
3838 {
3839 VkCommandBufferBeginInfo begin_info{};
3840 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3841 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3842
3843 vkCmdPipelineBarrier(command_buffer[0],
3844 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3845 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3846 0, nullptr, 0, nullptr);
3847
3848 VkViewport viewport{};
3849 viewport.maxDepth = 1.0f;
3850 viewport.minDepth = 0.0f;
3851 viewport.width = 512;
3852 viewport.height = 512;
3853 viewport.x = 0;
3854 viewport.y = 0;
3855 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3856 vkEndCommandBuffer(command_buffer[0]);
3857 }
3858 {
3859 VkCommandBufferBeginInfo begin_info{};
3860 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3861 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3862
3863 VkViewport viewport{};
3864 viewport.maxDepth = 1.0f;
3865 viewport.minDepth = 0.0f;
3866 viewport.width = 512;
3867 viewport.height = 512;
3868 viewport.x = 0;
3869 viewport.y = 0;
3870 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3871 vkEndCommandBuffer(command_buffer[1]);
3872 }
3873 {
3874 VkSubmitInfo submit_info[2];
3875 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3876
3877 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3878 submit_info[0].pNext = NULL;
3879 submit_info[0].commandBufferCount = 1;
3880 submit_info[0].pCommandBuffers = &command_buffer[0];
3881 submit_info[0].signalSemaphoreCount = 1;
3882 submit_info[0].pSignalSemaphores = &semaphore;
3883 submit_info[0].waitSemaphoreCount = 0;
3884 submit_info[0].pWaitSemaphores = NULL;
3885 submit_info[0].pWaitDstStageMask = 0;
3886
3887 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3888 submit_info[1].pNext = NULL;
3889 submit_info[1].commandBufferCount = 1;
3890 submit_info[1].pCommandBuffers = &command_buffer[1];
3891 submit_info[1].waitSemaphoreCount = 1;
3892 submit_info[1].pWaitSemaphores = &semaphore;
3893 submit_info[1].pWaitDstStageMask = flags;
3894 submit_info[1].signalSemaphoreCount = 0;
3895 submit_info[1].pSignalSemaphores = NULL;
3896 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
3897 }
3898
3899 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3900
3901 vkDestroyFence(m_device->device(), fence, nullptr);
3902 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3903 &command_buffer[0]);
3904 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3905
3906 m_errorMonitor->VerifyNotFound();
3907}
3908
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003909TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003910 TEST_DESCRIPTION(
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003911 "Run a simple draw calls to validate failure when Depth Bias dynamic "
3912 "state is required but not correctly bound.");
3913
3914 // Dynamic depth bias
3915 m_errorMonitor->SetDesiredFailureMsg(
3916 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3917 "Dynamic depth bias state not set for this command buffer");
3918 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3919 BsoFailDepthBias);
3920 m_errorMonitor->VerifyFound();
3921}
3922
3923TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
3924 TEST_DESCRIPTION(
3925 "Run a simple draw calls to validate failure when Line Width dynamic "
3926 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003927
3928 // Dynamic line width
Karl Schultz6addd812016-02-02 17:17:23 -07003929 m_errorMonitor->SetDesiredFailureMsg(
3930 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003931 "Dynamic line width state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003932 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3933 BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003934 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003935}
3936
3937TEST_F(VkLayerTest, DynamicViewportNotBound) {
3938 TEST_DESCRIPTION(
3939 "Run a simple draw calls to validate failure when Viewport dynamic "
3940 "state is required but not correctly bound.");
3941
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003942 // Dynamic viewport state
Karl Schultz6addd812016-02-02 17:17:23 -07003943 m_errorMonitor->SetDesiredFailureMsg(
3944 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003945 "Dynamic viewport state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003946 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3947 BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003948 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003949}
3950
3951TEST_F(VkLayerTest, DynamicScissorNotBound) {
3952 TEST_DESCRIPTION(
3953 "Run a simple draw calls to validate failure when Scissor dynamic "
3954 "state is required but not correctly bound.");
3955
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003956 // Dynamic scissor state
Karl Schultz6addd812016-02-02 17:17:23 -07003957 m_errorMonitor->SetDesiredFailureMsg(
3958 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003959 "Dynamic scissor state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003960 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3961 BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003962 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003963}
3964
3965TEST_F(VkLayerTest, DynamicColorBlendNotBound) {
3966 TEST_DESCRIPTION(
3967 "Run a simple draw calls to validate failure when Color Blend dynamic "
3968 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003969 // Dynamic blend state
Karl Schultz6addd812016-02-02 17:17:23 -07003970 m_errorMonitor->SetDesiredFailureMsg(
3971 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003972 "Dynamic depth bounds state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003973 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3974 BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003975 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003976}
3977
3978TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
3979 TEST_DESCRIPTION(
3980 "Run a simple draw calls to validate failure when Stencil Read dynamic "
3981 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003982 // Dynamic stencil read mask
Karl Schultz6addd812016-02-02 17:17:23 -07003983 m_errorMonitor->SetDesiredFailureMsg(
3984 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003985 "Dynamic stencil read mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003986 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3987 BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003988 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003989}
3990
3991TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
3992 TEST_DESCRIPTION(
3993 "Run a simple draw calls to validate failure when Stencil Write dynamic"
3994 " state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003995 // Dynamic stencil write mask
Karl Schultz6addd812016-02-02 17:17:23 -07003996 m_errorMonitor->SetDesiredFailureMsg(
3997 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003998 "Dynamic stencil write mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003999 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4000 BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004001 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004002}
4003
4004TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
4005 TEST_DESCRIPTION(
4006 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4007 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004008 // Dynamic stencil reference
Karl Schultz6addd812016-02-02 17:17:23 -07004009 m_errorMonitor->SetDesiredFailureMsg(
4010 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004011 "Dynamic stencil reference state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004012 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4013 BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004014 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004015}
4016
Karl Schultz6addd812016-02-02 17:17:23 -07004017TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004018 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004019
Karl Schultz6addd812016-02-02 17:17:23 -07004020 m_errorMonitor->SetDesiredFailureMsg(
4021 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4022 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4023 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004024
4025 VkFenceCreateInfo fenceInfo = {};
4026 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4027 fenceInfo.pNext = NULL;
4028 fenceInfo.flags = 0;
4029
4030 ASSERT_NO_FATAL_FAILURE(InitState());
4031 ASSERT_NO_FATAL_FAILURE(InitViewport());
4032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4033
Karl Schultz6addd812016-02-02 17:17:23 -07004034 // We luck out b/c by default the framework creates CB w/ the
4035 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004036 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004037 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
4038 m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004039 EndCommandBuffer();
4040
4041 testFence.init(*m_device, fenceInfo);
4042
4043 // Bypass framework since it does the waits automatically
4044 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004045 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004046 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4047 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004048 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004049 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004050 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004051 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004052 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004053 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004054 submit_info.pSignalSemaphores = NULL;
4055
Karl Schultz6addd812016-02-02 17:17:23 -07004056 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
4057 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004058
Karl Schultz6addd812016-02-02 17:17:23 -07004059 // Cause validation error by re-submitting cmd buffer that should only be
4060 // submitted once
4061 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004062
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004063 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004064}
4065
Karl Schultz6addd812016-02-02 17:17:23 -07004066TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004067 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07004068 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004069
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004070 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004071 "Unable to allocate 1 descriptors of "
4072 "type "
4073 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004074
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004075 ASSERT_NO_FATAL_FAILURE(InitState());
4076 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004077
Karl Schultz6addd812016-02-02 17:17:23 -07004078 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4079 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004080 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004081 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
4082 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004083
4084 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004085 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4086 ds_pool_ci.pNext = NULL;
4087 ds_pool_ci.flags = 0;
4088 ds_pool_ci.maxSets = 1;
4089 ds_pool_ci.poolSizeCount = 1;
4090 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004091
4092 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004093 err =
4094 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004095 ASSERT_VK_SUCCESS(err);
4096
4097 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004098 dsl_binding.binding = 0;
4099 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4100 dsl_binding.descriptorCount = 1;
4101 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4102 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004103
4104 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004105 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4106 ds_layout_ci.pNext = NULL;
4107 ds_layout_ci.bindingCount = 1;
4108 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004109
4110 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004111 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4112 &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004113 ASSERT_VK_SUCCESS(err);
4114
4115 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004116 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004117 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004118 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004119 alloc_info.descriptorPool = ds_pool;
4120 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004121 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4122 &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004123
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004124 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004125
Chia-I Wuf7458c52015-10-26 21:10:41 +08004126 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4127 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004128}
4129
Karl Schultz6addd812016-02-02 17:17:23 -07004130TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4131 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004132
Karl Schultz6addd812016-02-02 17:17:23 -07004133 m_errorMonitor->SetDesiredFailureMsg(
4134 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4135 "It is invalid to call vkFreeDescriptorSets() with a pool created "
4136 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004137
Tobin Ehlise735c692015-10-08 13:13:50 -06004138 ASSERT_NO_FATAL_FAILURE(InitState());
4139 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004140
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004141 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004142 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4143 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004144
4145 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004146 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4147 ds_pool_ci.pNext = NULL;
4148 ds_pool_ci.maxSets = 1;
4149 ds_pool_ci.poolSizeCount = 1;
4150 ds_pool_ci.flags = 0;
4151 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4152 // app can only call vkResetDescriptorPool on this pool.;
4153 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004154
4155 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004156 err =
4157 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004158 ASSERT_VK_SUCCESS(err);
4159
4160 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004161 dsl_binding.binding = 0;
4162 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4163 dsl_binding.descriptorCount = 1;
4164 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4165 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004166
4167 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004168 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4169 ds_layout_ci.pNext = NULL;
4170 ds_layout_ci.bindingCount = 1;
4171 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004172
4173 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004174 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4175 &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004176 ASSERT_VK_SUCCESS(err);
4177
4178 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004179 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004180 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004181 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004182 alloc_info.descriptorPool = ds_pool;
4183 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004184 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4185 &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004186 ASSERT_VK_SUCCESS(err);
4187
4188 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004189 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004190
Chia-I Wuf7458c52015-10-26 21:10:41 +08004191 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4192 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004193}
4194
Karl Schultz6addd812016-02-02 17:17:23 -07004195TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004196 // Attempt to clear Descriptor Pool with bad object.
4197 // ObjectTracker should catch this.
4198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4199 "Invalid VkDescriptorPool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004200 uint64_t fake_pool_handle = 0xbaad6001;
4201 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4202 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004203 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004204}
4205
Karl Schultz6addd812016-02-02 17:17:23 -07004206TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004207 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4208 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004209 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004210 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004211
4212 uint64_t fake_set_handle = 0xbaad6001;
4213 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004214 VkResult err;
4215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4216 "Invalid VkDescriptorSet Object 0xbaad6001");
4217
4218 ASSERT_NO_FATAL_FAILURE(InitState());
4219
4220 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4221 layout_bindings[0].binding = 0;
4222 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4223 layout_bindings[0].descriptorCount = 1;
4224 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4225 layout_bindings[0].pImmutableSamplers = NULL;
4226
4227 VkDescriptorSetLayout descriptor_set_layout;
4228 VkDescriptorSetLayoutCreateInfo dslci = {};
4229 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4230 dslci.pNext = NULL;
4231 dslci.bindingCount = 1;
4232 dslci.pBindings = layout_bindings;
4233 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004234 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004235
4236 VkPipelineLayout pipeline_layout;
4237 VkPipelineLayoutCreateInfo plci = {};
4238 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4239 plci.pNext = NULL;
4240 plci.setLayoutCount = 1;
4241 plci.pSetLayouts = &descriptor_set_layout;
4242 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004243 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004244
4245 BeginCommandBuffer();
4246 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004247 pipeline_layout, 0, 1, &bad_set, 0, NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004248 m_errorMonitor->VerifyFound();
4249 EndCommandBuffer();
4250 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4251 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004252}
4253
Karl Schultz6addd812016-02-02 17:17:23 -07004254TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004255 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4256 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004257 uint64_t fake_layout_handle = 0xbaad6001;
4258 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4260 "Invalid VkDescriptorSetLayout Object 0xbaad6001");
4261
4262 VkPipelineLayout pipeline_layout;
4263 VkPipelineLayoutCreateInfo plci = {};
4264 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4265 plci.pNext = NULL;
4266 plci.setLayoutCount = 1;
4267 plci.pSetLayouts = &bad_layout;
4268 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4269
4270 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004271}
4272
Karl Schultz6addd812016-02-02 17:17:23 -07004273TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004274 // Attempt to bind an invalid Pipeline to a valid Command Buffer
4275 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004276 // Create a valid cmd buffer
4277 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004278 uint64_t fake_pipeline_handle = 0xbaad6001;
4279 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4281 "Invalid VkPipeline Object 0xbaad6001");
4282 ASSERT_NO_FATAL_FAILURE(InitState());
4283 BeginCommandBuffer();
4284 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4285 VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
4286 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004287
4288 // Now issue a draw call with no pipeline bound
4289 m_errorMonitor->SetDesiredFailureMsg(
4290 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4291 "At Draw/Dispatch time no valid VkPipeline is bound!");
4292 ASSERT_NO_FATAL_FAILURE(InitState());
4293 BeginCommandBuffer();
4294 Draw(1, 0, 0, 0);
4295 m_errorMonitor->VerifyFound();
4296 // Finally same check once more but with Dispatch/Compute
4297 m_errorMonitor->SetDesiredFailureMsg(
4298 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4299 "At Draw/Dispatch time no valid VkPipeline is bound!");
4300 ASSERT_NO_FATAL_FAILURE(InitState());
4301 BeginCommandBuffer();
4302 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
4303 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004304}
4305
Karl Schultz6addd812016-02-02 17:17:23 -07004306TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
4307 // Create and update CommandBuffer then call QueueSubmit w/o calling End on
4308 // CommandBuffer
4309 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004310
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07004311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004312 " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004313
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004314 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06004315 ASSERT_NO_FATAL_FAILURE(InitViewport());
4316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004317 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004318 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4319 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004320
4321 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004322 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4323 ds_pool_ci.pNext = NULL;
4324 ds_pool_ci.maxSets = 1;
4325 ds_pool_ci.poolSizeCount = 1;
4326 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06004327
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004328 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004329 err =
4330 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004331 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004332
Tony Barboureb254902015-07-15 12:50:33 -06004333 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004334 dsl_binding.binding = 0;
4335 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4336 dsl_binding.descriptorCount = 1;
4337 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4338 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004339
Tony Barboureb254902015-07-15 12:50:33 -06004340 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004341 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4342 ds_layout_ci.pNext = NULL;
4343 ds_layout_ci.bindingCount = 1;
4344 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004345 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004346 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4347 &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004348 ASSERT_VK_SUCCESS(err);
4349
4350 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004351 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004352 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004353 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004354 alloc_info.descriptorPool = ds_pool;
4355 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004356 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4357 &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004358 ASSERT_VK_SUCCESS(err);
4359
Tony Barboureb254902015-07-15 12:50:33 -06004360 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004361 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4362 pipeline_layout_ci.pNext = NULL;
4363 pipeline_layout_ci.setLayoutCount = 1;
4364 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004365
4366 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004367 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4368 &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004369 ASSERT_VK_SUCCESS(err);
4370
Karl Schultz6addd812016-02-02 17:17:23 -07004371 VkShaderObj vs(m_device, bindStateVertShaderText,
4372 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06004373 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07004374 // on more devices
4375 VkShaderObj fs(m_device, bindStateFragShaderText,
4376 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004377
Tony Barbourc95e4ac2015-08-04 17:05:26 -06004378 VkPipelineObj pipe(m_device);
4379 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06004380 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06004381 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06004382 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004383
4384 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004385 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4386 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4387 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4388 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4389 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004390
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004391 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06004392
Chia-I Wuf7458c52015-10-26 21:10:41 +08004393 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4394 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4395 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004396}
4397
Karl Schultz6addd812016-02-02 17:17:23 -07004398TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004399 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07004400 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004401
Karl Schultz6addd812016-02-02 17:17:23 -07004402 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004403 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
4404 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004405
4406 ASSERT_NO_FATAL_FAILURE(InitState());
4407 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004408 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
4409 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004410
4411 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004412 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4413 ds_pool_ci.pNext = NULL;
4414 ds_pool_ci.maxSets = 1;
4415 ds_pool_ci.poolSizeCount = 1;
4416 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004417
4418 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004419 err =
4420 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004421 ASSERT_VK_SUCCESS(err);
4422
4423 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004424 dsl_binding.binding = 0;
4425 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
4426 dsl_binding.descriptorCount = 1;
4427 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4428 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004429
4430 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004431 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4432 ds_layout_ci.pNext = NULL;
4433 ds_layout_ci.bindingCount = 1;
4434 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004435 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004436 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4437 &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004438 ASSERT_VK_SUCCESS(err);
4439
4440 VkDescriptorSet descriptorSet;
4441 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004442 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004443 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004444 alloc_info.descriptorPool = ds_pool;
4445 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004446 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4447 &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004448 ASSERT_VK_SUCCESS(err);
4449
Karl Schultz6addd812016-02-02 17:17:23 -07004450 VkBufferView view =
4451 (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004452 VkWriteDescriptorSet descriptor_write;
4453 memset(&descriptor_write, 0, sizeof(descriptor_write));
4454 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4455 descriptor_write.dstSet = descriptorSet;
4456 descriptor_write.dstBinding = 0;
4457 descriptor_write.descriptorCount = 1;
4458 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
4459 descriptor_write.pTexelBufferView = &view;
4460
4461 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4462
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004463 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004464
4465 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4466 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4467}
4468
Karl Schultz6addd812016-02-02 17:17:23 -07004469TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
4470 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
4471 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07004472 // 1. No dynamicOffset supplied
4473 // 2. Too many dynamicOffsets supplied
4474 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07004475 VkResult err;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004477 " requires 1 dynamicOffsets, but only "
4478 "0 dynamicOffsets are left in "
4479 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004480
4481 ASSERT_NO_FATAL_FAILURE(InitState());
4482 ASSERT_NO_FATAL_FAILURE(InitViewport());
4483 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4484
4485 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004486 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
4487 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004488
4489 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004490 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4491 ds_pool_ci.pNext = NULL;
4492 ds_pool_ci.maxSets = 1;
4493 ds_pool_ci.poolSizeCount = 1;
4494 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004495
4496 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004497 err =
4498 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004499 ASSERT_VK_SUCCESS(err);
4500
4501 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004502 dsl_binding.binding = 0;
4503 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
4504 dsl_binding.descriptorCount = 1;
4505 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4506 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004507
4508 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004509 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4510 ds_layout_ci.pNext = NULL;
4511 ds_layout_ci.bindingCount = 1;
4512 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004513 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004514 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4515 &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004516 ASSERT_VK_SUCCESS(err);
4517
4518 VkDescriptorSet descriptorSet;
4519 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004520 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004521 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004522 alloc_info.descriptorPool = ds_pool;
4523 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004524 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4525 &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004526 ASSERT_VK_SUCCESS(err);
4527
4528 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004529 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4530 pipeline_layout_ci.pNext = NULL;
4531 pipeline_layout_ci.setLayoutCount = 1;
4532 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004533
4534 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004535 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4536 &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004537 ASSERT_VK_SUCCESS(err);
4538
4539 // Create a buffer to update the descriptor with
4540 uint32_t qfi = 0;
4541 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004542 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4543 buffCI.size = 1024;
4544 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4545 buffCI.queueFamilyIndexCount = 1;
4546 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004547
4548 VkBuffer dyub;
4549 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4550 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004551 // Allocate memory and bind to buffer so we can make it to the appropriate
4552 // error
4553 VkMemoryAllocateInfo mem_alloc = {};
4554 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4555 mem_alloc.pNext = NULL;
4556 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12004557 mem_alloc.memoryTypeIndex = 0;
4558
4559 VkMemoryRequirements memReqs;
4560 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
4561 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc,
4562 0);
4563 if (!pass) {
4564 vkDestroyBuffer(m_device->device(), dyub, NULL);
4565 return;
4566 }
4567
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004568 VkDeviceMemory mem;
4569 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4570 ASSERT_VK_SUCCESS(err);
4571 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4572 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004573 // Correctly update descriptor to avoid "NOT_UPDATED" error
4574 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004575 buffInfo.buffer = dyub;
4576 buffInfo.offset = 0;
4577 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004578
4579 VkWriteDescriptorSet descriptor_write;
4580 memset(&descriptor_write, 0, sizeof(descriptor_write));
4581 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4582 descriptor_write.dstSet = descriptorSet;
4583 descriptor_write.dstBinding = 0;
4584 descriptor_write.descriptorCount = 1;
4585 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
4586 descriptor_write.pBufferInfo = &buffInfo;
4587
4588 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4589
4590 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004591 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4592 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4593 1, &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004594 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07004595 uint32_t pDynOff[2] = {512, 756};
4596 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Karl Schultz6addd812016-02-02 17:17:23 -07004597 m_errorMonitor->SetDesiredFailureMsg(
4598 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07004599 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
Karl Schultz6addd812016-02-02 17:17:23 -07004600 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4601 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4602 1, &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12004603 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07004604 // Finally cause error due to dynamicOffset being too big
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4606 " dynamic offset 512 combined with "
4607 "offset 0 and range 1024 that "
4608 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07004609 // Create PSO to be used for draw-time errors below
4610 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12004611 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07004612 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07004613 "out gl_PerVertex { \n"
4614 " vec4 gl_Position;\n"
4615 "};\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07004616 "void main(){\n"
4617 " gl_Position = vec4(1);\n"
4618 "}\n";
4619 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12004620 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07004621 "\n"
4622 "layout(location=0) out vec4 x;\n"
4623 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4624 "void main(){\n"
4625 " x = vec4(bar.y);\n"
4626 "}\n";
4627 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4628 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4629 VkPipelineObj pipe(m_device);
4630 pipe.AddShader(&vs);
4631 pipe.AddShader(&fs);
4632 pipe.AddColorAttachment();
4633 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4634
Karl Schultz6addd812016-02-02 17:17:23 -07004635 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4636 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4637 // This update should succeed, but offset size of 512 will overstep buffer
4638 // /w range 1024 & size 1024
4639 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4640 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4641 1, &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004642 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004643 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004644
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004645 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06004646 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004647
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004648 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4649 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4650}
4651
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004652TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004653 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004654 ASSERT_NO_FATAL_FAILURE(InitState());
4655 ASSERT_NO_FATAL_FAILURE(InitViewport());
4656 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4657
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004658 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004659 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004660 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4661 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4662 pipeline_layout_ci.pushConstantRangeCount = 1;
4663 pipeline_layout_ci.pPushConstantRanges = &pc_range;
4664
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004665 //
4666 // Check for invalid push constant ranges in pipeline layouts.
4667 //
4668 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06004669 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004670 char const *msg;
4671 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004672
Karl Schultzc81037d2016-05-12 08:11:23 -06004673 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
4674 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
4675 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
4676 "vkCreatePipelineLayout() call has push constants index 0 with "
4677 "size 0."},
4678 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
4679 "vkCreatePipelineLayout() call has push constants index 0 with "
4680 "size 1."},
4681 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
4682 "vkCreatePipelineLayout() call has push constants index 0 with "
4683 "size 1."},
4684 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
4685 "vkCreatePipelineLayout() call has push constants index 0 with "
4686 "size 0."},
4687 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
4688 "vkCreatePipelineLayout() call has push constants index 0 with "
4689 "offset 1. Offset must"},
4690 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
4691 "vkCreatePipelineLayout() call has push constants index 0 "
4692 "with offset "},
4693 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
4694 "vkCreatePipelineLayout() call has push constants "
4695 "index 0 with offset "},
4696 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
4697 "vkCreatePipelineLayout() call has push constants index 0 "
4698 "with offset "},
4699 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
4700 "vkCreatePipelineLayout() call has push "
4701 "constants index 0 with offset "},
4702 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
4703 "vkCreatePipelineLayout() call has push "
4704 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004705 }};
4706
4707 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06004708 for (const auto &iter : range_tests) {
4709 pc_range = iter.range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4711 iter.msg);
4712 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
4713 NULL, &pipeline_layout);
4714 m_errorMonitor->VerifyFound();
4715 if (VK_SUCCESS == err) {
4716 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4717 }
4718 }
4719
4720 // Check for invalid stage flag
4721 pc_range.offset = 0;
4722 pc_range.size = 16;
4723 pc_range.stageFlags = 0;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004724 m_errorMonitor->SetDesiredFailureMsg(
4725 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004726 "vkCreatePipelineLayout() call has no stageFlags set.");
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004727 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4728 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004729 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004730 if (VK_SUCCESS == err) {
4731 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4732 }
4733
4734 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06004735 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004736 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06004737 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004738 char const *msg;
4739 };
4740
Karl Schultzc81037d2016-05-12 08:11:23 -06004741 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004742 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4743 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4744 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4745 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4746 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4747 "vkCreatePipelineLayout() call has push constants with overlapping "
4748 "ranges: 0:[0, 4), 1:[0, 4)"},
4749 {
4750 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4751 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4752 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4753 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
4754 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
4755 "vkCreatePipelineLayout() call has push constants with "
4756 "overlapping "
4757 "ranges: 3:[12, 20), 4:[16, 20)",
4758 },
4759 {
4760 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4761 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
4762 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4763 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4764 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4765 "vkCreatePipelineLayout() call has push constants with "
4766 "overlapping "
4767 "ranges: 0:[16, 20), 1:[12, 20)",
4768 },
4769 {
4770 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4771 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4772 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4773 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
4774 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4775 "vkCreatePipelineLayout() call has push constants with "
4776 "overlapping "
4777 "ranges: 0:[16, 20), 3:[12, 20)",
4778 },
4779 {
4780 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4781 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
4782 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
4783 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
4784 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
4785 "vkCreatePipelineLayout() call has push constants with "
4786 "overlapping "
4787 "ranges: 0:[16, 20), 2:[4, 100)",
4788 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004789
Karl Schultzc81037d2016-05-12 08:11:23 -06004790 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004791 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06004792 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
4793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004794 iter.msg);
4795 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
4796 NULL, &pipeline_layout);
4797 m_errorMonitor->VerifyFound();
4798 if (VK_SUCCESS == err) {
4799 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4800 }
4801 }
4802
4803 // Run some positive tests to make sure overlap checking in the layer is OK
Karl Schultzc81037d2016-05-12 08:11:23 -06004804 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos =
4805 {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4806 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4807 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4808 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
4809 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
4810 ""},
4811 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
4812 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
4813 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
4814 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
4815 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4816 ""}}};
4817 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004818 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
4819 m_errorMonitor->ExpectSuccess();
4820 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
4821 NULL, &pipeline_layout);
4822 m_errorMonitor->VerifyNotFound();
4823 if (VK_SUCCESS == err) {
4824 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4825 }
4826 }
4827
4828 //
4829 // CmdPushConstants tests
4830 //
Karl Schultzc81037d2016-05-12 08:11:23 -06004831 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004832
4833 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzc81037d2016-05-12 08:11:23 -06004834 const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{
4835 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
4836 "vkCmdPushConstants() call has push constants with size 0. Size "
4837 "must be greater than zero and a multiple of 4."},
4838 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
4839 "vkCmdPushConstants() call has push constants with size 1. Size "
4840 "must be greater than zero and a multiple of 4."},
4841 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
4842 "vkCmdPushConstants() call has push constants with size 1. Size "
4843 "must be greater than zero and a multiple of 4."},
4844 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
4845 "vkCmdPushConstants() call has push constants with offset 1. "
4846 "Offset must be a multiple of 4."},
4847 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
4848 "vkCmdPushConstants() call has push constants with offset 1. "
4849 "Offset must be a multiple of 4."},
4850 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
4851 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
4852 "0x1 not within flag-matching ranges in pipeline layout"},
4853 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
4854 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
4855 "0x1 not within flag-matching ranges in pipeline layout"},
4856 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
4857 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
4858 "0x1 not within flag-matching ranges in pipeline layout"},
4859 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
4860 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
4861 "0x1 not within flag-matching ranges in pipeline layout"},
4862 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
4863 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
4864 "any of the ranges in pipeline layout"},
4865 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
4866 0, 16},
4867 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
4868 "any of the ranges in pipeline layout"},
4869 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004870 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004871 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004872 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004873 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004874 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004875 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004876 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004877 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004878 "vkCmdPushConstants() call has push constants with offset "},
4879 }};
4880
4881 // Two ranges for testing robustness
Karl Schultzc81037d2016-05-12 08:11:23 -06004882 const VkPushConstantRange pc_range2[] = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004883 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06004884 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004885 };
Karl Schultzc81037d2016-05-12 08:11:23 -06004886 pipeline_layout_ci.pushConstantRangeCount =
4887 sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004888 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004889 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4890 &pipeline_layout);
4891 ASSERT_VK_SUCCESS(err);
4892 BeginCommandBuffer();
Karl Schultzc81037d2016-05-12 08:11:23 -06004893 for (const auto &iter : cmd_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4895 iter.msg);
4896 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
Karl Schultzc81037d2016-05-12 08:11:23 -06004897 iter.range.stageFlags, iter.range.offset,
4898 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004899 m_errorMonitor->VerifyFound();
4900 }
4901
4902 // Check for invalid stage flag
4903 m_errorMonitor->SetDesiredFailureMsg(
4904 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4905 "vkCmdPushConstants() call has no stageFlags set.");
4906 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0,
Karl Schultzc81037d2016-05-12 08:11:23 -06004907 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004908 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06004909 EndCommandBuffer();
4910 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
4911 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004912
Karl Schultzc81037d2016-05-12 08:11:23 -06004913 // overlapping range tests with cmd
4914 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
4915 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
4916 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
4917 "0x1 not within flag-matching ranges in pipeline layout"},
4918 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4919 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
4920 "0x1 not within flag-matching ranges in pipeline layout"},
4921 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
4922 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
4923 "0x1 not within flag-matching ranges in pipeline layout"},
4924 }};
4925 const VkPushConstantRange pc_range3[] = {
4926 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
4927 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
4928 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4929 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
4930 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
4931 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
4932 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
4933 };
4934 pipeline_layout_ci.pushConstantRangeCount =
4935 sizeof(pc_range3) / sizeof(VkPushConstantRange);
4936 pipeline_layout_ci.pPushConstantRanges = pc_range3;
4937 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4938 &pipeline_layout);
4939 ASSERT_VK_SUCCESS(err);
4940 BeginCommandBuffer();
4941 for (const auto &iter : cmd_overlap_tests) {
4942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4943 iter.msg);
4944 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
4945 iter.range.stageFlags, iter.range.offset,
4946 iter.range.size, dummy_values);
4947 m_errorMonitor->VerifyFound();
4948 }
4949 EndCommandBuffer();
4950 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
4951 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4952
4953 // positive overlapping range tests with cmd
4954 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
4955 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
4956 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
4957 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
4958 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
4959 }};
4960 const VkPushConstantRange pc_range4[] = {
4961 {VK_SHADER_STAGE_VERTEX_BIT, 0, 64},
4962 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
4963 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
4964 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4965 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
4966 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
4967 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
4968 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
4969 };
4970 pipeline_layout_ci.pushConstantRangeCount =
4971 sizeof(pc_range4) / sizeof(VkPushConstantRange);
4972 pipeline_layout_ci.pPushConstantRanges = pc_range4;
4973 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4974 &pipeline_layout);
4975 ASSERT_VK_SUCCESS(err);
4976 BeginCommandBuffer();
4977 for (const auto &iter : cmd_overlap_tests_pos) {
4978 m_errorMonitor->ExpectSuccess();
4979 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
4980 iter.range.stageFlags, iter.range.offset,
4981 iter.range.size, dummy_values);
4982 m_errorMonitor->VerifyNotFound();
4983 }
4984 EndCommandBuffer();
4985 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004986 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4987}
4988
Karl Schultz6addd812016-02-02 17:17:23 -07004989TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07004990 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07004991 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07004992
4993 ASSERT_NO_FATAL_FAILURE(InitState());
4994 ASSERT_NO_FATAL_FAILURE(InitViewport());
4995 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4996
4997 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
4998 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004999 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5000 ds_type_count[0].descriptorCount = 10;
5001 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5002 ds_type_count[1].descriptorCount = 2;
5003 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5004 ds_type_count[2].descriptorCount = 2;
5005 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
5006 ds_type_count[3].descriptorCount = 5;
5007 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
5008 // type
5009 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
5010 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
5011 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005012
5013 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005014 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5015 ds_pool_ci.pNext = NULL;
5016 ds_pool_ci.maxSets = 5;
5017 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
5018 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005019
5020 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005021 err =
5022 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005023 ASSERT_VK_SUCCESS(err);
5024
5025 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
5026 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005027 dsl_binding[0].binding = 0;
5028 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5029 dsl_binding[0].descriptorCount = 5;
5030 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
5031 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005032
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005033 // Create layout identical to set0 layout but w/ different stageFlags
5034 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005035 dsl_fs_stage_only.binding = 0;
5036 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5037 dsl_fs_stage_only.descriptorCount = 5;
5038 dsl_fs_stage_only.stageFlags =
5039 VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
5040 // bind time
5041 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005042 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005043 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5044 ds_layout_ci.pNext = NULL;
5045 ds_layout_ci.bindingCount = 1;
5046 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005047 static const uint32_t NUM_LAYOUTS = 4;
5048 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005049 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005050 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
5051 // layout for error case
5052 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5053 &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005054 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005055 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005056 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5057 &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005058 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005059 dsl_binding[0].binding = 0;
5060 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005061 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005062 dsl_binding[1].binding = 1;
5063 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5064 dsl_binding[1].descriptorCount = 2;
5065 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
5066 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005067 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005068 ds_layout_ci.bindingCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005069 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5070 &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005071 ASSERT_VK_SUCCESS(err);
5072 dsl_binding[0].binding = 0;
5073 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005074 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005075 ds_layout_ci.bindingCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07005076 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5077 &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005078 ASSERT_VK_SUCCESS(err);
5079 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005080 dsl_binding[0].descriptorCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005081 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5082 &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005083 ASSERT_VK_SUCCESS(err);
5084
5085 static const uint32_t NUM_SETS = 4;
5086 VkDescriptorSet descriptorSet[NUM_SETS] = {};
5087 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005088 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005089 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005090 alloc_info.descriptorPool = ds_pool;
5091 alloc_info.pSetLayouts = ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005092 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5093 descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005094 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005095 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005096 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005097 alloc_info.pSetLayouts = &ds_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005098 err =
5099 vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005100 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005101
5102 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005103 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5104 pipeline_layout_ci.pNext = NULL;
5105 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
5106 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005107
5108 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005109 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5110 &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005111 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005112 // Create pipelineLayout with only one setLayout
5113 pipeline_layout_ci.setLayoutCount = 1;
5114 VkPipelineLayout single_pipe_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005115 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5116 &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005117 ASSERT_VK_SUCCESS(err);
5118 // Create pipelineLayout with 2 descriptor setLayout at index 0
5119 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
5120 VkPipelineLayout pipe_layout_one_desc;
Karl Schultz6addd812016-02-02 17:17:23 -07005121 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5122 &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005123 ASSERT_VK_SUCCESS(err);
5124 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
5125 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
5126 VkPipelineLayout pipe_layout_five_samp;
Karl Schultz6addd812016-02-02 17:17:23 -07005127 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5128 &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005129 ASSERT_VK_SUCCESS(err);
5130 // Create pipelineLayout with UB type, but stageFlags for FS only
5131 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
5132 VkPipelineLayout pipe_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005133 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5134 &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005135 ASSERT_VK_SUCCESS(err);
5136 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
5137 VkDescriptorSetLayout pl_bad_s0[2] = {};
5138 pl_bad_s0[0] = ds_layout_fs_only;
5139 pl_bad_s0[1] = ds_layout[1];
5140 pipeline_layout_ci.setLayoutCount = 2;
5141 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
5142 VkPipelineLayout pipe_layout_bad_set0;
Karl Schultz6addd812016-02-02 17:17:23 -07005143 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5144 &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005145 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005146
5147 // Create a buffer to update the descriptor with
5148 uint32_t qfi = 0;
5149 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005150 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5151 buffCI.size = 1024;
5152 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5153 buffCI.queueFamilyIndexCount = 1;
5154 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005155
5156 VkBuffer dyub;
5157 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5158 ASSERT_VK_SUCCESS(err);
5159 // Correctly update descriptor to avoid "NOT_UPDATED" error
5160 static const uint32_t NUM_BUFFS = 5;
5161 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005162 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005163 buffInfo[i].buffer = dyub;
5164 buffInfo[i].offset = 0;
5165 buffInfo[i].range = 1024;
5166 }
Karl Schultz6addd812016-02-02 17:17:23 -07005167 VkImage image;
5168 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5169 const int32_t tex_width = 32;
5170 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005171 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005172 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5173 image_create_info.pNext = NULL;
5174 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5175 image_create_info.format = tex_format;
5176 image_create_info.extent.width = tex_width;
5177 image_create_info.extent.height = tex_height;
5178 image_create_info.extent.depth = 1;
5179 image_create_info.mipLevels = 1;
5180 image_create_info.arrayLayers = 1;
5181 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5182 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5183 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5184 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005185 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5186 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005187
Karl Schultz6addd812016-02-02 17:17:23 -07005188 VkMemoryRequirements memReqs;
5189 VkDeviceMemory imageMem;
5190 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005191 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005192 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5193 memAlloc.pNext = NULL;
5194 memAlloc.allocationSize = 0;
5195 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005196 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
5197 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07005198 pass =
5199 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005200 ASSERT_TRUE(pass);
5201 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
5202 ASSERT_VK_SUCCESS(err);
5203 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
5204 ASSERT_VK_SUCCESS(err);
5205
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005206 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005207 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5208 image_view_create_info.image = image;
5209 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5210 image_view_create_info.format = tex_format;
5211 image_view_create_info.subresourceRange.layerCount = 1;
5212 image_view_create_info.subresourceRange.baseMipLevel = 0;
5213 image_view_create_info.subresourceRange.levelCount = 1;
5214 image_view_create_info.subresourceRange.aspectMask =
5215 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005216
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005217 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07005218 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
5219 &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005220 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005221 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005222 imageInfo[0].imageView = view;
5223 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5224 imageInfo[1].imageView = view;
5225 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005226 imageInfo[2].imageView = view;
5227 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5228 imageInfo[3].imageView = view;
5229 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005230
5231 static const uint32_t NUM_SET_UPDATES = 3;
5232 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
5233 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5234 descriptor_write[0].dstSet = descriptorSet[0];
5235 descriptor_write[0].dstBinding = 0;
5236 descriptor_write[0].descriptorCount = 5;
5237 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5238 descriptor_write[0].pBufferInfo = buffInfo;
5239 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5240 descriptor_write[1].dstSet = descriptorSet[1];
5241 descriptor_write[1].dstBinding = 0;
5242 descriptor_write[1].descriptorCount = 2;
5243 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5244 descriptor_write[1].pImageInfo = imageInfo;
5245 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5246 descriptor_write[2].dstSet = descriptorSet[1];
5247 descriptor_write[2].dstBinding = 1;
5248 descriptor_write[2].descriptorCount = 2;
5249 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005250 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005251
5252 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005253
Tobin Ehlis88452832015-12-03 09:40:56 -07005254 // Create PSO to be used for draw-time errors below
5255 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005256 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005257 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005258 "out gl_PerVertex {\n"
5259 " vec4 gl_Position;\n"
5260 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005261 "void main(){\n"
5262 " gl_Position = vec4(1);\n"
5263 "}\n";
5264 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005265 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005266 "\n"
5267 "layout(location=0) out vec4 x;\n"
5268 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5269 "void main(){\n"
5270 " x = vec4(bar.y);\n"
5271 "}\n";
5272 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5273 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005274 VkPipelineObj pipe(m_device);
5275 pipe.AddShader(&vs);
5276 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07005277 pipe.AddColorAttachment();
5278 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07005279
5280 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07005281
Karl Schultz6addd812016-02-02 17:17:23 -07005282 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5283 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5284 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
5285 // of PSO
5286 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
5287 // cmd_pipeline.c
5288 // due to the fact that cmd_alloc_dset_data() has not been called in
5289 // cmd_bind_graphics_pipeline()
5290 // TODO : Want to cause various binding incompatibility issues here to test
5291 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07005292 // First cause various verify_layout_compatibility() fails
5293 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005294 // verify_set_layout_compatibility fail cases:
5295 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultz6addd812016-02-02 17:17:23 -07005296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5297 " due to: invalid VkPipelineLayout ");
5298 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5299 VK_PIPELINE_BIND_POINT_GRAPHICS,
5300 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1,
5301 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005302 m_errorMonitor->VerifyFound();
5303
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005304 // 2. layoutIndex exceeds # of layouts in layout
Karl Schultz6addd812016-02-02 17:17:23 -07005305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5306 " attempting to bind set to index 1");
5307 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5308 VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout,
5309 0, 2, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005310 m_errorMonitor->VerifyFound();
5311
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005312 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005313 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
5314 // descriptors
5315 m_errorMonitor->SetDesiredFailureMsg(
5316 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005317 " has 2 descriptors, but DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005318 vkCmdBindDescriptorSets(
5319 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5320 pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005321 m_errorMonitor->VerifyFound();
5322
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005323 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
5324 // 4. same # of descriptors but mismatch in type
Karl Schultz6addd812016-02-02 17:17:23 -07005325 m_errorMonitor->SetDesiredFailureMsg(
5326 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005327 " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
Karl Schultz6addd812016-02-02 17:17:23 -07005328 vkCmdBindDescriptorSets(
5329 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5330 pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005331 m_errorMonitor->VerifyFound();
5332
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005333 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
5334 // 5. same # of descriptors but mismatch in stageFlags
Karl Schultz6addd812016-02-02 17:17:23 -07005335 m_errorMonitor->SetDesiredFailureMsg(
5336 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005337 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005338 vkCmdBindDescriptorSets(
5339 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5340 pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005341 m_errorMonitor->VerifyFound();
5342
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005343 // Cause INFO messages due to disturbing previously bound Sets
5344 // First bind sets 0 & 1
Karl Schultz6addd812016-02-02 17:17:23 -07005345 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5346 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5347 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005348 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Karl Schultz6addd812016-02-02 17:17:23 -07005349 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07005350 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005351 " previously bound as set #0 was disturbed ");
5352 vkCmdBindDescriptorSets(
5353 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5354 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005355 m_errorMonitor->VerifyFound();
5356
Karl Schultz6addd812016-02-02 17:17:23 -07005357 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5358 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5359 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005360 // 2. Disturb set after last bound set
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07005361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005362 " newly bound as set #0 so set #1 and "
5363 "any subsequent sets were disturbed ");
5364 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5365 VK_PIPELINE_BIND_POINT_GRAPHICS,
5366 pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005367 m_errorMonitor->VerifyFound();
5368
Tobin Ehlis88452832015-12-03 09:40:56 -07005369 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07005370 // 1. Error due to not binding required set (we actually use same code as
5371 // above to disturb set0)
5372 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5373 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5374 2, &descriptorSet[0], 0, NULL);
5375 vkCmdBindDescriptorSets(
5376 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5377 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
5378 m_errorMonitor->SetDesiredFailureMsg(
5379 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5380 " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07005381 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005382 m_errorMonitor->VerifyFound();
5383
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005384 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005385 // 2. Error due to bound set not being compatible with PSO's
5386 // VkPipelineLayout (diff stageFlags in this case)
5387 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5388 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5389 2, &descriptorSet[0], 0, NULL);
5390 m_errorMonitor->SetDesiredFailureMsg(
5391 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5392 " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07005393 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005394 m_errorMonitor->VerifyFound();
5395
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005396 // Remaining clean-up
5397 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005398 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005399 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
5400 }
5401 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06005402 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
5403 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005404 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005405 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5406 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5407}
Tobin Ehlis559c6382015-11-05 09:52:49 -07005408
Karl Schultz6addd812016-02-02 17:17:23 -07005409TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005410
Karl Schultz6addd812016-02-02 17:17:23 -07005411 m_errorMonitor->SetDesiredFailureMsg(
5412 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005413 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005414
5415 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005416 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005417 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005418 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005419
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005420 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005421}
5422
Karl Schultz6addd812016-02-02 17:17:23 -07005423TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
5424 VkResult err;
5425 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005426
Karl Schultz6addd812016-02-02 17:17:23 -07005427 m_errorMonitor->SetDesiredFailureMsg(
5428 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005429 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005430
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005431 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005432
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005433 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005434 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06005435 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005436 cmd.commandPool = m_commandPool;
5437 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005438 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06005439
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005440 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06005441 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005442
5443 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005444 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005445 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005446 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06005447 cmd_buf_info.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07005448 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
5449 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005450 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005451
5452 // The error should be caught by validation of the BeginCommandBuffer call
5453 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
5454
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005455 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005456 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005457}
5458
Karl Schultz6addd812016-02-02 17:17:23 -07005459TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005460 // Cause error due to Begin while recording CB
5461 // Then cause 2 errors for attempting to reset CB w/o having
5462 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
5463 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005465 "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005466
5467 ASSERT_NO_FATAL_FAILURE(InitState());
5468
5469 // Calls AllocateCommandBuffers
5470 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
5471
Karl Schultz6addd812016-02-02 17:17:23 -07005472 // Force the failure by setting the Renderpass and Framebuffer fields with
5473 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005474 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005475 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005476 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5477 cmd_buf_info.pNext = NULL;
5478 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005479 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005480
5481 // Begin CB to transition to recording state
5482 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
5483 // Can't re-begin. This should trigger error
5484 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005485 m_errorMonitor->VerifyFound();
5486
Karl Schultz6addd812016-02-02 17:17:23 -07005487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5488 "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005489 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
5490 // Reset attempt will trigger error due to incorrect CommandPool state
5491 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005492 m_errorMonitor->VerifyFound();
5493
Karl Schultz6addd812016-02-02 17:17:23 -07005494 m_errorMonitor->SetDesiredFailureMsg(
5495 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5496 " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005497 // Transition CB to RECORDED state
5498 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
5499 // Now attempting to Begin will implicitly reset, which triggers error
5500 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005501 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005502}
5503
Karl Schultz6addd812016-02-02 17:17:23 -07005504TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005505 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07005506 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005507
Karl Schultz6addd812016-02-02 17:17:23 -07005508 m_errorMonitor->SetDesiredFailureMsg(
5509 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005510 "Invalid Pipeline CreateInfo State: Vtx Shader required");
5511
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005512 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06005513 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005514
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005515 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005516 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5517 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005518
5519 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005520 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5521 ds_pool_ci.pNext = NULL;
5522 ds_pool_ci.maxSets = 1;
5523 ds_pool_ci.poolSizeCount = 1;
5524 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005525
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005526 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005527 err =
5528 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005529 ASSERT_VK_SUCCESS(err);
5530
Tony Barboureb254902015-07-15 12:50:33 -06005531 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005532 dsl_binding.binding = 0;
5533 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5534 dsl_binding.descriptorCount = 1;
5535 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5536 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005537
Tony Barboureb254902015-07-15 12:50:33 -06005538 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005539 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5540 ds_layout_ci.pNext = NULL;
5541 ds_layout_ci.bindingCount = 1;
5542 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06005543
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005544 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005545 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5546 &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005547 ASSERT_VK_SUCCESS(err);
5548
5549 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005550 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005551 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005552 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005553 alloc_info.descriptorPool = ds_pool;
5554 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005555 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5556 &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005557 ASSERT_VK_SUCCESS(err);
5558
Tony Barboureb254902015-07-15 12:50:33 -06005559 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005560 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5561 pipeline_layout_ci.setLayoutCount = 1;
5562 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005563
5564 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005565 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5566 &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005567 ASSERT_VK_SUCCESS(err);
5568
Tobin Ehlise68360f2015-10-01 11:15:13 -06005569 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07005570 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06005571
5572 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005573 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5574 vp_state_ci.scissorCount = 1;
5575 vp_state_ci.pScissors = &sc;
5576 vp_state_ci.viewportCount = 1;
5577 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005578
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005579 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
5580 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5581 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
5582 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
5583 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
5584 rs_state_ci.depthClampEnable = VK_FALSE;
5585 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
5586 rs_state_ci.depthBiasEnable = VK_FALSE;
5587
Tony Barboureb254902015-07-15 12:50:33 -06005588 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005589 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5590 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005591 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07005592 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5593 gp_ci.layout = pipeline_layout;
5594 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06005595
5596 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005597 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5598 pc_ci.initialDataSize = 0;
5599 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005600
5601 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06005602 VkPipelineCache pipelineCache;
5603
Karl Schultz6addd812016-02-02 17:17:23 -07005604 err =
5605 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06005606 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005607 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5608 &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005609
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005610 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005611
Chia-I Wuf7458c52015-10-26 21:10:41 +08005612 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5613 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5614 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5615 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005616}
Tobin Ehlis912df022015-09-17 08:46:18 -06005617/*// TODO : This test should be good, but needs Tess support in compiler to run
5618TEST_F(VkLayerTest, InvalidPatchControlPoints)
5619{
5620 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06005621 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005622
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005624 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
5625primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005626
Tobin Ehlis912df022015-09-17 08:46:18 -06005627 ASSERT_NO_FATAL_FAILURE(InitState());
5628 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06005629
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005630 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06005631 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005632 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06005633
5634 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5635 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5636 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005637 ds_pool_ci.poolSizeCount = 1;
5638 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06005639
5640 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005641 err = vkCreateDescriptorPool(m_device->device(),
5642VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06005643 ASSERT_VK_SUCCESS(err);
5644
5645 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08005646 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06005647 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08005648 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06005649 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5650 dsl_binding.pImmutableSamplers = NULL;
5651
5652 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005653 ds_layout_ci.sType =
5654VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06005655 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005656 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005657 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06005658
5659 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005660 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5661&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06005662 ASSERT_VK_SUCCESS(err);
5663
5664 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07005665 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
5666VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06005667 ASSERT_VK_SUCCESS(err);
5668
5669 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005670 pipeline_layout_ci.sType =
5671VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06005672 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005673 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06005674 pipeline_layout_ci.pSetLayouts = &ds_layout;
5675
5676 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005677 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5678&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06005679 ASSERT_VK_SUCCESS(err);
5680
5681 VkPipelineShaderStageCreateInfo shaderStages[3];
5682 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
5683
Karl Schultz6addd812016-02-02 17:17:23 -07005684 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
5685this);
Tobin Ehlis912df022015-09-17 08:46:18 -06005686 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07005687 VkShaderObj
5688tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
5689this);
5690 VkShaderObj
5691te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
5692this);
Tobin Ehlis912df022015-09-17 08:46:18 -06005693
Karl Schultz6addd812016-02-02 17:17:23 -07005694 shaderStages[0].sType =
5695VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005696 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06005697 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07005698 shaderStages[1].sType =
5699VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005700 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06005701 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07005702 shaderStages[2].sType =
5703VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005704 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06005705 shaderStages[2].shader = te.handle();
5706
5707 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005708 iaCI.sType =
5709VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08005710 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06005711
5712 VkPipelineTessellationStateCreateInfo tsCI = {};
5713 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
5714 tsCI.patchControlPoints = 0; // This will cause an error
5715
5716 VkGraphicsPipelineCreateInfo gp_ci = {};
5717 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5718 gp_ci.pNext = NULL;
5719 gp_ci.stageCount = 3;
5720 gp_ci.pStages = shaderStages;
5721 gp_ci.pVertexInputState = NULL;
5722 gp_ci.pInputAssemblyState = &iaCI;
5723 gp_ci.pTessellationState = &tsCI;
5724 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005725 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06005726 gp_ci.pMultisampleState = NULL;
5727 gp_ci.pDepthStencilState = NULL;
5728 gp_ci.pColorBlendState = NULL;
5729 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5730 gp_ci.layout = pipeline_layout;
5731 gp_ci.renderPass = renderPass();
5732
5733 VkPipelineCacheCreateInfo pc_ci = {};
5734 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5735 pc_ci.pNext = NULL;
5736 pc_ci.initialSize = 0;
5737 pc_ci.initialData = 0;
5738 pc_ci.maxSize = 0;
5739
5740 VkPipeline pipeline;
5741 VkPipelineCache pipelineCache;
5742
Karl Schultz6addd812016-02-02 17:17:23 -07005743 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
5744&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06005745 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005746 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5747&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06005748
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005749 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005750
Chia-I Wuf7458c52015-10-26 21:10:41 +08005751 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5752 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5753 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5754 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06005755}
5756*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06005757// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07005758TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07005759 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005760
Karl Schultz6addd812016-02-02 17:17:23 -07005761 m_errorMonitor->SetDesiredFailureMsg(
5762 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005763 "Gfx Pipeline viewport count (1) must match scissor count (0).");
5764
Tobin Ehlise68360f2015-10-01 11:15:13 -06005765 ASSERT_NO_FATAL_FAILURE(InitState());
5766 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06005767
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005768 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005769 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5770 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005771
5772 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005773 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5774 ds_pool_ci.maxSets = 1;
5775 ds_pool_ci.poolSizeCount = 1;
5776 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005777
5778 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005779 err =
5780 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005781 ASSERT_VK_SUCCESS(err);
5782
5783 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005784 dsl_binding.binding = 0;
5785 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5786 dsl_binding.descriptorCount = 1;
5787 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005788
5789 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005790 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5791 ds_layout_ci.bindingCount = 1;
5792 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005793
5794 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005795 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5796 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005797 ASSERT_VK_SUCCESS(err);
5798
5799 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005800 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005801 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005802 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005803 alloc_info.descriptorPool = ds_pool;
5804 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005805 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5806 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005807 ASSERT_VK_SUCCESS(err);
5808
5809 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005810 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5811 pipeline_layout_ci.setLayoutCount = 1;
5812 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005813
5814 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005815 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5816 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005817 ASSERT_VK_SUCCESS(err);
5818
5819 VkViewport vp = {}; // Just need dummy vp to point to
5820
5821 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005822 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5823 vp_state_ci.scissorCount = 0;
5824 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
5825 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005826
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005827 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
5828 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5829 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
5830 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
5831 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
5832 rs_state_ci.depthClampEnable = VK_FALSE;
5833 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
5834 rs_state_ci.depthBiasEnable = VK_FALSE;
5835
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
5848 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005849 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5850 gp_ci.stageCount = 2;
5851 gp_ci.pStages = shaderStages;
5852 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005853 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07005854 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5855 gp_ci.layout = pipeline_layout;
5856 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005857
5858 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005859 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005860
5861 VkPipeline pipeline;
5862 VkPipelineCache pipelineCache;
5863
Karl Schultz6addd812016-02-02 17:17:23 -07005864 err =
5865 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005866 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005867 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5868 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005869
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005870 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005871
Chia-I Wuf7458c52015-10-26 21:10:41 +08005872 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5873 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5874 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5875 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005876}
Karl Schultz6addd812016-02-02 17:17:23 -07005877// Don't set viewport state in PSO. This is an error b/c we always need this
5878// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06005879// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07005880TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06005881 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07005882 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005883
Karl Schultz6addd812016-02-02 17:17:23 -07005884 m_errorMonitor->SetDesiredFailureMsg(
5885 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005886 "Gfx Pipeline pViewportState is null. Even if ");
5887
Tobin Ehlise68360f2015-10-01 11:15:13 -06005888 ASSERT_NO_FATAL_FAILURE(InitState());
5889 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06005890
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005891 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005892 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5893 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005894
5895 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005896 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5897 ds_pool_ci.maxSets = 1;
5898 ds_pool_ci.poolSizeCount = 1;
5899 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005900
5901 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005902 err =
5903 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005904 ASSERT_VK_SUCCESS(err);
5905
5906 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005907 dsl_binding.binding = 0;
5908 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5909 dsl_binding.descriptorCount = 1;
5910 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005911
5912 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005913 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5914 ds_layout_ci.bindingCount = 1;
5915 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005916
5917 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005918 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5919 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005920 ASSERT_VK_SUCCESS(err);
5921
5922 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005923 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005924 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005925 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005926 alloc_info.descriptorPool = ds_pool;
5927 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005928 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5929 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005930 ASSERT_VK_SUCCESS(err);
5931
5932 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005933 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5934 pipeline_layout_ci.setLayoutCount = 1;
5935 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005936
5937 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005938 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5939 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005940 ASSERT_VK_SUCCESS(err);
5941
5942 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
5943 // Set scissor as dynamic to avoid second error
5944 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005945 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
5946 dyn_state_ci.dynamicStateCount = 1;
5947 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005948
Cody Northropeb3a6c12015-10-05 14:44:45 -06005949 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07005950 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06005951
Karl Schultz6addd812016-02-02 17:17:23 -07005952 VkShaderObj vs(m_device, bindStateVertShaderText,
5953 VK_SHADER_STAGE_VERTEX_BIT, this);
5954 VkShaderObj fs(m_device, bindStateFragShaderText,
5955 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06005956 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07005957 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08005958 shaderStages[0] = vs.GetStageCreateInfo();
5959 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005960
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005961
5962 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
5963 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5964 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
5965 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
5966 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
5967 rs_state_ci.depthClampEnable = VK_FALSE;
5968 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
5969 rs_state_ci.depthBiasEnable = VK_FALSE;
5970
Tobin Ehlise68360f2015-10-01 11:15:13 -06005971 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005972 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5973 gp_ci.stageCount = 2;
5974 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005975 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07005976 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
5977 // should cause validation error
5978 gp_ci.pDynamicState = &dyn_state_ci;
5979 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5980 gp_ci.layout = pipeline_layout;
5981 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005982
5983 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005984 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005985
5986 VkPipeline pipeline;
5987 VkPipelineCache pipelineCache;
5988
Karl Schultz6addd812016-02-02 17:17:23 -07005989 err =
5990 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005991 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005992 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5993 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005994
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005995 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005996
Chia-I Wuf7458c52015-10-26 21:10:41 +08005997 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5998 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5999 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6000 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006001}
6002// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07006003// Then run second test where dynamic scissor count doesn't match PSO scissor
6004// count
6005TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
6006 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006007
Karl Schultz6addd812016-02-02 17:17:23 -07006008 m_errorMonitor->SetDesiredFailureMsg(
6009 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006010 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
6011
Tobin Ehlise68360f2015-10-01 11:15:13 -06006012 ASSERT_NO_FATAL_FAILURE(InitState());
6013 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006014
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006015 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006016 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6017 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006018
6019 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006020 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6021 ds_pool_ci.maxSets = 1;
6022 ds_pool_ci.poolSizeCount = 1;
6023 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006024
6025 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006026 err =
6027 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006028 ASSERT_VK_SUCCESS(err);
6029
6030 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006031 dsl_binding.binding = 0;
6032 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6033 dsl_binding.descriptorCount = 1;
6034 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006035
6036 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006037 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6038 ds_layout_ci.bindingCount = 1;
6039 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006040
6041 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006042 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6043 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006044 ASSERT_VK_SUCCESS(err);
6045
6046 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006047 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006048 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006049 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006050 alloc_info.descriptorPool = ds_pool;
6051 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006052 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6053 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006054 ASSERT_VK_SUCCESS(err);
6055
6056 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006057 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6058 pipeline_layout_ci.setLayoutCount = 1;
6059 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006060
6061 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006062 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6063 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006064 ASSERT_VK_SUCCESS(err);
6065
6066 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006067 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6068 vp_state_ci.viewportCount = 1;
6069 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
6070 vp_state_ci.scissorCount = 1;
6071 vp_state_ci.pScissors =
6072 NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06006073
6074 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6075 // Set scissor as dynamic to avoid that error
6076 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006077 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6078 dyn_state_ci.dynamicStateCount = 1;
6079 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006080
Cody Northropeb3a6c12015-10-05 14:44:45 -06006081 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006082 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006083
Karl Schultz6addd812016-02-02 17:17:23 -07006084 VkShaderObj vs(m_device, bindStateVertShaderText,
6085 VK_SHADER_STAGE_VERTEX_BIT, this);
6086 VkShaderObj fs(m_device, bindStateFragShaderText,
6087 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006088 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006089 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006090 shaderStages[0] = vs.GetStageCreateInfo();
6091 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006092
Cody Northropf6622dc2015-10-06 10:33:21 -06006093 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6094 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6095 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006096 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006097 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006098 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006099 vi_ci.pVertexAttributeDescriptions = nullptr;
6100
6101 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6102 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6103 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6104
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006105 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006106 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06006107 rs_ci.pNext = nullptr;
6108
Mark Youngc89c6312016-03-31 16:03:20 -06006109 VkPipelineColorBlendAttachmentState att = {};
6110 att.blendEnable = VK_FALSE;
6111 att.colorWriteMask = 0xf;
6112
Cody Northropf6622dc2015-10-06 10:33:21 -06006113 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6114 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6115 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006116 cb_ci.attachmentCount = 1;
6117 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06006118
Tobin Ehlise68360f2015-10-01 11:15:13 -06006119 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006120 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6121 gp_ci.stageCount = 2;
6122 gp_ci.pStages = shaderStages;
6123 gp_ci.pVertexInputState = &vi_ci;
6124 gp_ci.pInputAssemblyState = &ia_ci;
6125 gp_ci.pViewportState = &vp_state_ci;
6126 gp_ci.pRasterizationState = &rs_ci;
6127 gp_ci.pColorBlendState = &cb_ci;
6128 gp_ci.pDynamicState = &dyn_state_ci;
6129 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6130 gp_ci.layout = pipeline_layout;
6131 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006132
6133 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006134 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006135
6136 VkPipeline pipeline;
6137 VkPipelineCache pipelineCache;
6138
Karl Schultz6addd812016-02-02 17:17:23 -07006139 err =
6140 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006141 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006142 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6143 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006144
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006145 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006146
Tobin Ehlisd332f282015-10-02 11:00:56 -06006147 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07006148 // First need to successfully create the PSO from above by setting
6149 // pViewports
6150 m_errorMonitor->SetDesiredFailureMsg(
6151 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6152 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO "
6153 "scissorCount is 1. These counts must match.");
6154
6155 VkViewport vp = {}; // Just need dummy vp to point to
6156 vp_state_ci.pViewports = &vp;
6157 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6158 &gp_ci, NULL, &pipeline);
6159 ASSERT_VK_SUCCESS(err);
6160 BeginCommandBuffer();
6161 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6162 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
6163 VkRect2D scissors[2] = {}; // don't care about data
6164 // Count of 2 doesn't match PSO count of 1
6165 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
6166 Draw(1, 0, 0, 0);
6167
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006168 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006169
6170 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6171 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6172 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6173 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6174}
6175// Create PSO w/o non-zero scissorCount but no scissor data
6176// Then run second test where dynamic viewportCount doesn't match PSO
6177// viewportCount
6178TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
6179 VkResult err;
6180
6181 m_errorMonitor->SetDesiredFailureMsg(
6182 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6183 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
6184
6185 ASSERT_NO_FATAL_FAILURE(InitState());
6186 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6187
6188 VkDescriptorPoolSize ds_type_count = {};
6189 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6190 ds_type_count.descriptorCount = 1;
6191
6192 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6193 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6194 ds_pool_ci.maxSets = 1;
6195 ds_pool_ci.poolSizeCount = 1;
6196 ds_pool_ci.pPoolSizes = &ds_type_count;
6197
6198 VkDescriptorPool ds_pool;
6199 err =
6200 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6201 ASSERT_VK_SUCCESS(err);
6202
6203 VkDescriptorSetLayoutBinding dsl_binding = {};
6204 dsl_binding.binding = 0;
6205 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6206 dsl_binding.descriptorCount = 1;
6207 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6208
6209 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6210 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6211 ds_layout_ci.bindingCount = 1;
6212 ds_layout_ci.pBindings = &dsl_binding;
6213
6214 VkDescriptorSetLayout ds_layout;
6215 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6216 &ds_layout);
6217 ASSERT_VK_SUCCESS(err);
6218
6219 VkDescriptorSet descriptorSet;
6220 VkDescriptorSetAllocateInfo alloc_info = {};
6221 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6222 alloc_info.descriptorSetCount = 1;
6223 alloc_info.descriptorPool = ds_pool;
6224 alloc_info.pSetLayouts = &ds_layout;
6225 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6226 &descriptorSet);
6227 ASSERT_VK_SUCCESS(err);
6228
6229 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6230 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6231 pipeline_layout_ci.setLayoutCount = 1;
6232 pipeline_layout_ci.pSetLayouts = &ds_layout;
6233
6234 VkPipelineLayout pipeline_layout;
6235 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6236 &pipeline_layout);
6237 ASSERT_VK_SUCCESS(err);
6238
6239 VkPipelineViewportStateCreateInfo vp_state_ci = {};
6240 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6241 vp_state_ci.scissorCount = 1;
6242 vp_state_ci.pScissors =
6243 NULL; // Null scissor w/ count of 1 should cause error
6244 vp_state_ci.viewportCount = 1;
6245 vp_state_ci.pViewports =
6246 NULL; // vp is dynamic (below) so this won't cause error
6247
6248 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
6249 // Set scissor as dynamic to avoid that error
6250 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
6251 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6252 dyn_state_ci.dynamicStateCount = 1;
6253 dyn_state_ci.pDynamicStates = &vp_state;
6254
6255 VkPipelineShaderStageCreateInfo shaderStages[2];
6256 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6257
6258 VkShaderObj vs(m_device, bindStateVertShaderText,
6259 VK_SHADER_STAGE_VERTEX_BIT, this);
6260 VkShaderObj fs(m_device, bindStateFragShaderText,
6261 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006262 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006263 // but add it to be able to run on more devices
6264 shaderStages[0] = vs.GetStageCreateInfo();
6265 shaderStages[1] = fs.GetStageCreateInfo();
6266
6267 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6268 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6269 vi_ci.pNext = nullptr;
6270 vi_ci.vertexBindingDescriptionCount = 0;
6271 vi_ci.pVertexBindingDescriptions = nullptr;
6272 vi_ci.vertexAttributeDescriptionCount = 0;
6273 vi_ci.pVertexAttributeDescriptions = nullptr;
6274
6275 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6276 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6277 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6278
6279 VkPipelineRasterizationStateCreateInfo rs_ci = {};
6280 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6281 rs_ci.pNext = nullptr;
6282
Mark Youngc89c6312016-03-31 16:03:20 -06006283 VkPipelineColorBlendAttachmentState att = {};
6284 att.blendEnable = VK_FALSE;
6285 att.colorWriteMask = 0xf;
6286
Karl Schultz6addd812016-02-02 17:17:23 -07006287 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6288 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6289 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006290 cb_ci.attachmentCount = 1;
6291 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07006292
6293 VkGraphicsPipelineCreateInfo gp_ci = {};
6294 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6295 gp_ci.stageCount = 2;
6296 gp_ci.pStages = shaderStages;
6297 gp_ci.pVertexInputState = &vi_ci;
6298 gp_ci.pInputAssemblyState = &ia_ci;
6299 gp_ci.pViewportState = &vp_state_ci;
6300 gp_ci.pRasterizationState = &rs_ci;
6301 gp_ci.pColorBlendState = &cb_ci;
6302 gp_ci.pDynamicState = &dyn_state_ci;
6303 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6304 gp_ci.layout = pipeline_layout;
6305 gp_ci.renderPass = renderPass();
6306
6307 VkPipelineCacheCreateInfo pc_ci = {};
6308 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6309
6310 VkPipeline pipeline;
6311 VkPipelineCache pipelineCache;
6312
6313 err =
6314 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6315 ASSERT_VK_SUCCESS(err);
6316 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6317 &gp_ci, NULL, &pipeline);
6318
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006319 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006320
6321 // Now hit second fail case where we set scissor w/ different count than PSO
6322 // First need to successfully create the PSO from above by setting
6323 // pViewports
6324 m_errorMonitor->SetDesiredFailureMsg(
6325 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6326 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO "
6327 "viewportCount is 1. These counts must match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006328
Tobin Ehlisd332f282015-10-02 11:00:56 -06006329 VkRect2D sc = {}; // Just need dummy vp to point to
6330 vp_state_ci.pScissors = &sc;
Karl Schultz6addd812016-02-02 17:17:23 -07006331 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6332 &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006333 ASSERT_VK_SUCCESS(err);
6334 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006335 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6336 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006337 VkViewport viewports[2] = {}; // don't care about data
6338 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07006339 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006340 Draw(1, 0, 0, 0);
6341
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006342 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006343
Chia-I Wuf7458c52015-10-26 21:10:41 +08006344 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6345 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6346 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6347 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006348}
6349
Mark Young7394fdd2016-03-31 14:56:43 -06006350TEST_F(VkLayerTest, PSOLineWidthInvalid) {
6351 VkResult err;
6352
6353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06006354 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06006355
6356 ASSERT_NO_FATAL_FAILURE(InitState());
6357 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6358
6359 VkDescriptorPoolSize ds_type_count = {};
6360 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6361 ds_type_count.descriptorCount = 1;
6362
6363 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6364 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6365 ds_pool_ci.maxSets = 1;
6366 ds_pool_ci.poolSizeCount = 1;
6367 ds_pool_ci.pPoolSizes = &ds_type_count;
6368
6369 VkDescriptorPool ds_pool;
6370 err =
6371 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6372 ASSERT_VK_SUCCESS(err);
6373
6374 VkDescriptorSetLayoutBinding dsl_binding = {};
6375 dsl_binding.binding = 0;
6376 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6377 dsl_binding.descriptorCount = 1;
6378 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6379
6380 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6381 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6382 ds_layout_ci.bindingCount = 1;
6383 ds_layout_ci.pBindings = &dsl_binding;
6384
6385 VkDescriptorSetLayout ds_layout;
6386 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6387 &ds_layout);
6388 ASSERT_VK_SUCCESS(err);
6389
6390 VkDescriptorSet descriptorSet;
6391 VkDescriptorSetAllocateInfo alloc_info = {};
6392 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6393 alloc_info.descriptorSetCount = 1;
6394 alloc_info.descriptorPool = ds_pool;
6395 alloc_info.pSetLayouts = &ds_layout;
6396 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6397 &descriptorSet);
6398 ASSERT_VK_SUCCESS(err);
6399
6400 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6401 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6402 pipeline_layout_ci.setLayoutCount = 1;
6403 pipeline_layout_ci.pSetLayouts = &ds_layout;
6404
6405 VkPipelineLayout pipeline_layout;
6406 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6407 &pipeline_layout);
6408 ASSERT_VK_SUCCESS(err);
6409
6410 VkPipelineViewportStateCreateInfo vp_state_ci = {};
6411 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6412 vp_state_ci.scissorCount = 1;
6413 vp_state_ci.pScissors = NULL;
6414 vp_state_ci.viewportCount = 1;
6415 vp_state_ci.pViewports = NULL;
6416
6417 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT,
6418 VK_DYNAMIC_STATE_SCISSOR,
6419 VK_DYNAMIC_STATE_LINE_WIDTH};
6420 // Set scissor as dynamic to avoid that error
6421 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
6422 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6423 dyn_state_ci.dynamicStateCount = 2;
6424 dyn_state_ci.pDynamicStates = dynamic_states;
6425
6426 VkPipelineShaderStageCreateInfo shaderStages[2];
6427 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6428
6429 VkShaderObj vs(m_device, bindStateVertShaderText,
6430 VK_SHADER_STAGE_VERTEX_BIT, this);
6431 VkShaderObj fs(m_device, bindStateFragShaderText,
6432 VK_SHADER_STAGE_FRAGMENT_BIT,
6433 this); // TODO - We shouldn't need a fragment shader
6434 // but add it to be able to run on more devices
6435 shaderStages[0] = vs.GetStageCreateInfo();
6436 shaderStages[1] = fs.GetStageCreateInfo();
6437
6438 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6439 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6440 vi_ci.pNext = nullptr;
6441 vi_ci.vertexBindingDescriptionCount = 0;
6442 vi_ci.pVertexBindingDescriptions = nullptr;
6443 vi_ci.vertexAttributeDescriptionCount = 0;
6444 vi_ci.pVertexAttributeDescriptions = nullptr;
6445
6446 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6447 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6448 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6449
6450 VkPipelineRasterizationStateCreateInfo rs_ci = {};
6451 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6452 rs_ci.pNext = nullptr;
6453
Mark Young47107952016-05-02 15:59:55 -06006454 // Check too low (line width of -1.0f).
6455 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06006456
6457 VkPipelineColorBlendAttachmentState att = {};
6458 att.blendEnable = VK_FALSE;
6459 att.colorWriteMask = 0xf;
6460
6461 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6462 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6463 cb_ci.pNext = nullptr;
6464 cb_ci.attachmentCount = 1;
6465 cb_ci.pAttachments = &att;
6466
6467 VkGraphicsPipelineCreateInfo gp_ci = {};
6468 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6469 gp_ci.stageCount = 2;
6470 gp_ci.pStages = shaderStages;
6471 gp_ci.pVertexInputState = &vi_ci;
6472 gp_ci.pInputAssemblyState = &ia_ci;
6473 gp_ci.pViewportState = &vp_state_ci;
6474 gp_ci.pRasterizationState = &rs_ci;
6475 gp_ci.pColorBlendState = &cb_ci;
6476 gp_ci.pDynamicState = &dyn_state_ci;
6477 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6478 gp_ci.layout = pipeline_layout;
6479 gp_ci.renderPass = renderPass();
6480
6481 VkPipelineCacheCreateInfo pc_ci = {};
6482 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6483
6484 VkPipeline pipeline;
6485 VkPipelineCache pipelineCache;
6486
6487 err =
6488 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6489 ASSERT_VK_SUCCESS(err);
6490 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6491 &gp_ci, NULL, &pipeline);
6492
6493 m_errorMonitor->VerifyFound();
6494
6495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6496 "Attempt to set lineWidth to 65536");
6497
6498 // Check too high (line width of 65536.0f).
6499 rs_ci.lineWidth = 65536.0f;
6500
6501 err =
6502 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6503 ASSERT_VK_SUCCESS(err);
6504 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6505 &gp_ci, NULL, &pipeline);
6506
6507 m_errorMonitor->VerifyFound();
6508
6509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06006510 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06006511
6512 dyn_state_ci.dynamicStateCount = 3;
6513
6514 rs_ci.lineWidth = 1.0f;
6515
6516 err =
6517 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6518 ASSERT_VK_SUCCESS(err);
6519 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6520 &gp_ci, NULL, &pipeline);
6521 BeginCommandBuffer();
6522 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6523 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
6524
6525 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06006526 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06006527 m_errorMonitor->VerifyFound();
6528
6529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6530 "Attempt to set lineWidth to 65536");
6531
6532 // Check too high with dynamic setting.
6533 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
6534 m_errorMonitor->VerifyFound();
6535 EndCommandBuffer();
6536
6537 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6538 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6539 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6540 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6541}
6542
Karl Schultz6addd812016-02-02 17:17:23 -07006543TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006544 // Bind a NULL RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006545 m_errorMonitor->SetDesiredFailureMsg(
6546 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006547 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006548
6549 ASSERT_NO_FATAL_FAILURE(InitState());
6550 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006551
Tony Barbourfe3351b2015-07-28 10:17:20 -06006552 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006553 // Don't care about RenderPass handle b/c error should be flagged before
6554 // that
6555 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL,
6556 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006557
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006558 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006559}
6560
Karl Schultz6addd812016-02-02 17:17:23 -07006561TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006562 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006563 m_errorMonitor->SetDesiredFailureMsg(
6564 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006565 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006566
6567 ASSERT_NO_FATAL_FAILURE(InitState());
6568 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006569
Tony Barbourfe3351b2015-07-28 10:17:20 -06006570 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006571 // Just create a dummy Renderpass that's non-NULL so we can get to the
6572 // proper error
Tony Barboureb254902015-07-15 12:50:33 -06006573 VkRenderPassBeginInfo rp_begin = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006574 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
6575 rp_begin.pNext = NULL;
6576 rp_begin.renderPass = renderPass();
6577 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006578
Karl Schultz6addd812016-02-02 17:17:23 -07006579 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
6580 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006581
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006582 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006583}
6584
Cody Northrop3bb4d962016-05-09 16:15:57 -06006585TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
6586
6587 TEST_DESCRIPTION("End a command buffer with an active render pass");
6588
6589 m_errorMonitor->SetDesiredFailureMsg(
6590 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6591 "It is invalid to issue this call inside an active render pass");
6592
6593 ASSERT_NO_FATAL_FAILURE(InitState());
6594 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6595
6596 // The framework's BeginCommandBuffer calls CreateRenderPass
6597 BeginCommandBuffer();
6598
6599 // Call directly into vkEndCommandBuffer instead of the
6600 // the framework's EndCommandBuffer, which inserts a
6601 // vkEndRenderPass
6602 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
6603
6604 m_errorMonitor->VerifyFound();
6605
6606 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
6607 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
6608}
6609
Karl Schultz6addd812016-02-02 17:17:23 -07006610TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006611 // Call CmdFillBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07006612 m_errorMonitor->SetDesiredFailureMsg(
6613 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006614 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006615
6616 ASSERT_NO_FATAL_FAILURE(InitState());
6617 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006618
6619 // Renderpass is started here
6620 BeginCommandBuffer();
6621
6622 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006623 vk_testing::Buffer dstBuffer;
6624 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006625
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006626 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006627
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006628 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006629}
6630
Karl Schultz6addd812016-02-02 17:17:23 -07006631TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006632 // Call CmdUpdateBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07006633 m_errorMonitor->SetDesiredFailureMsg(
6634 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006635 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006636
6637 ASSERT_NO_FATAL_FAILURE(InitState());
6638 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006639
6640 // Renderpass is started here
6641 BeginCommandBuffer();
6642
6643 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006644 vk_testing::Buffer dstBuffer;
6645 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006646
Karl Schultz6addd812016-02-02 17:17:23 -07006647 VkDeviceSize dstOffset = 0;
6648 VkDeviceSize dataSize = 1024;
6649 const uint32_t *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006650
Karl Schultz6addd812016-02-02 17:17:23 -07006651 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
6652 dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006653
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006654 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006655}
6656
Karl Schultz6addd812016-02-02 17:17:23 -07006657TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006658 // Call CmdClearColorImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006659 m_errorMonitor->SetDesiredFailureMsg(
6660 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006661 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006662
6663 ASSERT_NO_FATAL_FAILURE(InitState());
6664 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006665
6666 // Renderpass is started here
6667 BeginCommandBuffer();
6668
Michael Lentine0a369f62016-02-03 16:51:46 -06006669 VkClearColorValue clear_color;
6670 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07006671 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
6672 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6673 const int32_t tex_width = 32;
6674 const int32_t tex_height = 32;
6675 VkImageCreateInfo image_create_info = {};
6676 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6677 image_create_info.pNext = NULL;
6678 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6679 image_create_info.format = tex_format;
6680 image_create_info.extent.width = tex_width;
6681 image_create_info.extent.height = tex_height;
6682 image_create_info.extent.depth = 1;
6683 image_create_info.mipLevels = 1;
6684 image_create_info.arrayLayers = 1;
6685 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6686 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
6687 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006688
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006689 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07006690 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
6691 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006692
Karl Schultz6addd812016-02-02 17:17:23 -07006693 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
6694 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006695
Karl Schultz6addd812016-02-02 17:17:23 -07006696 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
6697 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006698
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006699 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006700}
6701
Karl Schultz6addd812016-02-02 17:17:23 -07006702TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006703 // Call CmdClearDepthStencilImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006704 m_errorMonitor->SetDesiredFailureMsg(
6705 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006706 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006707
6708 ASSERT_NO_FATAL_FAILURE(InitState());
6709 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006710
6711 // Renderpass is started here
6712 BeginCommandBuffer();
6713
6714 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07006715 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07006716 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
6717 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6718 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
6719 image_create_info.extent.width = 64;
6720 image_create_info.extent.height = 64;
6721 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6722 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006723
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006724 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07006725 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
6726 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006727
Karl Schultz6addd812016-02-02 17:17:23 -07006728 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
6729 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006730
Karl Schultz6addd812016-02-02 17:17:23 -07006731 vkCmdClearDepthStencilImage(
6732 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
6733 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
6734 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006735
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006736 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006737}
6738
Karl Schultz6addd812016-02-02 17:17:23 -07006739TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006740 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006741 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006742
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006744 "vkCmdClearAttachments: This call "
6745 "must be issued inside an active "
6746 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006747
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006748 ASSERT_NO_FATAL_FAILURE(InitState());
6749 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006750
6751 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006752 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006753 ASSERT_VK_SUCCESS(err);
6754
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006755 VkClearAttachment color_attachment;
6756 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6757 color_attachment.clearValue.color.float32[0] = 0;
6758 color_attachment.clearValue.color.float32[1] = 0;
6759 color_attachment.clearValue.color.float32[2] = 0;
6760 color_attachment.clearValue.color.float32[3] = 0;
6761 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07006762 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
6763 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
6764 &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006765
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006766 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006767}
6768
Karl Schultz9e66a292016-04-21 15:57:51 -06006769TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
6770 // Try to add a buffer memory barrier with no buffer.
6771 m_errorMonitor->SetDesiredFailureMsg(
6772 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6773 "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE");
6774
6775 ASSERT_NO_FATAL_FAILURE(InitState());
6776 BeginCommandBuffer();
6777
6778 VkBufferMemoryBarrier buf_barrier = {};
6779 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
6780 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6781 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6782 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6783 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6784 buf_barrier.buffer = VK_NULL_HANDLE;
6785 buf_barrier.offset = 0;
6786 buf_barrier.size = VK_WHOLE_SIZE;
6787 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6788 VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
6789 0, 0, nullptr, 1, &buf_barrier, 0, nullptr);
6790
6791 m_errorMonitor->VerifyFound();
6792}
6793
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06006794TEST_F(VkLayerTest, InvalidBarriers) {
6795 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
6796
6797 m_errorMonitor->SetDesiredFailureMsg(
6798 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
6799
6800 ASSERT_NO_FATAL_FAILURE(InitState());
6801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6802
6803 VkMemoryBarrier mem_barrier = {};
6804 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
6805 mem_barrier.pNext = NULL;
6806 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6807 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6808 BeginCommandBuffer();
6809 // BeginCommandBuffer() starts a render pass
6810 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6811 VK_PIPELINE_STAGE_HOST_BIT,
6812 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
6813 &mem_barrier, 0, nullptr, 0, nullptr);
6814 m_errorMonitor->VerifyFound();
6815
6816 m_errorMonitor->SetDesiredFailureMsg(
6817 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6818 "Image Layout cannot be transitioned to UNDEFINED");
6819 VkImageObj image(m_device);
6820 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
6821 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6822 ASSERT_TRUE(image.initialized());
6823 VkImageMemoryBarrier img_barrier = {};
6824 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
6825 img_barrier.pNext = NULL;
6826 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6827 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6828 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
6829 // New layout can't be UNDEFINED
6830 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6831 img_barrier.image = image.handle();
6832 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6833 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6834 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6835 img_barrier.subresourceRange.baseArrayLayer = 0;
6836 img_barrier.subresourceRange.baseMipLevel = 0;
6837 img_barrier.subresourceRange.layerCount = 1;
6838 img_barrier.subresourceRange.levelCount = 1;
6839 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6840 VK_PIPELINE_STAGE_HOST_BIT,
6841 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6842 nullptr, 1, &img_barrier);
6843 m_errorMonitor->VerifyFound();
6844 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
6845
6846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6847 "Subresource must have the sum of the "
6848 "baseArrayLayer");
6849 // baseArrayLayer + layerCount must be <= image's arrayLayers
6850 img_barrier.subresourceRange.baseArrayLayer = 1;
6851 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6852 VK_PIPELINE_STAGE_HOST_BIT,
6853 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6854 nullptr, 1, &img_barrier);
6855 m_errorMonitor->VerifyFound();
6856 img_barrier.subresourceRange.baseArrayLayer = 0;
6857
6858 m_errorMonitor->SetDesiredFailureMsg(
6859 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6860 "Subresource must have the sum of the baseMipLevel");
6861 // baseMipLevel + levelCount must be <= image's mipLevels
6862 img_barrier.subresourceRange.baseMipLevel = 1;
6863 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6864 VK_PIPELINE_STAGE_HOST_BIT,
6865 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6866 nullptr, 1, &img_barrier);
6867 m_errorMonitor->VerifyFound();
6868 img_barrier.subresourceRange.baseMipLevel = 0;
6869
6870 m_errorMonitor->SetDesiredFailureMsg(
6871 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6872 "Buffer Barriers cannot be used during a render pass");
6873 vk_testing::Buffer buffer;
6874 buffer.init(*m_device, 256);
6875 VkBufferMemoryBarrier buf_barrier = {};
6876 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
6877 buf_barrier.pNext = NULL;
6878 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6879 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6880 buf_barrier.buffer = buffer.handle();
6881 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6882 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6883 buf_barrier.offset = 0;
6884 buf_barrier.size = VK_WHOLE_SIZE;
6885 // Can't send buffer barrier during a render pass
6886 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6887 VK_PIPELINE_STAGE_HOST_BIT,
6888 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
6889 &buf_barrier, 0, nullptr);
6890 m_errorMonitor->VerifyFound();
6891 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
6892
6893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6894 "which is not less than total size");
6895 buf_barrier.offset = 257;
6896 // Offset greater than total size
6897 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6898 VK_PIPELINE_STAGE_HOST_BIT,
6899 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
6900 &buf_barrier, 0, nullptr);
6901 m_errorMonitor->VerifyFound();
6902 buf_barrier.offset = 0;
6903
6904 m_errorMonitor->SetDesiredFailureMsg(
6905 VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
6906 buf_barrier.size = 257;
6907 // Size greater than total size
6908 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6909 VK_PIPELINE_STAGE_HOST_BIT,
6910 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
6911 &buf_barrier, 0, nullptr);
6912 m_errorMonitor->VerifyFound();
6913 buf_barrier.size = VK_WHOLE_SIZE;
6914
6915 m_errorMonitor->SetDesiredFailureMsg(
6916 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6917 "Image is a depth and stencil format and thus must "
6918 "have both VK_IMAGE_ASPECT_DEPTH_BIT and "
6919 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
6920 VkDepthStencilObj ds_image(m_device);
6921 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
6922 ASSERT_TRUE(ds_image.initialized());
6923 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
6924 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
6925 img_barrier.image = ds_image.handle();
6926 // Leave aspectMask at COLOR on purpose
6927 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6928 VK_PIPELINE_STAGE_HOST_BIT,
6929 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6930 nullptr, 1, &img_barrier);
6931 m_errorMonitor->VerifyFound();
6932}
6933
Karl Schultz6addd812016-02-02 17:17:23 -07006934TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006935 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006936 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006937
Karl Schultz6addd812016-02-02 17:17:23 -07006938 m_errorMonitor->SetDesiredFailureMsg(
6939 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006940 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
6941
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006942 ASSERT_NO_FATAL_FAILURE(InitState());
6943 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006944 uint32_t qfi = 0;
6945 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006946 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6947 buffCI.size = 1024;
6948 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
6949 buffCI.queueFamilyIndexCount = 1;
6950 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006951
6952 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006953 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006954 ASSERT_VK_SUCCESS(err);
6955
6956 BeginCommandBuffer();
6957 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006958 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6959 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006960 // Should error before calling to driver so don't care about actual data
Karl Schultz6addd812016-02-02 17:17:23 -07006961 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
6962 VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006963
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006964 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006965
Chia-I Wuf7458c52015-10-26 21:10:41 +08006966 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006967}
6968
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07006969TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
6970 // Create an out-of-range queueFamilyIndex
6971 m_errorMonitor->SetDesiredFailureMsg(
6972 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesde628532016-04-21 16:30:17 -06006973 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
6974 "of the indices specified when the device was created, via the "
6975 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07006976
6977 ASSERT_NO_FATAL_FAILURE(InitState());
6978 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6979 VkBufferCreateInfo buffCI = {};
6980 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6981 buffCI.size = 1024;
6982 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
6983 buffCI.queueFamilyIndexCount = 1;
6984 // Introduce failure by specifying invalid queue_family_index
6985 uint32_t qfi = 777;
6986 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06006987 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07006988
6989 VkBuffer ib;
6990 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
6991
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006992 m_errorMonitor->VerifyFound();
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07006993}
6994
Karl Schultz6addd812016-02-02 17:17:23 -07006995TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
6996 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
6997 // secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006998
Karl Schultz6addd812016-02-02 17:17:23 -07006999 m_errorMonitor->SetDesiredFailureMsg(
7000 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007001 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007002
7003 ASSERT_NO_FATAL_FAILURE(InitState());
7004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007005
7006 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007007 // ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007008 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
7009 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007010
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007011 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007012}
7013
Karl Schultz6addd812016-02-02 17:17:23 -07007014TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007015 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07007016 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007017
Karl Schultz6addd812016-02-02 17:17:23 -07007018 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007019 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7020 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
7021 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007022
Tobin Ehlis3b780662015-05-28 12:11:26 -06007023 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007024 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007025 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007026 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7027 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007028
7029 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007030 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7031 ds_pool_ci.pNext = NULL;
7032 ds_pool_ci.maxSets = 1;
7033 ds_pool_ci.poolSizeCount = 1;
7034 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06007035
Tobin Ehlis3b780662015-05-28 12:11:26 -06007036 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007037 err =
7038 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007039 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06007040 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007041 dsl_binding.binding = 0;
7042 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7043 dsl_binding.descriptorCount = 1;
7044 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7045 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007046
Tony Barboureb254902015-07-15 12:50:33 -06007047 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007048 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7049 ds_layout_ci.pNext = NULL;
7050 ds_layout_ci.bindingCount = 1;
7051 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007052
Tobin Ehlis3b780662015-05-28 12:11:26 -06007053 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007054 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7055 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007056 ASSERT_VK_SUCCESS(err);
7057
7058 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007059 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007060 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007061 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007062 alloc_info.descriptorPool = ds_pool;
7063 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007064 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7065 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007066 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007067
Tobin Ehlis30db8f82016-05-05 08:19:48 -06007068 VkSamplerCreateInfo sampler_ci = {};
7069 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7070 sampler_ci.pNext = NULL;
7071 sampler_ci.magFilter = VK_FILTER_NEAREST;
7072 sampler_ci.minFilter = VK_FILTER_NEAREST;
7073 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7074 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7075 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7076 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7077 sampler_ci.mipLodBias = 1.0;
7078 sampler_ci.anisotropyEnable = VK_FALSE;
7079 sampler_ci.maxAnisotropy = 1;
7080 sampler_ci.compareEnable = VK_FALSE;
7081 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7082 sampler_ci.minLod = 1.0;
7083 sampler_ci.maxLod = 1.0;
7084 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7085 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7086 VkSampler sampler;
7087 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7088 ASSERT_VK_SUCCESS(err);
7089
7090 VkDescriptorImageInfo info = {};
7091 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007092
7093 VkWriteDescriptorSet descriptor_write;
7094 memset(&descriptor_write, 0, sizeof(descriptor_write));
7095 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007096 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007097 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007098 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007099 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007100 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007101
7102 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7103
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007104 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007105
Chia-I Wuf7458c52015-10-26 21:10:41 +08007106 vkDestroySampler(m_device->device(), sampler, NULL);
7107 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7108 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007109}
7110
Karl Schultz6addd812016-02-02 17:17:23 -07007111TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007112 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07007113 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007114
Karl Schultz6addd812016-02-02 17:17:23 -07007115 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007116 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7117 " binding #0 with 1 total descriptors but update of 1 descriptors "
7118 "starting at binding offset of 0 combined with update array element "
7119 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007120
Tobin Ehlis3b780662015-05-28 12:11:26 -06007121 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007122 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007123 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007124 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7125 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007126
7127 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007128 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7129 ds_pool_ci.pNext = NULL;
7130 ds_pool_ci.maxSets = 1;
7131 ds_pool_ci.poolSizeCount = 1;
7132 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06007133
Tobin Ehlis3b780662015-05-28 12:11:26 -06007134 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007135 err =
7136 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007137 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007138
Tony Barboureb254902015-07-15 12:50:33 -06007139 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007140 dsl_binding.binding = 0;
7141 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7142 dsl_binding.descriptorCount = 1;
7143 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7144 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06007145
7146 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007147 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7148 ds_layout_ci.pNext = NULL;
7149 ds_layout_ci.bindingCount = 1;
7150 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007151
Tobin Ehlis3b780662015-05-28 12:11:26 -06007152 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007153 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7154 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007155 ASSERT_VK_SUCCESS(err);
7156
7157 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007158 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007159 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007160 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007161 alloc_info.descriptorPool = ds_pool;
7162 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007163 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7164 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007165 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007166
Tobin Ehlis30db8f82016-05-05 08:19:48 -06007167 // Correctly update descriptor to avoid "NOT_UPDATED" error
7168 VkDescriptorBufferInfo buff_info = {};
7169 buff_info.buffer =
7170 VkBuffer(0); // Don't care about buffer handle for this test
7171 buff_info.offset = 0;
7172 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007173
7174 VkWriteDescriptorSet descriptor_write;
7175 memset(&descriptor_write, 0, sizeof(descriptor_write));
7176 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007177 descriptor_write.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007178 descriptor_write.dstArrayElement =
7179 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08007180 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007181 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7182 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007183
7184 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7185
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007186 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007187
Chia-I Wuf7458c52015-10-26 21:10:41 +08007188 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7189 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007190}
7191
Karl Schultz6addd812016-02-02 17:17:23 -07007192TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
7193 // Create layout w/ count of 1 and attempt update to that layout w/ binding
7194 // index 2
7195 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007196
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7198 " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007199
Tobin Ehlis3b780662015-05-28 12:11:26 -06007200 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007201 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007202 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007203 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7204 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007205
7206 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007207 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7208 ds_pool_ci.pNext = NULL;
7209 ds_pool_ci.maxSets = 1;
7210 ds_pool_ci.poolSizeCount = 1;
7211 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06007212
Tobin Ehlis3b780662015-05-28 12:11:26 -06007213 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007214 err =
7215 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007216 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007217
Tony Barboureb254902015-07-15 12:50:33 -06007218 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007219 dsl_binding.binding = 0;
7220 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7221 dsl_binding.descriptorCount = 1;
7222 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7223 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06007224
7225 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007226 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7227 ds_layout_ci.pNext = NULL;
7228 ds_layout_ci.bindingCount = 1;
7229 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007230 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007231 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7232 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007233 ASSERT_VK_SUCCESS(err);
7234
7235 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007236 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007237 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007238 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007239 alloc_info.descriptorPool = ds_pool;
7240 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007241 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7242 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007243 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007244
Tony Barboureb254902015-07-15 12:50:33 -06007245 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007246 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7247 sampler_ci.pNext = NULL;
7248 sampler_ci.magFilter = VK_FILTER_NEAREST;
7249 sampler_ci.minFilter = VK_FILTER_NEAREST;
7250 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7251 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7252 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7253 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7254 sampler_ci.mipLodBias = 1.0;
7255 sampler_ci.anisotropyEnable = VK_FALSE;
7256 sampler_ci.maxAnisotropy = 1;
7257 sampler_ci.compareEnable = VK_FALSE;
7258 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7259 sampler_ci.minLod = 1.0;
7260 sampler_ci.maxLod = 1.0;
7261 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7262 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06007263
Tobin Ehlis3b780662015-05-28 12:11:26 -06007264 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007265 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007266 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007267
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007268 VkDescriptorImageInfo info = {};
7269 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007270
7271 VkWriteDescriptorSet descriptor_write;
7272 memset(&descriptor_write, 0, sizeof(descriptor_write));
7273 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007274 descriptor_write.dstSet = descriptorSet;
7275 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007276 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007277 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007278 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007279 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007280
7281 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7282
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007283 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007284
Chia-I Wuf7458c52015-10-26 21:10:41 +08007285 vkDestroySampler(m_device->device(), sampler, NULL);
7286 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7287 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007288}
7289
Karl Schultz6addd812016-02-02 17:17:23 -07007290TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
7291 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
7292 // types
7293 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007294
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis660bcdc2016-05-17 10:39:46 -06007296 ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007297
Tobin Ehlis3b780662015-05-28 12:11:26 -06007298 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007299
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007300 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007301 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7302 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007303
7304 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007305 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7306 ds_pool_ci.pNext = NULL;
7307 ds_pool_ci.maxSets = 1;
7308 ds_pool_ci.poolSizeCount = 1;
7309 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06007310
Tobin Ehlis3b780662015-05-28 12:11:26 -06007311 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007312 err =
7313 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007314 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06007315 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007316 dsl_binding.binding = 0;
7317 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7318 dsl_binding.descriptorCount = 1;
7319 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7320 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007321
Tony Barboureb254902015-07-15 12:50:33 -06007322 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007323 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7324 ds_layout_ci.pNext = NULL;
7325 ds_layout_ci.bindingCount = 1;
7326 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007327
Tobin Ehlis3b780662015-05-28 12:11:26 -06007328 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007329 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7330 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007331 ASSERT_VK_SUCCESS(err);
7332
7333 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007334 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007335 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007336 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007337 alloc_info.descriptorPool = ds_pool;
7338 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007339 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7340 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007341 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007342
Tony Barboureb254902015-07-15 12:50:33 -06007343 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007344 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7345 sampler_ci.pNext = NULL;
7346 sampler_ci.magFilter = VK_FILTER_NEAREST;
7347 sampler_ci.minFilter = VK_FILTER_NEAREST;
7348 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7349 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7350 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7351 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7352 sampler_ci.mipLodBias = 1.0;
7353 sampler_ci.anisotropyEnable = VK_FALSE;
7354 sampler_ci.maxAnisotropy = 1;
7355 sampler_ci.compareEnable = VK_FALSE;
7356 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7357 sampler_ci.minLod = 1.0;
7358 sampler_ci.maxLod = 1.0;
7359 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7360 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007361 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007362 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007363 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007364
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007365 VkDescriptorImageInfo info = {};
7366 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007367
7368 VkWriteDescriptorSet descriptor_write;
7369 memset(&descriptor_write, 0, sizeof(descriptor_write));
Karl Schultz6addd812016-02-02 17:17:23 -07007370 descriptor_write.sType =
7371 (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007372 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007373 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007374 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007375 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007376 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007377
7378 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7379
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007380 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007381
Chia-I Wuf7458c52015-10-26 21:10:41 +08007382 vkDestroySampler(m_device->device(), sampler, NULL);
7383 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7384 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007385}
7386
Karl Schultz6addd812016-02-02 17:17:23 -07007387TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007388 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07007389 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007390
Karl Schultz6addd812016-02-02 17:17:23 -07007391 m_errorMonitor->SetDesiredFailureMsg(
7392 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007393 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007394
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007395 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007396 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
7397 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007398 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007399 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
7400 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007401
7402 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007403 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7404 ds_pool_ci.pNext = NULL;
7405 ds_pool_ci.maxSets = 1;
7406 ds_pool_ci.poolSizeCount = 1;
7407 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007408
7409 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007410 err =
7411 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007412 ASSERT_VK_SUCCESS(err);
7413
7414 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007415 dsl_binding.binding = 0;
7416 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7417 dsl_binding.descriptorCount = 1;
7418 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7419 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007420
7421 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007422 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7423 ds_layout_ci.pNext = NULL;
7424 ds_layout_ci.bindingCount = 1;
7425 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007426 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007427 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7428 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007429 ASSERT_VK_SUCCESS(err);
7430
7431 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007432 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007433 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007434 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007435 alloc_info.descriptorPool = ds_pool;
7436 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007437 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7438 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007439 ASSERT_VK_SUCCESS(err);
7440
Karl Schultz6addd812016-02-02 17:17:23 -07007441 VkSampler sampler =
7442 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007443
7444 VkDescriptorImageInfo descriptor_info;
7445 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
7446 descriptor_info.sampler = sampler;
7447
7448 VkWriteDescriptorSet descriptor_write;
7449 memset(&descriptor_write, 0, sizeof(descriptor_write));
7450 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007451 descriptor_write.dstSet = descriptorSet;
7452 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007453 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007454 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7455 descriptor_write.pImageInfo = &descriptor_info;
7456
7457 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7458
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007459 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007460
Chia-I Wuf7458c52015-10-26 21:10:41 +08007461 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7462 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007463}
7464
Karl Schultz6addd812016-02-02 17:17:23 -07007465TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
7466 // Create a single combined Image/Sampler descriptor and send it an invalid
7467 // imageView
7468 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007469
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7471 "Attempted write update to combined "
7472 "image sampler descriptor failed due "
Tobin Ehlis63c4b8a2016-05-09 10:29:34 -06007473 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007474
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007475 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007476 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007477 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7478 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007479
7480 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007481 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7482 ds_pool_ci.pNext = NULL;
7483 ds_pool_ci.maxSets = 1;
7484 ds_pool_ci.poolSizeCount = 1;
7485 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007486
7487 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007488 err =
7489 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007490 ASSERT_VK_SUCCESS(err);
7491
7492 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007493 dsl_binding.binding = 0;
7494 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7495 dsl_binding.descriptorCount = 1;
7496 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7497 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007498
7499 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007500 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7501 ds_layout_ci.pNext = NULL;
7502 ds_layout_ci.bindingCount = 1;
7503 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007504 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007505 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7506 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007507 ASSERT_VK_SUCCESS(err);
7508
7509 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007510 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007511 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007512 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007513 alloc_info.descriptorPool = ds_pool;
7514 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007515 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7516 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007517 ASSERT_VK_SUCCESS(err);
7518
7519 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007520 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7521 sampler_ci.pNext = NULL;
7522 sampler_ci.magFilter = VK_FILTER_NEAREST;
7523 sampler_ci.minFilter = VK_FILTER_NEAREST;
7524 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7525 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7526 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7527 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7528 sampler_ci.mipLodBias = 1.0;
7529 sampler_ci.anisotropyEnable = VK_FALSE;
7530 sampler_ci.maxAnisotropy = 1;
7531 sampler_ci.compareEnable = VK_FALSE;
7532 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7533 sampler_ci.minLod = 1.0;
7534 sampler_ci.maxLod = 1.0;
7535 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7536 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007537
7538 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007539 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007540 ASSERT_VK_SUCCESS(err);
7541
Karl Schultz6addd812016-02-02 17:17:23 -07007542 VkImageView view =
7543 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007544
7545 VkDescriptorImageInfo descriptor_info;
7546 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
7547 descriptor_info.sampler = sampler;
7548 descriptor_info.imageView = view;
7549
7550 VkWriteDescriptorSet descriptor_write;
7551 memset(&descriptor_write, 0, sizeof(descriptor_write));
7552 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007553 descriptor_write.dstSet = descriptorSet;
7554 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007555 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007556 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7557 descriptor_write.pImageInfo = &descriptor_info;
7558
7559 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7560
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007561 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007562
Chia-I Wuf7458c52015-10-26 21:10:41 +08007563 vkDestroySampler(m_device->device(), sampler, NULL);
7564 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7565 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007566}
7567
Karl Schultz6addd812016-02-02 17:17:23 -07007568TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
7569 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
7570 // into the other
7571 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007572
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7574 " binding #1 with type "
7575 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
7576 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007577
Tobin Ehlis04356f92015-10-27 16:35:27 -06007578 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007579 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007580 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007581 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7582 ds_type_count[0].descriptorCount = 1;
7583 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7584 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007585
7586 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007587 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7588 ds_pool_ci.pNext = NULL;
7589 ds_pool_ci.maxSets = 1;
7590 ds_pool_ci.poolSizeCount = 2;
7591 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007592
7593 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007594 err =
7595 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007596 ASSERT_VK_SUCCESS(err);
7597 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007598 dsl_binding[0].binding = 0;
7599 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7600 dsl_binding[0].descriptorCount = 1;
7601 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7602 dsl_binding[0].pImmutableSamplers = NULL;
7603 dsl_binding[1].binding = 1;
7604 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7605 dsl_binding[1].descriptorCount = 1;
7606 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7607 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007608
7609 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007610 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7611 ds_layout_ci.pNext = NULL;
7612 ds_layout_ci.bindingCount = 2;
7613 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007614
7615 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007616 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7617 &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007618 ASSERT_VK_SUCCESS(err);
7619
7620 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007621 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007622 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007623 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007624 alloc_info.descriptorPool = ds_pool;
7625 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007626 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7627 &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007628 ASSERT_VK_SUCCESS(err);
7629
7630 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007631 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7632 sampler_ci.pNext = NULL;
7633 sampler_ci.magFilter = VK_FILTER_NEAREST;
7634 sampler_ci.minFilter = VK_FILTER_NEAREST;
7635 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7636 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7637 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7638 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7639 sampler_ci.mipLodBias = 1.0;
7640 sampler_ci.anisotropyEnable = VK_FALSE;
7641 sampler_ci.maxAnisotropy = 1;
7642 sampler_ci.compareEnable = VK_FALSE;
7643 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7644 sampler_ci.minLod = 1.0;
7645 sampler_ci.maxLod = 1.0;
7646 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7647 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007648
7649 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007650 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007651 ASSERT_VK_SUCCESS(err);
7652
7653 VkDescriptorImageInfo info = {};
7654 info.sampler = sampler;
7655
7656 VkWriteDescriptorSet descriptor_write;
7657 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
7658 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007659 descriptor_write.dstSet = descriptorSet;
7660 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08007661 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007662 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7663 descriptor_write.pImageInfo = &info;
7664 // This write update should succeed
7665 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7666 // Now perform a copy update that fails due to type mismatch
7667 VkCopyDescriptorSet copy_ds_update;
7668 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
7669 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
7670 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06007671 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007672 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007673 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08007674 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06007675 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
7676
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007677 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06007678 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07007679 m_errorMonitor->SetDesiredFailureMsg(
7680 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007681 " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -06007682 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
7683 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
7684 copy_ds_update.srcSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007685 copy_ds_update.srcBinding =
7686 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007687 copy_ds_update.dstSet = descriptorSet;
7688 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06007689 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06007690 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
7691
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007692 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007693
Tobin Ehlis04356f92015-10-27 16:35:27 -06007694 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07007695 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007696 VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
7697 "update array offset of 0 and update of "
7698 "5 descriptors oversteps total number "
7699 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007700
Tobin Ehlis04356f92015-10-27 16:35:27 -06007701 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
7702 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
7703 copy_ds_update.srcSet = descriptorSet;
7704 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007705 copy_ds_update.dstSet = descriptorSet;
7706 copy_ds_update.dstBinding = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007707 copy_ds_update.descriptorCount =
7708 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06007709 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
7710
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007711 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06007712
Chia-I Wuf7458c52015-10-26 21:10:41 +08007713 vkDestroySampler(m_device->device(), sampler, NULL);
7714 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7715 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007716}
7717
Karl Schultz6addd812016-02-02 17:17:23 -07007718TEST_F(VkLayerTest, NumSamplesMismatch) {
7719 // Create CommandBuffer where MSAA samples doesn't match RenderPass
7720 // sampleCount
7721 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007722
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007724 "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007725
Tobin Ehlis3b780662015-05-28 12:11:26 -06007726 ASSERT_NO_FATAL_FAILURE(InitState());
7727 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007728 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06007729 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007730 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007731
7732 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007733 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7734 ds_pool_ci.pNext = NULL;
7735 ds_pool_ci.maxSets = 1;
7736 ds_pool_ci.poolSizeCount = 1;
7737 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06007738
Tobin Ehlis3b780662015-05-28 12:11:26 -06007739 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007740 err =
7741 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007742 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007743
Tony Barboureb254902015-07-15 12:50:33 -06007744 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007745 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06007746 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007747 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007748 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7749 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007750
Tony Barboureb254902015-07-15 12:50:33 -06007751 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7752 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7753 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007754 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007755 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007756
Tobin Ehlis3b780662015-05-28 12:11:26 -06007757 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007758 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7759 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007760 ASSERT_VK_SUCCESS(err);
7761
7762 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007763 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007764 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007765 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007766 alloc_info.descriptorPool = ds_pool;
7767 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007768 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7769 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007770 ASSERT_VK_SUCCESS(err);
7771
Tony Barboureb254902015-07-15 12:50:33 -06007772 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007773 pipe_ms_state_ci.sType =
7774 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7775 pipe_ms_state_ci.pNext = NULL;
7776 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7777 pipe_ms_state_ci.sampleShadingEnable = 0;
7778 pipe_ms_state_ci.minSampleShading = 1.0;
7779 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007780
Tony Barboureb254902015-07-15 12:50:33 -06007781 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007782 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7783 pipeline_layout_ci.pNext = NULL;
7784 pipeline_layout_ci.setLayoutCount = 1;
7785 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007786
7787 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007788 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7789 &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007790 ASSERT_VK_SUCCESS(err);
7791
Karl Schultz6addd812016-02-02 17:17:23 -07007792 VkShaderObj vs(m_device, bindStateVertShaderText,
7793 VK_SHADER_STAGE_VERTEX_BIT, this);
7794 VkShaderObj fs(m_device, bindStateFragShaderText,
7795 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06007796 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07007797 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06007798 VkPipelineObj pipe(m_device);
7799 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007800 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06007801 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06007802 pipe.SetMSAA(&pipe_ms_state_ci);
7803 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06007804
Tony Barbourfe3351b2015-07-28 10:17:20 -06007805 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007806 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7807 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06007808
Mark Young29927482016-05-04 14:38:51 -06007809 // Render triangle (the error should trigger on the attempt to draw).
7810 Draw(3, 1, 0, 0);
7811
7812 // Finalize recording of the command buffer
7813 EndCommandBuffer();
7814
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007815 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007816
Chia-I Wuf7458c52015-10-26 21:10:41 +08007817 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7818 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7819 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007820}
Mark Young29927482016-05-04 14:38:51 -06007821
Mark Youngc89c6312016-03-31 16:03:20 -06007822TEST_F(VkLayerTest, NumBlendAttachMismatch) {
7823 // Create Pipeline where the number of blend attachments doesn't match the
7824 // number of color attachments. In this case, we don't add any color
7825 // blend attachments even though we have a color attachment.
7826 VkResult err;
7827
7828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young29927482016-05-04 14:38:51 -06007829 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06007830
7831 ASSERT_NO_FATAL_FAILURE(InitState());
7832 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7833 VkDescriptorPoolSize ds_type_count = {};
7834 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7835 ds_type_count.descriptorCount = 1;
7836
7837 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7838 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7839 ds_pool_ci.pNext = NULL;
7840 ds_pool_ci.maxSets = 1;
7841 ds_pool_ci.poolSizeCount = 1;
7842 ds_pool_ci.pPoolSizes = &ds_type_count;
7843
7844 VkDescriptorPool ds_pool;
7845 err =
7846 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7847 ASSERT_VK_SUCCESS(err);
7848
7849 VkDescriptorSetLayoutBinding dsl_binding = {};
7850 dsl_binding.binding = 0;
7851 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7852 dsl_binding.descriptorCount = 1;
7853 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7854 dsl_binding.pImmutableSamplers = NULL;
7855
7856 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7857 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7858 ds_layout_ci.pNext = NULL;
7859 ds_layout_ci.bindingCount = 1;
7860 ds_layout_ci.pBindings = &dsl_binding;
7861
7862 VkDescriptorSetLayout ds_layout;
7863 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7864 &ds_layout);
7865 ASSERT_VK_SUCCESS(err);
7866
7867 VkDescriptorSet descriptorSet;
7868 VkDescriptorSetAllocateInfo alloc_info = {};
7869 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7870 alloc_info.descriptorSetCount = 1;
7871 alloc_info.descriptorPool = ds_pool;
7872 alloc_info.pSetLayouts = &ds_layout;
7873 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7874 &descriptorSet);
7875 ASSERT_VK_SUCCESS(err);
7876
7877 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7878 pipe_ms_state_ci.sType =
7879 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7880 pipe_ms_state_ci.pNext = NULL;
7881 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7882 pipe_ms_state_ci.sampleShadingEnable = 0;
7883 pipe_ms_state_ci.minSampleShading = 1.0;
7884 pipe_ms_state_ci.pSampleMask = NULL;
7885
7886 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7887 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7888 pipeline_layout_ci.pNext = NULL;
7889 pipeline_layout_ci.setLayoutCount = 1;
7890 pipeline_layout_ci.pSetLayouts = &ds_layout;
7891
7892 VkPipelineLayout pipeline_layout;
7893 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7894 &pipeline_layout);
7895 ASSERT_VK_SUCCESS(err);
7896
7897 VkShaderObj vs(m_device, bindStateVertShaderText,
7898 VK_SHADER_STAGE_VERTEX_BIT, this);
7899 VkShaderObj fs(m_device, bindStateFragShaderText,
7900 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06007901 this); // We shouldn't need a fragment shader
Mark Youngc89c6312016-03-31 16:03:20 -06007902 // but add it to be able to run on more devices
7903 VkPipelineObj pipe(m_device);
7904 pipe.AddShader(&vs);
7905 pipe.AddShader(&fs);
7906 pipe.SetMSAA(&pipe_ms_state_ci);
7907 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7908
7909 BeginCommandBuffer();
7910 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7911 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7912
Mark Young29927482016-05-04 14:38:51 -06007913 // Render triangle (the error should trigger on the attempt to draw).
7914 Draw(3, 1, 0, 0);
7915
7916 // Finalize recording of the command buffer
7917 EndCommandBuffer();
7918
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007919 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06007920
7921 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7922 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7923 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7924}
Mark Young29927482016-05-04 14:38:51 -06007925
Karl Schultz6addd812016-02-02 17:17:23 -07007926TEST_F(VkLayerTest, ClearCmdNoDraw) {
7927 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
7928 // to issuing a Draw
7929 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007930
Karl Schultz6addd812016-02-02 17:17:23 -07007931 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbour7e56d302016-03-02 15:12:01 -07007932 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007933 "vkCmdClearAttachments() issued on CB object ");
7934
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007935 ASSERT_NO_FATAL_FAILURE(InitState());
7936 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
Tobin Ehlis53eddda2015-07-01 16:46:13 -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 Ehlis53eddda2015-07-01 16:46:13 -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 Ehlis53eddda2015-07-01 16:46:13 -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;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007966
Tobin Ehlis53eddda2015-07-01 16:46:13 -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 Ehlis53eddda2015-07-01 16:46:13 -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 Ehlis53eddda2015-07-01 16:46:13 -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_4_BIT;
7987 pipe_ms_state_ci.sampleShadingEnable = 0;
7988 pipe_ms_state_ci.minSampleShading = 1.0;
7989 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -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;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007996
7997 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007998 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7999 &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008000 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008001
Karl Schultz6addd812016-02-02 17:17:23 -07008002 VkShaderObj vs(m_device, bindStateVertShaderText,
8003 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06008004 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07008005 // on more devices
8006 VkShaderObj fs(m_device, bindStateFragShaderText,
8007 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008008
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008009 VkPipelineObj pipe(m_device);
8010 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008011 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008012 pipe.SetMSAA(&pipe_ms_state_ci);
8013 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06008014
8015 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008016
Karl Schultz6addd812016-02-02 17:17:23 -07008017 // Main thing we care about for this test is that the VkImage obj we're
8018 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008019 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008020 VkClearAttachment color_attachment;
8021 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8022 color_attachment.clearValue.color.float32[0] = 1.0;
8023 color_attachment.clearValue.color.float32[1] = 1.0;
8024 color_attachment.clearValue.color.float32[2] = 1.0;
8025 color_attachment.clearValue.color.float32[3] = 1.0;
8026 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008027 VkClearRect clear_rect = {
8028 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008029
Karl Schultz6addd812016-02-02 17:17:23 -07008030 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
8031 &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008032
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008033 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008034
Chia-I Wuf7458c52015-10-26 21:10:41 +08008035 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8036 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8037 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008038}
8039
Karl Schultz6addd812016-02-02 17:17:23 -07008040TEST_F(VkLayerTest, VtxBufferBadIndex) {
8041 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008042
Karl Schultz6addd812016-02-02 17:17:23 -07008043 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008044 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07008045 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008046
Tobin Ehlis502480b2015-06-24 15:53:07 -06008047 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06008048 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06008049 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06008050
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008051 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008052 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8053 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008054
8055 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008056 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8057 ds_pool_ci.pNext = NULL;
8058 ds_pool_ci.maxSets = 1;
8059 ds_pool_ci.poolSizeCount = 1;
8060 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008061
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008062 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008063 err =
8064 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008065 ASSERT_VK_SUCCESS(err);
8066
Tony Barboureb254902015-07-15 12:50:33 -06008067 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008068 dsl_binding.binding = 0;
8069 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8070 dsl_binding.descriptorCount = 1;
8071 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8072 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008073
Tony Barboureb254902015-07-15 12:50:33 -06008074 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008075 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8076 ds_layout_ci.pNext = NULL;
8077 ds_layout_ci.bindingCount = 1;
8078 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008079
Tobin Ehlis502480b2015-06-24 15:53:07 -06008080 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008081 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8082 &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008083 ASSERT_VK_SUCCESS(err);
8084
8085 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008086 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008087 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008088 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008089 alloc_info.descriptorPool = ds_pool;
8090 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008091 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8092 &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008093 ASSERT_VK_SUCCESS(err);
8094
Tony Barboureb254902015-07-15 12:50:33 -06008095 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008096 pipe_ms_state_ci.sType =
8097 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8098 pipe_ms_state_ci.pNext = NULL;
8099 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8100 pipe_ms_state_ci.sampleShadingEnable = 0;
8101 pipe_ms_state_ci.minSampleShading = 1.0;
8102 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008103
Tony Barboureb254902015-07-15 12:50:33 -06008104 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008105 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8106 pipeline_layout_ci.pNext = NULL;
8107 pipeline_layout_ci.setLayoutCount = 1;
8108 pipeline_layout_ci.pSetLayouts = &ds_layout;
8109 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008110
Karl Schultz6addd812016-02-02 17:17:23 -07008111 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8112 &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008113 ASSERT_VK_SUCCESS(err);
8114
Karl Schultz6addd812016-02-02 17:17:23 -07008115 VkShaderObj vs(m_device, bindStateVertShaderText,
8116 VK_SHADER_STAGE_VERTEX_BIT, this);
8117 VkShaderObj fs(m_device, bindStateFragShaderText,
8118 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06008119 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07008120 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008121 VkPipelineObj pipe(m_device);
8122 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008123 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06008124 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008125 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008126 pipe.SetViewport(m_viewports);
8127 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008128 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06008129
8130 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008131 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8132 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06008133 // Don't care about actual data, just need to get to draw to flag error
8134 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz6addd812016-02-02 17:17:23 -07008135 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
8136 (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06008137 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06008138 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008139
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008140 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008141
Chia-I Wuf7458c52015-10-26 21:10:41 +08008142 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8143 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8144 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008145}
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06008146// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
8147TEST_F(VkLayerTest, InvalidImageLayout) {
8148 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
8149 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
8150 "images in the wrong layout when they're copied or transitioned.");
8151 // 3 in ValidateCmdBufImageLayouts
8152 // * -1 Attempt to submit cmd buf w/ deleted image
8153 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
8154 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
8155 m_errorMonitor->SetDesiredFailureMsg(
8156 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8157 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
8158
8159 ASSERT_NO_FATAL_FAILURE(InitState());
8160 // Create src & dst images to use for copy operations
8161 VkImage src_image;
8162 VkImage dst_image;
8163
8164 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8165 const int32_t tex_width = 32;
8166 const int32_t tex_height = 32;
8167
8168 VkImageCreateInfo image_create_info = {};
8169 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8170 image_create_info.pNext = NULL;
8171 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8172 image_create_info.format = tex_format;
8173 image_create_info.extent.width = tex_width;
8174 image_create_info.extent.height = tex_height;
8175 image_create_info.extent.depth = 1;
8176 image_create_info.mipLevels = 1;
8177 image_create_info.arrayLayers = 4;
8178 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8179 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8180 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8181 image_create_info.flags = 0;
8182
8183 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
8184 ASSERT_VK_SUCCESS(err);
8185 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
8186 ASSERT_VK_SUCCESS(err);
8187
8188 BeginCommandBuffer();
8189 VkImageCopy copyRegion;
8190 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8191 copyRegion.srcSubresource.mipLevel = 0;
8192 copyRegion.srcSubresource.baseArrayLayer = 0;
8193 copyRegion.srcSubresource.layerCount = 1;
8194 copyRegion.srcOffset.x = 0;
8195 copyRegion.srcOffset.y = 0;
8196 copyRegion.srcOffset.z = 0;
8197 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8198 copyRegion.dstSubresource.mipLevel = 0;
8199 copyRegion.dstSubresource.baseArrayLayer = 0;
8200 copyRegion.dstSubresource.layerCount = 1;
8201 copyRegion.dstOffset.x = 0;
8202 copyRegion.dstOffset.y = 0;
8203 copyRegion.dstOffset.z = 0;
8204 copyRegion.extent.width = 1;
8205 copyRegion.extent.height = 1;
8206 copyRegion.extent.depth = 1;
8207 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8208 m_errorMonitor->VerifyFound();
8209 // Now cause error due to src image layout changing
8210 m_errorMonitor->SetDesiredFailureMsg(
8211 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8212 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
8213 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8214 m_errorMonitor->VerifyFound();
8215 // Final src error is due to bad layout type
8216 m_errorMonitor->SetDesiredFailureMsg(
8217 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8218 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
8219 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8220 m_errorMonitor->VerifyFound();
8221 // Now verify same checks for dst
8222 m_errorMonitor->SetDesiredFailureMsg(
8223 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8224 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
8225 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8226 m_errorMonitor->VerifyFound();
8227 // Now cause error due to src image layout changing
8228 m_errorMonitor->SetDesiredFailureMsg(
8229 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8230 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
8231 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
8232 m_errorMonitor->VerifyFound();
8233 m_errorMonitor->SetDesiredFailureMsg(
8234 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8235 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
8236 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
8237 m_errorMonitor->VerifyFound();
8238 // Now cause error due to bad image layout transition in PipelineBarrier
8239 VkImageMemoryBarrier image_barrier[1] = {};
8240 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
8241 image_barrier[0].image = src_image;
8242 image_barrier[0].subresourceRange.layerCount = 2;
8243 image_barrier[0].subresourceRange.levelCount = 2;
8244 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8245 m_errorMonitor->SetDesiredFailureMsg(
8246 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8247 "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL.");
8248 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier);
8249 m_errorMonitor->VerifyFound();
8250
8251 // Finally some layout errors at RenderPass create time
8252 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
8253 VkAttachmentReference attach = {};
8254 // perf warning for GENERAL layout w/ non-DS input attachment
8255 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8256 VkSubpassDescription subpass = {};
8257 subpass.inputAttachmentCount = 1;
8258 subpass.pInputAttachments = &attach;
8259 VkRenderPassCreateInfo rpci = {};
8260 rpci.subpassCount = 1;
8261 rpci.pSubpasses = &subpass;
8262 rpci.attachmentCount = 1;
8263 VkAttachmentDescription attach_desc = {};
8264 attach_desc.format = VK_FORMAT_UNDEFINED;
8265 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -06008266 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06008267 VkRenderPass rp;
8268 m_errorMonitor->SetDesiredFailureMsg(
8269 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8270 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
8271 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8272 m_errorMonitor->VerifyFound();
8273 // error w/ non-general layout
8274 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
8275
8276 m_errorMonitor->SetDesiredFailureMsg(
8277 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8278 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
8279 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8280 m_errorMonitor->VerifyFound();
8281 subpass.inputAttachmentCount = 0;
8282 subpass.colorAttachmentCount = 1;
8283 subpass.pColorAttachments = &attach;
8284 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8285 // perf warning for GENERAL layout on color attachment
8286 m_errorMonitor->SetDesiredFailureMsg(
8287 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8288 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
8289 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8290 m_errorMonitor->VerifyFound();
8291 // error w/ non-color opt or GENERAL layout for color attachment
8292 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
8293 m_errorMonitor->SetDesiredFailureMsg(
8294 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8295 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
8296 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8297 m_errorMonitor->VerifyFound();
8298 subpass.colorAttachmentCount = 0;
8299 subpass.pDepthStencilAttachment = &attach;
8300 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8301 // perf warning for GENERAL layout on DS attachment
8302 m_errorMonitor->SetDesiredFailureMsg(
8303 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8304 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
8305 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8306 m_errorMonitor->VerifyFound();
8307 // error w/ non-ds opt or GENERAL layout for color attachment
8308 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
8309 m_errorMonitor->SetDesiredFailureMsg(
8310 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8311 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.");
8312 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8313 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -06008314 // For this error we need a valid renderpass so create default one
8315 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
8316 attach.attachment = 0;
8317 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
8318 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
8319 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
8320 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
8321 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
8322 // Can't do a CLEAR load on READ_ONLY initialLayout
8323 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8324 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
8325 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8327 " with invalid first layout "
8328 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
8329 "ONLY_OPTIMAL");
8330 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8331 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06008332
8333 vkDestroyImage(m_device->device(), src_image, NULL);
8334 vkDestroyImage(m_device->device(), dst_image, NULL);
8335}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008336#endif // DRAW_STATE_TESTS
8337
Tobin Ehlis0788f522015-05-26 16:11:58 -06008338#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06008339#if GTEST_IS_THREADSAFE
8340struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008341 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008342 VkEvent event;
8343 bool bailout;
8344};
8345
Karl Schultz6addd812016-02-02 17:17:23 -07008346extern "C" void *AddToCommandBuffer(void *arg) {
8347 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008348
Karl Schultz6addd812016-02-02 17:17:23 -07008349 for (int i = 0; i < 10000; i++) {
8350 vkCmdSetEvent(data->commandBuffer, data->event,
8351 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008352 if (data->bailout) {
8353 break;
8354 }
8355 }
8356 return NULL;
8357}
8358
Karl Schultz6addd812016-02-02 17:17:23 -07008359TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -06008360 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008361
Karl Schultz6addd812016-02-02 17:17:23 -07008362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8363 "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008364
Mike Stroyanaccf7692015-05-12 16:00:45 -06008365 ASSERT_NO_FATAL_FAILURE(InitState());
8366 ASSERT_NO_FATAL_FAILURE(InitViewport());
8367 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8368
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008369 // Calls AllocateCommandBuffers
8370 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06008371
8372 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008373 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008374
8375 VkEventCreateInfo event_info;
8376 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008377 VkResult err;
8378
8379 memset(&event_info, 0, sizeof(event_info));
8380 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8381
Chia-I Wuf7458c52015-10-26 21:10:41 +08008382 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008383 ASSERT_VK_SUCCESS(err);
8384
Mike Stroyanaccf7692015-05-12 16:00:45 -06008385 err = vkResetEvent(device(), event);
8386 ASSERT_VK_SUCCESS(err);
8387
8388 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008389 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008390 data.event = event;
8391 data.bailout = false;
8392 m_errorMonitor->SetBailout(&data.bailout);
8393 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06008394 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008395 // Add many entries to command buffer from this thread at the same time.
8396 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06008397
Mike Stroyan4268d1f2015-07-13 14:45:35 -06008398 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008399 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008400
Mike Stroyan10b8cb72016-01-22 15:22:03 -07008401 m_errorMonitor->SetBailout(NULL);
8402
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008403 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008404
Chia-I Wuf7458c52015-10-26 21:10:41 +08008405 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008406}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008407#endif // GTEST_IS_THREADSAFE
8408#endif // THREADING_TESTS
8409
Chris Forbes9f7ff632015-05-25 11:13:08 +12008410#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07008411TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008413 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008414
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008415 ASSERT_NO_FATAL_FAILURE(InitState());
8416 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8417
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008418 VkShaderModule module;
8419 VkShaderModuleCreateInfo moduleCreateInfo;
8420 struct icd_spv_header spv;
8421
8422 spv.magic = ICD_SPV_MAGIC;
8423 spv.version = ICD_SPV_VERSION;
8424 spv.gen_magic = 0;
8425
8426 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
8427 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07008428 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008429 moduleCreateInfo.codeSize = 4;
8430 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008431 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008432
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008433 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008434}
8435
Karl Schultz6addd812016-02-02 17:17:23 -07008436TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008438 "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008439
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008440 ASSERT_NO_FATAL_FAILURE(InitState());
8441 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8442
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008443 VkShaderModule module;
8444 VkShaderModuleCreateInfo moduleCreateInfo;
8445 struct icd_spv_header spv;
8446
8447 spv.magic = ~ICD_SPV_MAGIC;
8448 spv.version = ICD_SPV_VERSION;
8449 spv.gen_magic = 0;
8450
8451 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
8452 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07008453 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008454 moduleCreateInfo.codeSize = sizeof(spv) + 10;
8455 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008456 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008457
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008458 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008459}
8460
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008461#if 0
8462// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -07008463TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008465 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008466
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008467 ASSERT_NO_FATAL_FAILURE(InitState());
8468 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8469
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008470 VkShaderModule module;
8471 VkShaderModuleCreateInfo moduleCreateInfo;
8472 struct icd_spv_header spv;
8473
8474 spv.magic = ICD_SPV_MAGIC;
8475 spv.version = ~ICD_SPV_VERSION;
8476 spv.gen_magic = 0;
8477
8478 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
8479 moduleCreateInfo.pNext = NULL;
8480
Karl Schultz6addd812016-02-02 17:17:23 -07008481 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008482 moduleCreateInfo.codeSize = sizeof(spv) + 10;
8483 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008484 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008485
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008486 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008487}
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008488#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008489
Karl Schultz6addd812016-02-02 17:17:23 -07008490TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008492 "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008493
Chris Forbes9f7ff632015-05-25 11:13:08 +12008494 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12008496
8497 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008498 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12008499 "\n"
8500 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07008501 "out gl_PerVertex {\n"
8502 " vec4 gl_Position;\n"
8503 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12008504 "void main(){\n"
8505 " gl_Position = vec4(1);\n"
8506 " x = 0;\n"
8507 "}\n";
8508 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008509 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12008510 "\n"
8511 "layout(location=0) out vec4 color;\n"
8512 "void main(){\n"
8513 " color = vec4(1);\n"
8514 "}\n";
8515
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008516 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8517 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12008518
8519 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008520 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12008521 pipe.AddShader(&vs);
8522 pipe.AddShader(&fs);
8523
Chris Forbes9f7ff632015-05-25 11:13:08 +12008524 VkDescriptorSetObj descriptorSet(m_device);
8525 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008526 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12008527
Tony Barbour5781e8f2015-08-04 16:23:11 -06008528 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12008529
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008530 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +12008531}
Chris Forbes9f7ff632015-05-25 11:13:08 +12008532
Karl Schultz6addd812016-02-02 17:17:23 -07008533TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008535 "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008536
Chris Forbes59cb88d2015-05-25 11:13:13 +12008537 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008538 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12008539
8540 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008541 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12008542 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07008543 "out gl_PerVertex {\n"
8544 " vec4 gl_Position;\n"
8545 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12008546 "void main(){\n"
8547 " gl_Position = vec4(1);\n"
8548 "}\n";
8549 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008550 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12008551 "\n"
8552 "layout(location=0) in float x;\n"
8553 "layout(location=0) out vec4 color;\n"
8554 "void main(){\n"
8555 " color = vec4(x);\n"
8556 "}\n";
8557
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008558 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8559 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12008560
8561 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008562 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12008563 pipe.AddShader(&vs);
8564 pipe.AddShader(&fs);
8565
Chris Forbes59cb88d2015-05-25 11:13:13 +12008566 VkDescriptorSetObj descriptorSet(m_device);
8567 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008568 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12008569
Tony Barbour5781e8f2015-08-04 16:23:11 -06008570 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12008571
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008572 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +12008573}
8574
Karl Schultz6addd812016-02-02 17:17:23 -07008575TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13008576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008577 "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +13008578
8579 ASSERT_NO_FATAL_FAILURE(InitState());
8580 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8581
8582 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008583 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008584 "\n"
8585 "out gl_PerVertex {\n"
8586 " vec4 gl_Position;\n"
8587 "};\n"
8588 "void main(){\n"
8589 " gl_Position = vec4(1);\n"
8590 "}\n";
8591 char const *fsSource =
8592 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008593 "\n"
8594 "in block { layout(location=0) float x; } ins;\n"
8595 "layout(location=0) out vec4 color;\n"
8596 "void main(){\n"
8597 " color = vec4(ins.x);\n"
8598 "}\n";
8599
8600 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8601 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8602
8603 VkPipelineObj pipe(m_device);
8604 pipe.AddColorAttachment();
8605 pipe.AddShader(&vs);
8606 pipe.AddShader(&fs);
8607
8608 VkDescriptorSetObj descriptorSet(m_device);
8609 descriptorSet.AppendDummy();
8610 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8611
8612 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8613
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008614 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13008615}
8616
Karl Schultz6addd812016-02-02 17:17:23 -07008617TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes0036fd12016-01-26 14:19:49 +13008618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbese9928822016-02-17 14:44:52 +13008619 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz6addd812016-02-02 17:17:23 -07008620 "output arr[2] of float32' vs 'ptr to "
8621 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +13008622
8623 ASSERT_NO_FATAL_FAILURE(InitState());
8624 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8625
8626 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008627 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13008628 "\n"
8629 "layout(location=0) out float x[2];\n"
8630 "out gl_PerVertex {\n"
8631 " vec4 gl_Position;\n"
8632 "};\n"
8633 "void main(){\n"
8634 " x[0] = 0; x[1] = 0;\n"
8635 " gl_Position = vec4(1);\n"
8636 "}\n";
8637 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008638 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13008639 "\n"
8640 "layout(location=0) in float x[3];\n"
8641 "layout(location=0) out vec4 color;\n"
8642 "void main(){\n"
8643 " color = vec4(x[0] + x[1] + x[2]);\n"
8644 "}\n";
8645
8646 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8647 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8648
8649 VkPipelineObj pipe(m_device);
8650 pipe.AddColorAttachment();
8651 pipe.AddShader(&vs);
8652 pipe.AddShader(&fs);
8653
8654 VkDescriptorSetObj descriptorSet(m_device);
8655 descriptorSet.AppendDummy();
8656 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8657
8658 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8659
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008660 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +13008661}
8662
Karl Schultz6addd812016-02-02 17:17:23 -07008663TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008665 "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008666
Chris Forbesb56af562015-05-25 11:13:17 +12008667 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008668 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12008669
8670 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008671 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12008672 "\n"
8673 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07008674 "out gl_PerVertex {\n"
8675 " vec4 gl_Position;\n"
8676 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12008677 "void main(){\n"
8678 " x = 0;\n"
8679 " gl_Position = vec4(1);\n"
8680 "}\n";
8681 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008682 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12008683 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008684 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbesb56af562015-05-25 11:13:17 +12008685 "layout(location=0) out vec4 color;\n"
8686 "void main(){\n"
8687 " color = vec4(x);\n"
8688 "}\n";
8689
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008690 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8691 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12008692
8693 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008694 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12008695 pipe.AddShader(&vs);
8696 pipe.AddShader(&fs);
8697
Chris Forbesb56af562015-05-25 11:13:17 +12008698 VkDescriptorSetObj descriptorSet(m_device);
8699 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008700 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12008701
Tony Barbour5781e8f2015-08-04 16:23:11 -06008702 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12008703
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008704 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +12008705}
8706
Karl Schultz6addd812016-02-02 17:17:23 -07008707TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13008708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008709 "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +13008710
8711 ASSERT_NO_FATAL_FAILURE(InitState());
8712 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8713
8714 char const *vsSource =
8715 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008716 "\n"
8717 "out block { layout(location=0) int x; } outs;\n"
8718 "out gl_PerVertex {\n"
8719 " vec4 gl_Position;\n"
8720 "};\n"
8721 "void main(){\n"
8722 " outs.x = 0;\n"
8723 " gl_Position = vec4(1);\n"
8724 "}\n";
8725 char const *fsSource =
8726 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008727 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008728 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbesa3e85f62016-01-15 14:53:11 +13008729 "layout(location=0) out vec4 color;\n"
8730 "void main(){\n"
8731 " color = vec4(ins.x);\n"
8732 "}\n";
8733
8734 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8735 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8736
8737 VkPipelineObj pipe(m_device);
8738 pipe.AddColorAttachment();
8739 pipe.AddShader(&vs);
8740 pipe.AddShader(&fs);
8741
8742 VkDescriptorSetObj descriptorSet(m_device);
8743 descriptorSet.AppendDummy();
8744 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8745
8746 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8747
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008748 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13008749}
8750
8751TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
8752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8753 "location 0.0 which is not written by vertex shader");
8754
8755 ASSERT_NO_FATAL_FAILURE(InitState());
8756 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8757
8758 char const *vsSource =
8759 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008760 "\n"
8761 "out block { layout(location=1) float x; } outs;\n"
8762 "out gl_PerVertex {\n"
8763 " vec4 gl_Position;\n"
8764 "};\n"
8765 "void main(){\n"
8766 " outs.x = 0;\n"
8767 " gl_Position = vec4(1);\n"
8768 "}\n";
8769 char const *fsSource =
8770 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008771 "\n"
8772 "in block { layout(location=0) float x; } ins;\n"
8773 "layout(location=0) out vec4 color;\n"
8774 "void main(){\n"
8775 " color = vec4(ins.x);\n"
8776 "}\n";
8777
8778 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8779 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8780
8781 VkPipelineObj pipe(m_device);
8782 pipe.AddColorAttachment();
8783 pipe.AddShader(&vs);
8784 pipe.AddShader(&fs);
8785
8786 VkDescriptorSetObj descriptorSet(m_device);
8787 descriptorSet.AppendDummy();
8788 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8789
8790 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8791
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008792 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13008793}
8794
8795TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
8796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8797 "location 0.1 which is not written by vertex shader");
8798
8799 ASSERT_NO_FATAL_FAILURE(InitState());
8800 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8801
8802 char const *vsSource =
8803 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008804 "\n"
8805 "out block { layout(location=0, component=0) float x; } outs;\n"
8806 "out gl_PerVertex {\n"
8807 " vec4 gl_Position;\n"
8808 "};\n"
8809 "void main(){\n"
8810 " outs.x = 0;\n"
8811 " gl_Position = vec4(1);\n"
8812 "}\n";
8813 char const *fsSource =
8814 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008815 "\n"
8816 "in block { layout(location=0, component=1) float x; } ins;\n"
8817 "layout(location=0) out vec4 color;\n"
8818 "void main(){\n"
8819 " color = vec4(ins.x);\n"
8820 "}\n";
8821
8822 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8823 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8824
8825 VkPipelineObj pipe(m_device);
8826 pipe.AddColorAttachment();
8827 pipe.AddShader(&vs);
8828 pipe.AddShader(&fs);
8829
8830 VkDescriptorSetObj descriptorSet(m_device);
8831 descriptorSet.AppendDummy();
8832 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8833
8834 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8835
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008836 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13008837}
8838
Karl Schultz6addd812016-02-02 17:17:23 -07008839TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008841 "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008842
Chris Forbesde136e02015-05-25 11:13:28 +12008843 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008844 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12008845
8846 VkVertexInputBindingDescription input_binding;
8847 memset(&input_binding, 0, sizeof(input_binding));
8848
8849 VkVertexInputAttributeDescription input_attrib;
8850 memset(&input_attrib, 0, sizeof(input_attrib));
8851 input_attrib.format = VK_FORMAT_R32_SFLOAT;
8852
8853 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008854 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12008855 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07008856 "out gl_PerVertex {\n"
8857 " vec4 gl_Position;\n"
8858 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +12008859 "void main(){\n"
8860 " gl_Position = vec4(1);\n"
8861 "}\n";
8862 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008863 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12008864 "\n"
8865 "layout(location=0) out vec4 color;\n"
8866 "void main(){\n"
8867 " color = vec4(1);\n"
8868 "}\n";
8869
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008870 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8871 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12008872
8873 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008874 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12008875 pipe.AddShader(&vs);
8876 pipe.AddShader(&fs);
8877
8878 pipe.AddVertexInputBindings(&input_binding, 1);
8879 pipe.AddVertexInputAttribs(&input_attrib, 1);
8880
Chris Forbesde136e02015-05-25 11:13:28 +12008881 VkDescriptorSetObj descriptorSet(m_device);
8882 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008883 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12008884
Tony Barbour5781e8f2015-08-04 16:23:11 -06008885 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12008886
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008887 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +12008888}
8889
Karl Schultz6addd812016-02-02 17:17:23 -07008890TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008892 "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +13008893
8894 ASSERT_NO_FATAL_FAILURE(InitState());
8895 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8896
8897 VkVertexInputBindingDescription input_binding;
8898 memset(&input_binding, 0, sizeof(input_binding));
8899
8900 VkVertexInputAttributeDescription input_attrib;
8901 memset(&input_attrib, 0, sizeof(input_attrib));
8902 input_attrib.format = VK_FORMAT_R32_SFLOAT;
8903
8904 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008905 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13008906 "\n"
8907 "layout(location=1) in float x;\n"
8908 "out gl_PerVertex {\n"
8909 " vec4 gl_Position;\n"
8910 "};\n"
8911 "void main(){\n"
8912 " gl_Position = vec4(x);\n"
8913 "}\n";
8914 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008915 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13008916 "\n"
8917 "layout(location=0) out vec4 color;\n"
8918 "void main(){\n"
8919 " color = vec4(1);\n"
8920 "}\n";
8921
8922 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8923 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8924
8925 VkPipelineObj pipe(m_device);
8926 pipe.AddColorAttachment();
8927 pipe.AddShader(&vs);
8928 pipe.AddShader(&fs);
8929
8930 pipe.AddVertexInputBindings(&input_binding, 1);
8931 pipe.AddVertexInputAttribs(&input_attrib, 1);
8932
8933 VkDescriptorSetObj descriptorSet(m_device);
8934 descriptorSet.AppendDummy();
8935 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8936
8937 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8938
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008939 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +13008940}
8941
Karl Schultz6addd812016-02-02 17:17:23 -07008942TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
8943 m_errorMonitor->SetDesiredFailureMsg(
8944 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008945 "VS consumes input at location 0 but not provided");
8946
Chris Forbes62e8e502015-05-25 11:13:29 +12008947 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008948 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12008949
8950 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008951 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12008952 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008953 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -07008954 "out gl_PerVertex {\n"
8955 " vec4 gl_Position;\n"
8956 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12008957 "void main(){\n"
8958 " gl_Position = x;\n"
8959 "}\n";
8960 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008961 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12008962 "\n"
8963 "layout(location=0) out vec4 color;\n"
8964 "void main(){\n"
8965 " color = vec4(1);\n"
8966 "}\n";
8967
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008968 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8969 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12008970
8971 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008972 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12008973 pipe.AddShader(&vs);
8974 pipe.AddShader(&fs);
8975
Chris Forbes62e8e502015-05-25 11:13:29 +12008976 VkDescriptorSetObj descriptorSet(m_device);
8977 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008978 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12008979
Tony Barbour5781e8f2015-08-04 16:23:11 -06008980 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12008981
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008982 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +12008983}
8984
Karl Schultz6addd812016-02-02 17:17:23 -07008985TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
8986 m_errorMonitor->SetDesiredFailureMsg(
8987 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008988 "location 0 does not match VS input type");
8989
Chris Forbesc97d98e2015-05-25 11:13:31 +12008990 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008991 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12008992
8993 VkVertexInputBindingDescription input_binding;
8994 memset(&input_binding, 0, sizeof(input_binding));
8995
8996 VkVertexInputAttributeDescription input_attrib;
8997 memset(&input_attrib, 0, sizeof(input_attrib));
8998 input_attrib.format = VK_FORMAT_R32_SFLOAT;
8999
9000 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009001 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12009002 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009003 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07009004 "out gl_PerVertex {\n"
9005 " vec4 gl_Position;\n"
9006 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12009007 "void main(){\n"
9008 " gl_Position = vec4(x);\n"
9009 "}\n";
9010 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009011 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12009012 "\n"
9013 "layout(location=0) out vec4 color;\n"
9014 "void main(){\n"
9015 " color = vec4(1);\n"
9016 "}\n";
9017
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009018 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9019 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12009020
9021 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009022 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12009023 pipe.AddShader(&vs);
9024 pipe.AddShader(&fs);
9025
9026 pipe.AddVertexInputBindings(&input_binding, 1);
9027 pipe.AddVertexInputAttribs(&input_attrib, 1);
9028
Chris Forbesc97d98e2015-05-25 11:13:31 +12009029 VkDescriptorSetObj descriptorSet(m_device);
9030 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009031 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12009032
Tony Barbour5781e8f2015-08-04 16:23:11 -06009033 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12009034
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009035 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +12009036}
9037
Chris Forbesc68b43c2016-04-06 11:18:47 +12009038TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
9039 m_errorMonitor->SetDesiredFailureMsg(
9040 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9041 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
9042
9043 ASSERT_NO_FATAL_FAILURE(InitState());
9044 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9045
9046 char const *vsSource =
9047 "#version 450\n"
9048 "\n"
9049 "out gl_PerVertex {\n"
9050 " vec4 gl_Position;\n"
9051 "};\n"
9052 "void main(){\n"
9053 " gl_Position = vec4(1);\n"
9054 "}\n";
9055 char const *fsSource =
9056 "#version 450\n"
9057 "\n"
9058 "layout(location=0) out vec4 color;\n"
9059 "void main(){\n"
9060 " color = vec4(1);\n"
9061 "}\n";
9062
9063 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9064 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9065
9066 VkPipelineObj pipe(m_device);
9067 pipe.AddColorAttachment();
9068 pipe.AddShader(&vs);
9069 pipe.AddShader(&vs);
9070 pipe.AddShader(&fs);
9071
9072 VkDescriptorSetObj descriptorSet(m_device);
9073 descriptorSet.AppendDummy();
9074 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9075
9076 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9077
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009078 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +12009079}
9080
Karl Schultz6addd812016-02-02 17:17:23 -07009081TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009082 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13009083
9084 ASSERT_NO_FATAL_FAILURE(InitState());
9085 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9086
9087 VkVertexInputBindingDescription input_binding;
9088 memset(&input_binding, 0, sizeof(input_binding));
9089
9090 VkVertexInputAttributeDescription input_attribs[2];
9091 memset(input_attribs, 0, sizeof(input_attribs));
9092
9093 for (int i = 0; i < 2; i++) {
9094 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
9095 input_attribs[i].location = i;
9096 }
9097
9098 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009099 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009100 "\n"
9101 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009102 "out gl_PerVertex {\n"
9103 " vec4 gl_Position;\n"
9104 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009105 "void main(){\n"
9106 " gl_Position = x[0] + x[1];\n"
9107 "}\n";
9108 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009109 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009110 "\n"
9111 "layout(location=0) out vec4 color;\n"
9112 "void main(){\n"
9113 " color = vec4(1);\n"
9114 "}\n";
9115
9116 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9117 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9118
9119 VkPipelineObj pipe(m_device);
9120 pipe.AddColorAttachment();
9121 pipe.AddShader(&vs);
9122 pipe.AddShader(&fs);
9123
9124 pipe.AddVertexInputBindings(&input_binding, 1);
9125 pipe.AddVertexInputAttribs(input_attribs, 2);
9126
9127 VkDescriptorSetObj descriptorSet(m_device);
9128 descriptorSet.AppendDummy();
9129 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9130
9131 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9132
9133 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009134 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +13009135}
9136
Chris Forbes2682b242015-11-24 11:13:14 +13009137TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
9138{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009139 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13009140
9141 ASSERT_NO_FATAL_FAILURE(InitState());
9142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9143
9144 VkVertexInputBindingDescription input_binding;
9145 memset(&input_binding, 0, sizeof(input_binding));
9146
9147 VkVertexInputAttributeDescription input_attribs[2];
9148 memset(input_attribs, 0, sizeof(input_attribs));
9149
9150 for (int i = 0; i < 2; i++) {
9151 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
9152 input_attribs[i].location = i;
9153 }
9154
9155 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009156 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009157 "\n"
9158 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -07009159 "out gl_PerVertex {\n"
9160 " vec4 gl_Position;\n"
9161 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009162 "void main(){\n"
9163 " gl_Position = x[0] + x[1];\n"
9164 "}\n";
9165 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009166 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009167 "\n"
9168 "layout(location=0) out vec4 color;\n"
9169 "void main(){\n"
9170 " color = vec4(1);\n"
9171 "}\n";
9172
9173 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9174 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9175
9176 VkPipelineObj pipe(m_device);
9177 pipe.AddColorAttachment();
9178 pipe.AddShader(&vs);
9179 pipe.AddShader(&fs);
9180
9181 pipe.AddVertexInputBindings(&input_binding, 1);
9182 pipe.AddVertexInputAttribs(input_attribs, 2);
9183
9184 VkDescriptorSetObj descriptorSet(m_device);
9185 descriptorSet.AppendDummy();
9186 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9187
9188 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9189
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009190 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +13009191}
Chris Forbes2682b242015-11-24 11:13:14 +13009192
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009193TEST_F(VkLayerTest, CreatePipelineSimplePositive)
9194{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009195 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009196
9197 ASSERT_NO_FATAL_FAILURE(InitState());
9198 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9199
9200 char const *vsSource =
9201 "#version 450\n"
9202 "out gl_PerVertex {\n"
9203 " vec4 gl_Position;\n"
9204 "};\n"
9205 "void main(){\n"
9206 " gl_Position = vec4(0);\n"
9207 "}\n";
9208 char const *fsSource =
9209 "#version 450\n"
9210 "\n"
9211 "layout(location=0) out vec4 color;\n"
9212 "void main(){\n"
9213 " color = vec4(1);\n"
9214 "}\n";
9215
9216 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9217 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9218
9219 VkPipelineObj pipe(m_device);
9220 pipe.AddColorAttachment();
9221 pipe.AddShader(&vs);
9222 pipe.AddShader(&fs);
9223
9224 VkDescriptorSetObj descriptorSet(m_device);
9225 descriptorSet.AppendDummy();
9226 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9227
9228 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9229
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009230 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009231}
9232
Chris Forbes912c9192016-04-05 17:50:35 +12009233TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch)
9234{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009235 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +12009236
9237 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
9238
9239 ASSERT_NO_FATAL_FAILURE(InitState());
9240 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9241
9242 char const *vsSource =
9243 "#version 450\n"
9244 "out gl_PerVertex {\n"
9245 " vec4 gl_Position;\n"
9246 "};\n"
9247 "layout(location=0) out vec3 x;\n"
9248 "layout(location=1) out ivec3 y;\n"
9249 "layout(location=2) out vec3 z;\n"
9250 "void main(){\n"
9251 " gl_Position = vec4(0);\n"
9252 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
9253 "}\n";
9254 char const *fsSource =
9255 "#version 450\n"
9256 "\n"
9257 "layout(location=0) out vec4 color;\n"
9258 "layout(location=0) in float x;\n"
9259 "layout(location=1) flat in int y;\n"
9260 "layout(location=2) in vec2 z;\n"
9261 "void main(){\n"
9262 " color = vec4(1 + x + y + z.x);\n"
9263 "}\n";
9264
9265 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9266 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9267
9268 VkPipelineObj pipe(m_device);
9269 pipe.AddColorAttachment();
9270 pipe.AddShader(&vs);
9271 pipe.AddShader(&fs);
9272
9273 VkDescriptorSetObj descriptorSet(m_device);
9274 descriptorSet.AppendDummy();
9275 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9276
9277 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9278
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009279 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +12009280}
9281
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009282TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
9283{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009284 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009285
9286 ASSERT_NO_FATAL_FAILURE(InitState());
9287 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9288
Chris Forbesc1e852d2016-04-04 19:26:42 +12009289 if (!m_device->phy().features().tessellationShader) {
9290 printf("Device does not support tessellation shaders; skipped.\n");
9291 return;
9292 }
9293
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009294 char const *vsSource =
9295 "#version 450\n"
9296 "void main(){}\n";
9297 char const *tcsSource =
9298 "#version 450\n"
9299 "layout(location=0) out int x[];\n"
9300 "layout(vertices=3) out;\n"
9301 "void main(){\n"
9302 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
9303 " gl_TessLevelInner[0] = 1;\n"
9304 " x[gl_InvocationID] = gl_InvocationID;\n"
9305 "}\n";
9306 char const *tesSource =
9307 "#version 450\n"
9308 "layout(triangles, equal_spacing, cw) in;\n"
9309 "layout(location=0) in int x[];\n"
9310 "out gl_PerVertex { vec4 gl_Position; };\n"
9311 "void main(){\n"
9312 " gl_Position.xyz = gl_TessCoord;\n"
9313 " gl_Position.w = x[0] + x[1] + x[2];\n"
9314 "}\n";
9315 char const *fsSource =
9316 "#version 450\n"
9317 "layout(location=0) out vec4 color;\n"
9318 "void main(){\n"
9319 " color = vec4(1);\n"
9320 "}\n";
9321
9322 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9323 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
9324 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
9325 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9326
9327 VkPipelineInputAssemblyStateCreateInfo iasci{
9328 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
9329 nullptr,
9330 0,
9331 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
9332 VK_FALSE};
9333
Chris Forbesb4cacb62016-04-04 19:15:00 +12009334 VkPipelineTessellationStateCreateInfo tsci{
9335 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
9336 nullptr,
9337 0,
9338 3};
9339
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009340 VkPipelineObj pipe(m_device);
9341 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +12009342 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009343 pipe.AddColorAttachment();
9344 pipe.AddShader(&vs);
9345 pipe.AddShader(&tcs);
9346 pipe.AddShader(&tes);
9347 pipe.AddShader(&fs);
9348
9349 VkDescriptorSetObj descriptorSet(m_device);
9350 descriptorSet.AppendDummy();
9351 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9352
9353 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9354
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009355 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009356}
9357
Chris Forbesa0ab8152016-04-20 13:34:27 +12009358TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive)
9359{
9360 m_errorMonitor->ExpectSuccess();
9361
9362 ASSERT_NO_FATAL_FAILURE(InitState());
9363 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9364
9365 if (!m_device->phy().features().geometryShader) {
9366 printf("Device does not support geometry shaders; skipped.\n");
9367 return;
9368 }
9369
9370 char const *vsSource =
9371 "#version 450\n"
9372 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
9373 "void main(){\n"
9374 " vs_out.x = vec4(1);\n"
9375 "}\n";
9376 char const *gsSource =
9377 "#version 450\n"
9378 "layout(triangles) in;\n"
9379 "layout(triangle_strip, max_vertices=3) out;\n"
9380 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
9381 "out gl_PerVertex { vec4 gl_Position; };\n"
9382 "void main() {\n"
9383 " gl_Position = gs_in[0].x;\n"
9384 " EmitVertex();\n"
9385 "}\n";
9386 char const *fsSource =
9387 "#version 450\n"
9388 "layout(location=0) out vec4 color;\n"
9389 "void main(){\n"
9390 " color = vec4(1);\n"
9391 "}\n";
9392
9393 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9394 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
9395 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9396
9397 VkPipelineObj pipe(m_device);
9398 pipe.AddColorAttachment();
9399 pipe.AddShader(&vs);
9400 pipe.AddShader(&gs);
9401 pipe.AddShader(&fs);
9402
9403 VkDescriptorSetObj descriptorSet(m_device);
9404 descriptorSet.AppendDummy();
9405 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9406
9407 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9408
9409 m_errorMonitor->VerifyNotFound();
9410}
9411
Chris Forbesa0193bc2016-04-04 19:19:47 +12009412TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
9413{
9414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9415 "is per-vertex in tessellation control shader stage "
9416 "but per-patch in tessellation evaluation shader stage");
9417
9418 ASSERT_NO_FATAL_FAILURE(InitState());
9419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9420
Chris Forbesc1e852d2016-04-04 19:26:42 +12009421 if (!m_device->phy().features().tessellationShader) {
9422 printf("Device does not support tessellation shaders; skipped.\n");
9423 return;
9424 }
9425
Chris Forbesa0193bc2016-04-04 19:19:47 +12009426 char const *vsSource =
9427 "#version 450\n"
9428 "void main(){}\n";
9429 char const *tcsSource =
9430 "#version 450\n"
9431 "layout(location=0) out int x[];\n"
9432 "layout(vertices=3) out;\n"
9433 "void main(){\n"
9434 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
9435 " gl_TessLevelInner[0] = 1;\n"
9436 " x[gl_InvocationID] = gl_InvocationID;\n"
9437 "}\n";
9438 char const *tesSource =
9439 "#version 450\n"
9440 "layout(triangles, equal_spacing, cw) in;\n"
9441 "layout(location=0) patch in int x;\n"
9442 "out gl_PerVertex { vec4 gl_Position; };\n"
9443 "void main(){\n"
9444 " gl_Position.xyz = gl_TessCoord;\n"
9445 " gl_Position.w = x;\n"
9446 "}\n";
9447 char const *fsSource =
9448 "#version 450\n"
9449 "layout(location=0) out vec4 color;\n"
9450 "void main(){\n"
9451 " color = vec4(1);\n"
9452 "}\n";
9453
9454 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9455 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
9456 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
9457 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9458
9459 VkPipelineInputAssemblyStateCreateInfo iasci{
9460 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
9461 nullptr,
9462 0,
9463 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
9464 VK_FALSE};
9465
9466 VkPipelineTessellationStateCreateInfo tsci{
9467 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
9468 nullptr,
9469 0,
9470 3};
9471
9472 VkPipelineObj pipe(m_device);
9473 pipe.SetInputAssembly(&iasci);
9474 pipe.SetTessellation(&tsci);
9475 pipe.AddColorAttachment();
9476 pipe.AddShader(&vs);
9477 pipe.AddShader(&tcs);
9478 pipe.AddShader(&tes);
9479 pipe.AddShader(&fs);
9480
9481 VkDescriptorSetObj descriptorSet(m_device);
9482 descriptorSet.AppendDummy();
9483 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9484
9485 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9486
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009487 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +12009488}
9489
Karl Schultz6addd812016-02-02 17:17:23 -07009490TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
9491 m_errorMonitor->SetDesiredFailureMsg(
9492 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009493 "Duplicate vertex input binding descriptions for binding 0");
9494
Chris Forbes280ba2c2015-06-12 11:16:41 +12009495 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009496 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12009497
9498 /* Two binding descriptions for binding 0 */
9499 VkVertexInputBindingDescription input_bindings[2];
9500 memset(input_bindings, 0, sizeof(input_bindings));
9501
9502 VkVertexInputAttributeDescription input_attrib;
9503 memset(&input_attrib, 0, sizeof(input_attrib));
9504 input_attrib.format = VK_FORMAT_R32_SFLOAT;
9505
9506 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009507 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12009508 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009509 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07009510 "out gl_PerVertex {\n"
9511 " vec4 gl_Position;\n"
9512 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12009513 "void main(){\n"
9514 " gl_Position = vec4(x);\n"
9515 "}\n";
9516 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009517 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12009518 "\n"
9519 "layout(location=0) out vec4 color;\n"
9520 "void main(){\n"
9521 " color = vec4(1);\n"
9522 "}\n";
9523
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009524 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9525 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +12009526
9527 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009528 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12009529 pipe.AddShader(&vs);
9530 pipe.AddShader(&fs);
9531
9532 pipe.AddVertexInputBindings(input_bindings, 2);
9533 pipe.AddVertexInputAttribs(&input_attrib, 1);
9534
Chris Forbes280ba2c2015-06-12 11:16:41 +12009535 VkDescriptorSetObj descriptorSet(m_device);
9536 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009537 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12009538
Tony Barbour5781e8f2015-08-04 16:23:11 -06009539 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12009540
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009541 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +12009542}
Chris Forbes8f68b562015-05-25 11:13:32 +12009543
Chris Forbes35efec72016-04-21 14:32:08 +12009544TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
9545 m_errorMonitor->ExpectSuccess();
9546
9547 ASSERT_NO_FATAL_FAILURE(InitState());
9548 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9549
9550 if (!m_device->phy().features().tessellationShader) {
9551 printf("Device does not support 64bit vertex attributes; skipped.\n");
9552 return;
9553 }
9554
9555 VkVertexInputBindingDescription input_bindings[1];
9556 memset(input_bindings, 0, sizeof(input_bindings));
9557
9558 VkVertexInputAttributeDescription input_attribs[4];
9559 memset(input_attribs, 0, sizeof(input_attribs));
9560 input_attribs[0].location = 0;
9561 input_attribs[0].offset = 0;
9562 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9563 input_attribs[1].location = 2;
9564 input_attribs[1].offset = 32;
9565 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9566 input_attribs[2].location = 4;
9567 input_attribs[2].offset = 64;
9568 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9569 input_attribs[3].location = 6;
9570 input_attribs[3].offset = 96;
9571 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9572
9573 char const *vsSource =
9574 "#version 450\n"
9575 "\n"
9576 "layout(location=0) in dmat4 x;\n"
9577 "out gl_PerVertex {\n"
9578 " vec4 gl_Position;\n"
9579 "};\n"
9580 "void main(){\n"
9581 " gl_Position = vec4(x[0][0]);\n"
9582 "}\n";
9583 char const *fsSource =
9584 "#version 450\n"
9585 "\n"
9586 "layout(location=0) out vec4 color;\n"
9587 "void main(){\n"
9588 " color = vec4(1);\n"
9589 "}\n";
9590
9591 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9592 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9593
9594 VkPipelineObj pipe(m_device);
9595 pipe.AddColorAttachment();
9596 pipe.AddShader(&vs);
9597 pipe.AddShader(&fs);
9598
9599 pipe.AddVertexInputBindings(input_bindings, 1);
9600 pipe.AddVertexInputAttribs(input_attribs, 4);
9601
9602 VkDescriptorSetObj descriptorSet(m_device);
9603 descriptorSet.AppendDummy();
9604 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9605
9606 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9607
9608 m_errorMonitor->VerifyNotFound();
9609}
9610
Karl Schultz6addd812016-02-02 17:17:23 -07009611TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009613 "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009614
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009615 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009616
9617 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009618 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009619 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009620 "out gl_PerVertex {\n"
9621 " vec4 gl_Position;\n"
9622 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009623 "void main(){\n"
9624 " gl_Position = vec4(1);\n"
9625 "}\n";
9626 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009627 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009628 "\n"
9629 "void main(){\n"
9630 "}\n";
9631
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009632 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9633 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009634
9635 VkPipelineObj pipe(m_device);
9636 pipe.AddShader(&vs);
9637 pipe.AddShader(&fs);
9638
Chia-I Wu08accc62015-07-07 11:50:03 +08009639 /* set up CB 0, not written */
9640 pipe.AddColorAttachment();
9641 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009642
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009643 VkDescriptorSetObj descriptorSet(m_device);
9644 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009645 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009646
Tony Barbour5781e8f2015-08-04 16:23:11 -06009647 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009648
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009649 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009650}
9651
Karl Schultz6addd812016-02-02 17:17:23 -07009652TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Karl Schultz6addd812016-02-02 17:17:23 -07009653 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009654 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009655 "FS writes to output location 1 with no matching attachment");
9656
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009657 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009658
9659 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009660 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009661 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009662 "out gl_PerVertex {\n"
9663 " vec4 gl_Position;\n"
9664 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009665 "void main(){\n"
9666 " gl_Position = vec4(1);\n"
9667 "}\n";
9668 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009669 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009670 "\n"
9671 "layout(location=0) out vec4 x;\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009672 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009673 "void main(){\n"
9674 " x = vec4(1);\n"
9675 " y = vec4(1);\n"
9676 "}\n";
9677
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009678 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9679 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009680
9681 VkPipelineObj pipe(m_device);
9682 pipe.AddShader(&vs);
9683 pipe.AddShader(&fs);
9684
Chia-I Wu08accc62015-07-07 11:50:03 +08009685 /* set up CB 0, not written */
9686 pipe.AddColorAttachment();
9687 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009688 /* FS writes CB 1, but we don't configure it */
9689
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009690 VkDescriptorSetObj descriptorSet(m_device);
9691 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009692 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009693
Tony Barbour5781e8f2015-08-04 16:23:11 -06009694 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009695
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009696 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009697}
9698
Karl Schultz6addd812016-02-02 17:17:23 -07009699TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009701 "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009702
Chris Forbesa36d69e2015-05-25 11:13:44 +12009703 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12009704
9705 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009706 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12009707 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009708 "out gl_PerVertex {\n"
9709 " vec4 gl_Position;\n"
9710 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12009711 "void main(){\n"
9712 " gl_Position = vec4(1);\n"
9713 "}\n";
9714 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009715 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12009716 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009717 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbesa36d69e2015-05-25 11:13:44 +12009718 "void main(){\n"
9719 " x = ivec4(1);\n"
9720 "}\n";
9721
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009722 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9723 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +12009724
9725 VkPipelineObj pipe(m_device);
9726 pipe.AddShader(&vs);
9727 pipe.AddShader(&fs);
9728
Chia-I Wu08accc62015-07-07 11:50:03 +08009729 /* set up CB 0; type is UNORM by default */
9730 pipe.AddColorAttachment();
9731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12009732
Chris Forbesa36d69e2015-05-25 11:13:44 +12009733 VkDescriptorSetObj descriptorSet(m_device);
9734 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009735 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12009736
Tony Barbour5781e8f2015-08-04 16:23:11 -06009737 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12009738
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009739 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +12009740}
Chris Forbes7b1b8932015-06-05 14:43:36 +12009741
Karl Schultz6addd812016-02-02 17:17:23 -07009742TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009744 "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009745
Chris Forbes556c76c2015-08-14 12:04:59 +12009746 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12009747
9748 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009749 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12009750 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009751 "out gl_PerVertex {\n"
9752 " vec4 gl_Position;\n"
9753 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12009754 "void main(){\n"
9755 " gl_Position = vec4(1);\n"
9756 "}\n";
9757 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009758 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12009759 "\n"
9760 "layout(location=0) out vec4 x;\n"
9761 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
9762 "void main(){\n"
9763 " x = vec4(bar.y);\n"
9764 "}\n";
9765
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009766 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9767 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +12009768
Chris Forbes556c76c2015-08-14 12:04:59 +12009769 VkPipelineObj pipe(m_device);
9770 pipe.AddShader(&vs);
9771 pipe.AddShader(&fs);
9772
9773 /* set up CB 0; type is UNORM by default */
9774 pipe.AddColorAttachment();
9775 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9776
9777 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009778 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +12009779
9780 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9781
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009782 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +12009783}
9784
Chris Forbes5c59e902016-02-26 16:56:09 +13009785TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
9786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9787 "not declared in layout");
9788
9789 ASSERT_NO_FATAL_FAILURE(InitState());
9790
9791 char const *vsSource =
9792 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +13009793 "\n"
9794 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
9795 "out gl_PerVertex {\n"
9796 " vec4 gl_Position;\n"
9797 "};\n"
9798 "void main(){\n"
9799 " gl_Position = vec4(consts.x);\n"
9800 "}\n";
9801 char const *fsSource =
9802 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +13009803 "\n"
9804 "layout(location=0) out vec4 x;\n"
9805 "void main(){\n"
9806 " x = vec4(1);\n"
9807 "}\n";
9808
9809 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9810 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9811
9812 VkPipelineObj pipe(m_device);
9813 pipe.AddShader(&vs);
9814 pipe.AddShader(&fs);
9815
9816 /* set up CB 0; type is UNORM by default */
9817 pipe.AddColorAttachment();
9818 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9819
9820 VkDescriptorSetObj descriptorSet(m_device);
9821 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9822
9823 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9824
9825 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009826 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +13009827}
9828
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009829#endif // SHADER_CHECKER_TESTS
9830
9831#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -06009832TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Karl Schultz6addd812016-02-02 17:17:23 -07009833 m_errorMonitor->SetDesiredFailureMsg(
9834 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009835 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009836
9837 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009838
9839 // Create an image
9840 VkImage image;
9841
Karl Schultz6addd812016-02-02 17:17:23 -07009842 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9843 const int32_t tex_width = 32;
9844 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009845
9846 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009847 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9848 image_create_info.pNext = NULL;
9849 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9850 image_create_info.format = tex_format;
9851 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009852 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -07009853 image_create_info.extent.depth = 1;
9854 image_create_info.mipLevels = 1;
9855 image_create_info.arrayLayers = 1;
9856 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9857 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9858 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9859 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009860
9861 // Introduce error by sending down a bogus width extent
9862 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009863 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009864
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009865 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009866}
9867
Mark Youngc48c4c12016-04-11 14:26:49 -06009868TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
9869 m_errorMonitor->SetDesiredFailureMsg(
9870 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9871 "CreateImage extents is 0 for at least one required dimension");
9872
9873 ASSERT_NO_FATAL_FAILURE(InitState());
9874
9875 // Create an image
9876 VkImage image;
9877
9878 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9879 const int32_t tex_width = 32;
9880 const int32_t tex_height = 32;
9881
9882 VkImageCreateInfo image_create_info = {};
9883 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9884 image_create_info.pNext = NULL;
9885 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9886 image_create_info.format = tex_format;
9887 image_create_info.extent.width = tex_width;
9888 image_create_info.extent.height = tex_height;
9889 image_create_info.extent.depth = 1;
9890 image_create_info.mipLevels = 1;
9891 image_create_info.arrayLayers = 1;
9892 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9893 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9894 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9895 image_create_info.flags = 0;
9896
9897 // Introduce error by sending down a bogus width extent
9898 image_create_info.extent.width = 0;
9899 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
9900
9901 m_errorMonitor->VerifyFound();
9902}
9903
Karl Schultz6addd812016-02-02 17:17:23 -07009904TEST_F(VkLayerTest, UpdateBufferAlignment) {
9905 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mike Stroyana3082432015-09-25 13:39:21 -06009906
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009908 "dstOffset, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009909
Mike Stroyana3082432015-09-25 13:39:21 -06009910 ASSERT_NO_FATAL_FAILURE(InitState());
9911
9912 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9913 vk_testing::Buffer buffer;
9914 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
9915
9916 BeginCommandBuffer();
9917 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009918 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009919 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009920
Mike Stroyana3082432015-09-25 13:39:21 -06009921 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009923 "dataSize, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009924
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009925 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009926 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06009927 EndCommandBuffer();
9928}
9929
Karl Schultz6addd812016-02-02 17:17:23 -07009930TEST_F(VkLayerTest, FillBufferAlignment) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009932 "dstOffset, is not a multiple of 4");
Mike Stroyana3082432015-09-25 13:39:21 -06009933
9934 ASSERT_NO_FATAL_FAILURE(InitState());
9935
9936 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9937 vk_testing::Buffer buffer;
9938 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
9939
9940 BeginCommandBuffer();
9941 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009942 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009943 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009944
Mike Stroyana3082432015-09-25 13:39:21 -06009945 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009947 "size, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009948
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009949 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009950
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009951 m_errorMonitor->VerifyFound();
9952
Mike Stroyana3082432015-09-25 13:39:21 -06009953 EndCommandBuffer();
9954}
9955
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009956#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +12009957
Tobin Ehliscde08892015-09-22 10:11:37 -06009958#if IMAGE_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07009959TEST_F(VkLayerTest, InvalidImageView) {
9960 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -06009961
Karl Schultz6addd812016-02-02 17:17:23 -07009962 m_errorMonitor->SetDesiredFailureMsg(
9963 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009964 "vkCreateImageView called with baseMipLevel 10 ");
9965
Tobin Ehliscde08892015-09-22 10:11:37 -06009966 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -06009967
Mike Stroyana3082432015-09-25 13:39:21 -06009968 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -07009969 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -06009970
Karl Schultz6addd812016-02-02 17:17:23 -07009971 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9972 const int32_t tex_width = 32;
9973 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -06009974
9975 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009976 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9977 image_create_info.pNext = NULL;
9978 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9979 image_create_info.format = tex_format;
9980 image_create_info.extent.width = tex_width;
9981 image_create_info.extent.height = tex_height;
9982 image_create_info.extent.depth = 1;
9983 image_create_info.mipLevels = 1;
9984 image_create_info.arrayLayers = 1;
9985 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9986 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9987 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9988 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -06009989
Chia-I Wuf7458c52015-10-26 21:10:41 +08009990 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -06009991 ASSERT_VK_SUCCESS(err);
9992
9993 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009994 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9995 image_view_create_info.image = image;
9996 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
9997 image_view_create_info.format = tex_format;
9998 image_view_create_info.subresourceRange.layerCount = 1;
9999 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
10000 image_view_create_info.subresourceRange.levelCount = 1;
10001 image_view_create_info.subresourceRange.aspectMask =
10002 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060010003
10004 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070010005 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
10006 &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060010007
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010008 m_errorMonitor->VerifyFound();
Tobin Ehliscde08892015-09-22 10:11:37 -060010009}
Mike Stroyana3082432015-09-25 13:39:21 -060010010
Karl Schultz6addd812016-02-02 17:17:23 -070010011TEST_F(VkLayerTest, InvalidImageViewAspect) {
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010012 TEST_DESCRIPTION(
10013 "Create an image and try to create a view with an invalid aspectMask");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010015 "vkCreateImageView: Color image "
10016 "formats must have ONLY the "
10017 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010018
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010019 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010020
Karl Schultz6addd812016-02-02 17:17:23 -070010021 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010022 VkImageObj image(m_device);
10023 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT,
10024 VK_IMAGE_TILING_LINEAR, 0);
10025 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010026
10027 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010028 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010029 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070010030 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
10031 image_view_create_info.format = tex_format;
10032 image_view_create_info.subresourceRange.baseMipLevel = 0;
10033 image_view_create_info.subresourceRange.levelCount = 1;
10034 // Cause an error by setting an invalid image aspect
10035 image_view_create_info.subresourceRange.aspectMask =
10036 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010037
10038 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010039 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010040
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010041 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010042}
10043
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010044TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070010045 VkResult err;
10046 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010047
Karl Schultz6addd812016-02-02 17:17:23 -070010048 m_errorMonitor->SetDesiredFailureMsg(
10049 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010050 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010051
Mike Stroyana3082432015-09-25 13:39:21 -060010052 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010053
10054 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010055 VkImage srcImage;
10056 VkImage dstImage;
10057 VkDeviceMemory srcMem;
10058 VkDeviceMemory destMem;
10059 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010060
10061 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010062 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10063 image_create_info.pNext = NULL;
10064 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10065 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10066 image_create_info.extent.width = 32;
10067 image_create_info.extent.height = 32;
10068 image_create_info.extent.depth = 1;
10069 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010070 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070010071 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10072 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10073 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10074 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010075
Karl Schultz6addd812016-02-02 17:17:23 -070010076 err =
10077 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010078 ASSERT_VK_SUCCESS(err);
10079
Karl Schultz6addd812016-02-02 17:17:23 -070010080 err =
10081 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010082 ASSERT_VK_SUCCESS(err);
10083
10084 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010085 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010086 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10087 memAlloc.pNext = NULL;
10088 memAlloc.allocationSize = 0;
10089 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010090
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010091 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010092 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010093 pass =
10094 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010095 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010096 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010097 ASSERT_VK_SUCCESS(err);
10098
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010099 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010100 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010101 pass =
10102 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010103 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010104 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010105 ASSERT_VK_SUCCESS(err);
10106
10107 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10108 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010109 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010110 ASSERT_VK_SUCCESS(err);
10111
10112 BeginCommandBuffer();
10113 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010114 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010115 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010116 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010117 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060010118 copyRegion.srcOffset.x = 0;
10119 copyRegion.srcOffset.y = 0;
10120 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010121 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010122 copyRegion.dstSubresource.mipLevel = 0;
10123 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010124 // Introduce failure by forcing the dst layerCount to differ from src
10125 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010126 copyRegion.dstOffset.x = 0;
10127 copyRegion.dstOffset.y = 0;
10128 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010129 copyRegion.extent.width = 1;
10130 copyRegion.extent.height = 1;
10131 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010132 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10133 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010134 EndCommandBuffer();
10135
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010136 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010137
Chia-I Wuf7458c52015-10-26 21:10:41 +080010138 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010139 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010140 vkFreeMemory(m_device->device(), srcMem, NULL);
10141 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010142}
10143
Tony Barbourd6673642016-05-05 14:46:39 -060010144TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
10145
10146 TEST_DESCRIPTION("Creating images with unsuported formats ");
10147
10148 ASSERT_NO_FATAL_FAILURE(InitState());
10149 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10150 VkImageObj image(m_device);
10151 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
10152 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
10153 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
10154 VK_IMAGE_TILING_OPTIMAL, 0);
10155 ASSERT_TRUE(image.initialized());
10156
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010157 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
10158 VkImageCreateInfo image_create_info;
10159 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10160 image_create_info.pNext = NULL;
10161 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10162 image_create_info.format = VK_FORMAT_UNDEFINED;
10163 image_create_info.extent.width = 32;
10164 image_create_info.extent.height = 32;
10165 image_create_info.extent.depth = 1;
10166 image_create_info.mipLevels = 1;
10167 image_create_info.arrayLayers = 1;
10168 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10169 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10170 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10171 image_create_info.flags = 0;
10172
10173 m_errorMonitor->SetDesiredFailureMsg(
10174 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10175 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
10176
10177 VkImage localImage;
10178 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
10179 m_errorMonitor->VerifyFound();
10180
Tony Barbourd6673642016-05-05 14:46:39 -060010181 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010182 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060010183 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
10184 VkFormat format = static_cast<VkFormat>(f);
10185 VkFormatProperties fProps = m_device->format_properties(format);
10186 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
10187 fProps.optimalTilingFeatures == 0) {
10188 unsupported = format;
10189 break;
10190 }
10191 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010192
Tony Barbourd6673642016-05-05 14:46:39 -060010193 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060010194 image_create_info.format = unsupported;
Tony Barbourd6673642016-05-05 14:46:39 -060010195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010196 "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060010197
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010198 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060010199 m_errorMonitor->VerifyFound();
10200 }
10201}
10202
10203TEST_F(VkLayerTest, ImageLayerViewTests) {
10204 VkResult ret;
10205 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
10206
10207 ASSERT_NO_FATAL_FAILURE(InitState());
10208
10209 VkImageObj image(m_device);
10210 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
10211 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
10212 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
10213 VK_IMAGE_TILING_OPTIMAL, 0);
10214 ASSERT_TRUE(image.initialized());
10215
10216 VkImageView imgView;
10217 VkImageViewCreateInfo imgViewInfo = {};
10218 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10219 imgViewInfo.image = image.handle();
10220 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
10221 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
10222 imgViewInfo.subresourceRange.layerCount = 1;
10223 imgViewInfo.subresourceRange.baseMipLevel = 0;
10224 imgViewInfo.subresourceRange.levelCount = 1;
10225 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10226
10227 m_errorMonitor->SetDesiredFailureMsg(
10228 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10229 "vkCreateImageView called with baseMipLevel");
10230 // View can't have baseMipLevel >= image's mipLevels - Expect
10231 // VIEW_CREATE_ERROR
10232 imgViewInfo.subresourceRange.baseMipLevel = 1;
10233 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10234 m_errorMonitor->VerifyFound();
10235 imgViewInfo.subresourceRange.baseMipLevel = 0;
10236
10237 m_errorMonitor->SetDesiredFailureMsg(
10238 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10239 "vkCreateImageView called with baseArrayLayer");
10240 // View can't have baseArrayLayer >= image's arraySize - Expect
10241 // VIEW_CREATE_ERROR
10242 imgViewInfo.subresourceRange.baseArrayLayer = 1;
10243 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10244 m_errorMonitor->VerifyFound();
10245 imgViewInfo.subresourceRange.baseArrayLayer = 0;
10246
10247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10248 "vkCreateImageView called with 0 in "
10249 "pCreateInfo->subresourceRange."
10250 "levelCount");
10251 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
10252 imgViewInfo.subresourceRange.levelCount = 0;
10253 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10254 m_errorMonitor->VerifyFound();
10255 imgViewInfo.subresourceRange.levelCount = 1;
10256
10257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10258 "vkCreateImageView called with 0 in "
10259 "pCreateInfo->subresourceRange."
10260 "layerCount");
10261 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
10262 imgViewInfo.subresourceRange.layerCount = 0;
10263 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10264 m_errorMonitor->VerifyFound();
10265 imgViewInfo.subresourceRange.layerCount = 1;
10266
10267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10268 "but both must be color formats");
10269 // Can't use depth format for view into color image - Expect INVALID_FORMAT
10270 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
10271 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10272 m_errorMonitor->VerifyFound();
10273 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
10274
10275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10276 "Formats MUST be IDENTICAL unless "
10277 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
10278 "was set on image creation.");
10279 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
10280 // VIEW_CREATE_ERROR
10281 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
10282 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10283 m_errorMonitor->VerifyFound();
10284 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
10285
10286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10287 "can support ImageViews with "
10288 "differing formats but they must be "
10289 "in the same compatibility class.");
10290 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
10291 // VIEW_CREATE_ERROR
10292 VkImageCreateInfo mutImgInfo = image.create_info();
10293 VkImage mutImage;
10294 mutImgInfo.format = VK_FORMAT_R8_UINT;
10295 assert(
10296 m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures &
10297 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
10298 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
10299 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10300 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
10301 ASSERT_VK_SUCCESS(ret);
10302 imgViewInfo.image = mutImage;
10303 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10304 m_errorMonitor->VerifyFound();
10305 imgViewInfo.image = image.handle();
10306 vkDestroyImage(m_device->handle(), mutImage, NULL);
10307}
10308
10309TEST_F(VkLayerTest, MiscImageLayerTests) {
10310
10311 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
10312
10313 ASSERT_NO_FATAL_FAILURE(InitState());
10314
10315 VkImageObj image(m_device);
10316 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
10317 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
10318 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
10319 VK_IMAGE_TILING_OPTIMAL, 0);
10320 ASSERT_TRUE(image.initialized());
10321
10322 m_errorMonitor->SetDesiredFailureMsg(
10323 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10324 "number of layers in image subresource is zero");
10325 vk_testing::Buffer buffer;
10326 VkMemoryPropertyFlags reqs = 0;
10327 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
10328 VkBufferImageCopy region = {};
10329 region.bufferRowLength = 128;
10330 region.bufferImageHeight = 128;
10331 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10332 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
10333 region.imageSubresource.layerCount = 0;
10334 region.imageExtent.height = 4;
10335 region.imageExtent.width = 4;
10336 region.imageExtent.depth = 1;
10337 m_commandBuffer->BeginCommandBuffer();
10338 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
10339 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
10340 1, &region);
10341 m_errorMonitor->VerifyFound();
10342 region.imageSubresource.layerCount = 1;
10343
10344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10345 "aspectMasks for each region must "
10346 "specify only COLOR or DEPTH or "
10347 "STENCIL");
10348 // Expect MISMATCHED_IMAGE_ASPECT
10349 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
10350 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
10351 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
10352 1, &region);
10353 m_errorMonitor->VerifyFound();
10354 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10355
10356 m_errorMonitor->SetDesiredFailureMsg(
10357 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10358 "If the format of srcImage is a depth, stencil, depth stencil or "
10359 "integer-based format then filter must be VK_FILTER_NEAREST");
10360 // Expect INVALID_FILTER
10361 VkImageObj intImage1(m_device);
10362 intImage1.init(128, 128, VK_FORMAT_R8_UINT,
10363 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
10364 0);
10365 VkImageObj intImage2(m_device);
10366 intImage2.init(128, 128, VK_FORMAT_R8_UINT,
10367 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
10368 0);
10369 VkImageBlit blitRegion = {};
10370 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10371 blitRegion.srcSubresource.baseArrayLayer = 0;
10372 blitRegion.srcSubresource.layerCount = 1;
10373 blitRegion.srcSubresource.mipLevel = 0;
10374 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10375 blitRegion.dstSubresource.baseArrayLayer = 0;
10376 blitRegion.dstSubresource.layerCount = 1;
10377 blitRegion.dstSubresource.mipLevel = 0;
10378
10379 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(),
10380 intImage1.layout(), intImage2.handle(), intImage2.layout(),
10381 16, &blitRegion, VK_FILTER_LINEAR);
10382 m_errorMonitor->VerifyFound();
10383
10384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10385 "called with 0 in ppMemoryBarriers");
10386 VkImageMemoryBarrier img_barrier;
10387 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10388 img_barrier.pNext = NULL;
10389 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10390 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10391 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10392 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10393 img_barrier.image = image.handle();
10394 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10395 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10396 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10397 img_barrier.subresourceRange.baseArrayLayer = 0;
10398 img_barrier.subresourceRange.baseMipLevel = 0;
10399 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
10400 img_barrier.subresourceRange.layerCount = 0;
10401 img_barrier.subresourceRange.levelCount = 1;
10402 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
10403 VK_PIPELINE_STAGE_HOST_BIT,
10404 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
10405 nullptr, 1, &img_barrier);
10406 m_errorMonitor->VerifyFound();
10407 img_barrier.subresourceRange.layerCount = 1;
10408}
10409
10410TEST_F(VkLayerTest, ImageFormatLimits) {
10411
10412 TEST_DESCRIPTION("Exceed the limits of image format ");
10413
10414 m_errorMonitor->SetDesiredFailureMsg(
10415 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10416 "CreateImage extents exceed allowable limits for format");
10417 VkImageCreateInfo image_create_info = {};
10418 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10419 image_create_info.pNext = NULL;
10420 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10421 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10422 image_create_info.extent.width = 32;
10423 image_create_info.extent.height = 32;
10424 image_create_info.extent.depth = 1;
10425 image_create_info.mipLevels = 1;
10426 image_create_info.arrayLayers = 1;
10427 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10428 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10429 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10430 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10431 image_create_info.flags = 0;
10432
10433 VkImage nullImg;
10434 VkImageFormatProperties imgFmtProps;
10435 vkGetPhysicalDeviceImageFormatProperties(
10436 gpu(), image_create_info.format, image_create_info.imageType,
10437 image_create_info.tiling, image_create_info.usage,
10438 image_create_info.flags, &imgFmtProps);
10439 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
10440 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10441 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10442 m_errorMonitor->VerifyFound();
10443 image_create_info.extent.depth = 1;
10444
10445 m_errorMonitor->SetDesiredFailureMsg(
10446 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10447 "exceeds allowable maximum supported by format of");
10448 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
10449 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10450 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10451 m_errorMonitor->VerifyFound();
10452 image_create_info.mipLevels = 1;
10453
10454 m_errorMonitor->SetDesiredFailureMsg(
10455 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10456 "exceeds allowable maximum supported by format of");
10457 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
10458 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10459 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10460 m_errorMonitor->VerifyFound();
10461 image_create_info.arrayLayers = 1;
10462
10463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10464 "is not supported by format");
10465 int samples = imgFmtProps.sampleCounts >> 1;
10466 image_create_info.samples = (VkSampleCountFlagBits)samples;
10467 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10468 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10469 m_errorMonitor->VerifyFound();
10470 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10471
10472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10473 "pCreateInfo->initialLayout, must be "
10474 "VK_IMAGE_LAYOUT_UNDEFINED or "
10475 "VK_IMAGE_LAYOUT_PREINITIALIZED");
10476 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10477 // Expect INVALID_LAYOUT
10478 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10479 m_errorMonitor->VerifyFound();
10480 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10481}
10482
Karl Schultz6addd812016-02-02 17:17:23 -070010483TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060010484 VkResult err;
10485 bool pass;
10486
10487 // Create color images with different format sizes and try to copy between them
10488 m_errorMonitor->SetDesiredFailureMsg(
10489 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10490 "vkCmdCopyImage called with unmatched source and dest image format sizes");
10491
10492 ASSERT_NO_FATAL_FAILURE(InitState());
10493
10494 // Create two images of different types and try to copy between them
10495 VkImage srcImage;
10496 VkImage dstImage;
10497 VkDeviceMemory srcMem;
10498 VkDeviceMemory destMem;
10499 VkMemoryRequirements memReqs;
10500
10501 VkImageCreateInfo image_create_info = {};
10502 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10503 image_create_info.pNext = NULL;
10504 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10505 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10506 image_create_info.extent.width = 32;
10507 image_create_info.extent.height = 32;
10508 image_create_info.extent.depth = 1;
10509 image_create_info.mipLevels = 1;
10510 image_create_info.arrayLayers = 1;
10511 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10512 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10513 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10514 image_create_info.flags = 0;
10515
10516 err =
10517 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
10518 ASSERT_VK_SUCCESS(err);
10519
10520 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
10521 // Introduce failure by creating second image with a different-sized format.
10522 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
10523
10524 err =
10525 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
10526 ASSERT_VK_SUCCESS(err);
10527
10528 // Allocate memory
10529 VkMemoryAllocateInfo memAlloc = {};
10530 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10531 memAlloc.pNext = NULL;
10532 memAlloc.allocationSize = 0;
10533 memAlloc.memoryTypeIndex = 0;
10534
10535 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
10536 memAlloc.allocationSize = memReqs.size;
10537 pass =
10538 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
10539 ASSERT_TRUE(pass);
10540 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
10541 ASSERT_VK_SUCCESS(err);
10542
10543 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
10544 memAlloc.allocationSize = memReqs.size;
10545 pass =
10546 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
10547 ASSERT_TRUE(pass);
10548 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
10549 ASSERT_VK_SUCCESS(err);
10550
10551 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10552 ASSERT_VK_SUCCESS(err);
10553 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
10554 ASSERT_VK_SUCCESS(err);
10555
10556 BeginCommandBuffer();
10557 VkImageCopy copyRegion;
10558 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10559 copyRegion.srcSubresource.mipLevel = 0;
10560 copyRegion.srcSubresource.baseArrayLayer = 0;
10561 copyRegion.srcSubresource.layerCount = 0;
10562 copyRegion.srcOffset.x = 0;
10563 copyRegion.srcOffset.y = 0;
10564 copyRegion.srcOffset.z = 0;
10565 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10566 copyRegion.dstSubresource.mipLevel = 0;
10567 copyRegion.dstSubresource.baseArrayLayer = 0;
10568 copyRegion.dstSubresource.layerCount = 0;
10569 copyRegion.dstOffset.x = 0;
10570 copyRegion.dstOffset.y = 0;
10571 copyRegion.dstOffset.z = 0;
10572 copyRegion.extent.width = 1;
10573 copyRegion.extent.height = 1;
10574 copyRegion.extent.depth = 1;
10575 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10576 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10577 EndCommandBuffer();
10578
10579 m_errorMonitor->VerifyFound();
10580
10581 vkDestroyImage(m_device->device(), srcImage, NULL);
10582 vkDestroyImage(m_device->device(), dstImage, NULL);
10583 vkFreeMemory(m_device->device(), srcMem, NULL);
10584 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010585}
10586
Karl Schultz6addd812016-02-02 17:17:23 -070010587TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
10588 VkResult err;
10589 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010590
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010591 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010592 m_errorMonitor->SetDesiredFailureMsg(
10593 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010594 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010595
Mike Stroyana3082432015-09-25 13:39:21 -060010596 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010597
10598 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010599 VkImage srcImage;
10600 VkImage dstImage;
10601 VkDeviceMemory srcMem;
10602 VkDeviceMemory destMem;
10603 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010604
10605 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010606 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10607 image_create_info.pNext = NULL;
10608 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10609 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10610 image_create_info.extent.width = 32;
10611 image_create_info.extent.height = 32;
10612 image_create_info.extent.depth = 1;
10613 image_create_info.mipLevels = 1;
10614 image_create_info.arrayLayers = 1;
10615 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10616 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10617 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10618 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010619
Karl Schultz6addd812016-02-02 17:17:23 -070010620 err =
10621 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010622 ASSERT_VK_SUCCESS(err);
10623
Karl Schultzbdb75952016-04-19 11:36:49 -060010624 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
10625
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010626 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070010627 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010628 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
10629 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010630
Karl Schultz6addd812016-02-02 17:17:23 -070010631 err =
10632 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010633 ASSERT_VK_SUCCESS(err);
10634
10635 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010636 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010637 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10638 memAlloc.pNext = NULL;
10639 memAlloc.allocationSize = 0;
10640 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010641
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010642 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010643 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010644 pass =
10645 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010646 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010647 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010648 ASSERT_VK_SUCCESS(err);
10649
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010650 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010651 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010652 pass =
10653 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010654 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010655 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010656 ASSERT_VK_SUCCESS(err);
10657
10658 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10659 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010660 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010661 ASSERT_VK_SUCCESS(err);
10662
10663 BeginCommandBuffer();
10664 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010665 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010666 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010667 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010668 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010669 copyRegion.srcOffset.x = 0;
10670 copyRegion.srcOffset.y = 0;
10671 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010672 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010673 copyRegion.dstSubresource.mipLevel = 0;
10674 copyRegion.dstSubresource.baseArrayLayer = 0;
10675 copyRegion.dstSubresource.layerCount = 0;
10676 copyRegion.dstOffset.x = 0;
10677 copyRegion.dstOffset.y = 0;
10678 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010679 copyRegion.extent.width = 1;
10680 copyRegion.extent.height = 1;
10681 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010682 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10683 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010684 EndCommandBuffer();
10685
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010686 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010687
Chia-I Wuf7458c52015-10-26 21:10:41 +080010688 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010689 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010690 vkFreeMemory(m_device->device(), srcMem, NULL);
10691 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010692}
10693
Karl Schultz6addd812016-02-02 17:17:23 -070010694TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
10695 VkResult err;
10696 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010697
Karl Schultz6addd812016-02-02 17:17:23 -070010698 m_errorMonitor->SetDesiredFailureMsg(
10699 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010700 "vkCmdResolveImage called with source sample count less than 2.");
10701
Mike Stroyana3082432015-09-25 13:39:21 -060010702 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010703
10704 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070010705 VkImage srcImage;
10706 VkImage dstImage;
10707 VkDeviceMemory srcMem;
10708 VkDeviceMemory destMem;
10709 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010710
10711 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010712 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10713 image_create_info.pNext = NULL;
10714 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10715 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10716 image_create_info.extent.width = 32;
10717 image_create_info.extent.height = 1;
10718 image_create_info.extent.depth = 1;
10719 image_create_info.mipLevels = 1;
10720 image_create_info.arrayLayers = 1;
10721 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10722 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10723 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10724 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010725
Karl Schultz6addd812016-02-02 17:17:23 -070010726 err =
10727 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010728 ASSERT_VK_SUCCESS(err);
10729
Karl Schultz6addd812016-02-02 17:17:23 -070010730 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010731
Karl Schultz6addd812016-02-02 17:17:23 -070010732 err =
10733 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010734 ASSERT_VK_SUCCESS(err);
10735
10736 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010737 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010738 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10739 memAlloc.pNext = NULL;
10740 memAlloc.allocationSize = 0;
10741 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010742
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010743 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010744 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010745 pass =
10746 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010747 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010748 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010749 ASSERT_VK_SUCCESS(err);
10750
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010751 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010752 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010753 pass =
10754 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010755 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010756 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010757 ASSERT_VK_SUCCESS(err);
10758
10759 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10760 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010761 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010762 ASSERT_VK_SUCCESS(err);
10763
10764 BeginCommandBuffer();
10765 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070010766 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
10767 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060010768 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010769 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010770 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010771 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010772 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010773 resolveRegion.srcOffset.x = 0;
10774 resolveRegion.srcOffset.y = 0;
10775 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010776 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010777 resolveRegion.dstSubresource.mipLevel = 0;
10778 resolveRegion.dstSubresource.baseArrayLayer = 0;
10779 resolveRegion.dstSubresource.layerCount = 0;
10780 resolveRegion.dstOffset.x = 0;
10781 resolveRegion.dstOffset.y = 0;
10782 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010783 resolveRegion.extent.width = 1;
10784 resolveRegion.extent.height = 1;
10785 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010786 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10787 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010788 EndCommandBuffer();
10789
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010790 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010791
Chia-I Wuf7458c52015-10-26 21:10:41 +080010792 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010793 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010794 vkFreeMemory(m_device->device(), srcMem, NULL);
10795 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010796}
10797
Karl Schultz6addd812016-02-02 17:17:23 -070010798TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
10799 VkResult err;
10800 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010801
Karl Schultz6addd812016-02-02 17:17:23 -070010802 m_errorMonitor->SetDesiredFailureMsg(
10803 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010804 "vkCmdResolveImage called with dest sample count greater than 1.");
10805
Mike Stroyana3082432015-09-25 13:39:21 -060010806 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010807
Chris Forbesa7530692016-05-08 12:35:39 +120010808 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070010809 VkImage srcImage;
10810 VkImage dstImage;
10811 VkDeviceMemory srcMem;
10812 VkDeviceMemory destMem;
10813 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010814
10815 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010816 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10817 image_create_info.pNext = NULL;
10818 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10819 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10820 image_create_info.extent.width = 32;
10821 image_create_info.extent.height = 1;
10822 image_create_info.extent.depth = 1;
10823 image_create_info.mipLevels = 1;
10824 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120010825 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070010826 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10827 // Note: Some implementations expect color attachment usage for any
10828 // multisample surface
10829 image_create_info.usage =
10830 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10831 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010832
Karl Schultz6addd812016-02-02 17:17:23 -070010833 err =
10834 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010835 ASSERT_VK_SUCCESS(err);
10836
Karl Schultz6addd812016-02-02 17:17:23 -070010837 // Note: Some implementations expect color attachment usage for any
10838 // multisample surface
10839 image_create_info.usage =
10840 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010841
Karl Schultz6addd812016-02-02 17:17:23 -070010842 err =
10843 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010844 ASSERT_VK_SUCCESS(err);
10845
10846 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010847 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010848 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10849 memAlloc.pNext = NULL;
10850 memAlloc.allocationSize = 0;
10851 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010852
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010853 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010854 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010855 pass =
10856 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010857 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010858 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010859 ASSERT_VK_SUCCESS(err);
10860
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010861 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010862 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010863 pass =
10864 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010865 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010866 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010867 ASSERT_VK_SUCCESS(err);
10868
10869 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10870 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010871 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010872 ASSERT_VK_SUCCESS(err);
10873
10874 BeginCommandBuffer();
10875 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070010876 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
10877 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060010878 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010879 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010880 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010881 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010882 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010883 resolveRegion.srcOffset.x = 0;
10884 resolveRegion.srcOffset.y = 0;
10885 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010886 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010887 resolveRegion.dstSubresource.mipLevel = 0;
10888 resolveRegion.dstSubresource.baseArrayLayer = 0;
10889 resolveRegion.dstSubresource.layerCount = 0;
10890 resolveRegion.dstOffset.x = 0;
10891 resolveRegion.dstOffset.y = 0;
10892 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010893 resolveRegion.extent.width = 1;
10894 resolveRegion.extent.height = 1;
10895 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010896 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10897 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010898 EndCommandBuffer();
10899
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010900 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010901
Chia-I Wuf7458c52015-10-26 21:10:41 +080010902 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010903 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010904 vkFreeMemory(m_device->device(), srcMem, NULL);
10905 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010906}
10907
Karl Schultz6addd812016-02-02 17:17:23 -070010908TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
10909 VkResult err;
10910 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010911
Karl Schultz6addd812016-02-02 17:17:23 -070010912 m_errorMonitor->SetDesiredFailureMsg(
10913 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010914 "vkCmdResolveImage called with unmatched source and dest formats.");
10915
Mike Stroyana3082432015-09-25 13:39:21 -060010916 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010917
10918 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010919 VkImage srcImage;
10920 VkImage dstImage;
10921 VkDeviceMemory srcMem;
10922 VkDeviceMemory destMem;
10923 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010924
10925 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010926 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10927 image_create_info.pNext = NULL;
10928 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10929 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10930 image_create_info.extent.width = 32;
10931 image_create_info.extent.height = 1;
10932 image_create_info.extent.depth = 1;
10933 image_create_info.mipLevels = 1;
10934 image_create_info.arrayLayers = 1;
10935 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
10936 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10937 // Note: Some implementations expect color attachment usage for any
10938 // multisample surface
10939 image_create_info.usage =
10940 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10941 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010942
Karl Schultz6addd812016-02-02 17:17:23 -070010943 err =
10944 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010945 ASSERT_VK_SUCCESS(err);
10946
Karl Schultz6addd812016-02-02 17:17:23 -070010947 // Set format to something other than source image
10948 image_create_info.format = VK_FORMAT_R32_SFLOAT;
10949 // Note: Some implementations expect color attachment usage for any
10950 // multisample surface
10951 image_create_info.usage =
10952 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10953 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010954
Karl Schultz6addd812016-02-02 17:17:23 -070010955 err =
10956 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010957 ASSERT_VK_SUCCESS(err);
10958
10959 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010960 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010961 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10962 memAlloc.pNext = NULL;
10963 memAlloc.allocationSize = 0;
10964 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010965
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010966 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010967 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010968 pass =
10969 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010970 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010971 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010972 ASSERT_VK_SUCCESS(err);
10973
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010974 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010975 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010976 pass =
10977 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010978 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010979 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010980 ASSERT_VK_SUCCESS(err);
10981
10982 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10983 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010984 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010985 ASSERT_VK_SUCCESS(err);
10986
10987 BeginCommandBuffer();
10988 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070010989 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
10990 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060010991 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010992 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010993 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010994 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010995 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010996 resolveRegion.srcOffset.x = 0;
10997 resolveRegion.srcOffset.y = 0;
10998 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010999 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011000 resolveRegion.dstSubresource.mipLevel = 0;
11001 resolveRegion.dstSubresource.baseArrayLayer = 0;
11002 resolveRegion.dstSubresource.layerCount = 0;
11003 resolveRegion.dstOffset.x = 0;
11004 resolveRegion.dstOffset.y = 0;
11005 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011006 resolveRegion.extent.width = 1;
11007 resolveRegion.extent.height = 1;
11008 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011009 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11010 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011011 EndCommandBuffer();
11012
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011013 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011014
Chia-I Wuf7458c52015-10-26 21:10:41 +080011015 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011016 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011017 vkFreeMemory(m_device->device(), srcMem, NULL);
11018 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011019}
11020
Karl Schultz6addd812016-02-02 17:17:23 -070011021TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
11022 VkResult err;
11023 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011024
Karl Schultz6addd812016-02-02 17:17:23 -070011025 m_errorMonitor->SetDesiredFailureMsg(
11026 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011027 "vkCmdResolveImage called with unmatched source and dest image types.");
11028
Mike Stroyana3082432015-09-25 13:39:21 -060011029 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011030
11031 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011032 VkImage srcImage;
11033 VkImage dstImage;
11034 VkDeviceMemory srcMem;
11035 VkDeviceMemory destMem;
11036 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011037
11038 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011039 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11040 image_create_info.pNext = NULL;
11041 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11042 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11043 image_create_info.extent.width = 32;
11044 image_create_info.extent.height = 1;
11045 image_create_info.extent.depth = 1;
11046 image_create_info.mipLevels = 1;
11047 image_create_info.arrayLayers = 1;
11048 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
11049 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11050 // Note: Some implementations expect color attachment usage for any
11051 // multisample surface
11052 image_create_info.usage =
11053 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11054 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011055
Karl Schultz6addd812016-02-02 17:17:23 -070011056 err =
11057 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011058 ASSERT_VK_SUCCESS(err);
11059
Karl Schultz6addd812016-02-02 17:17:23 -070011060 image_create_info.imageType = VK_IMAGE_TYPE_1D;
11061 // Note: Some implementations expect color attachment usage for any
11062 // multisample surface
11063 image_create_info.usage =
11064 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11065 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011066
Karl Schultz6addd812016-02-02 17:17:23 -070011067 err =
11068 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011069 ASSERT_VK_SUCCESS(err);
11070
11071 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011072 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011073 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11074 memAlloc.pNext = NULL;
11075 memAlloc.allocationSize = 0;
11076 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011077
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011078 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011079 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011080 pass =
11081 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011082 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011083 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011084 ASSERT_VK_SUCCESS(err);
11085
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011086 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011087 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011088 pass =
11089 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011090 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011091 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011092 ASSERT_VK_SUCCESS(err);
11093
11094 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11095 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011096 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011097 ASSERT_VK_SUCCESS(err);
11098
11099 BeginCommandBuffer();
11100 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011101 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11102 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011103 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011104 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011105 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011106 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011107 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011108 resolveRegion.srcOffset.x = 0;
11109 resolveRegion.srcOffset.y = 0;
11110 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011111 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011112 resolveRegion.dstSubresource.mipLevel = 0;
11113 resolveRegion.dstSubresource.baseArrayLayer = 0;
11114 resolveRegion.dstSubresource.layerCount = 0;
11115 resolveRegion.dstOffset.x = 0;
11116 resolveRegion.dstOffset.y = 0;
11117 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011118 resolveRegion.extent.width = 1;
11119 resolveRegion.extent.height = 1;
11120 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011121 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11122 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011123 EndCommandBuffer();
11124
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011125 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011126
Chia-I Wuf7458c52015-10-26 21:10:41 +080011127 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011128 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011129 vkFreeMemory(m_device->device(), srcMem, NULL);
11130 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011131}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011132
Karl Schultz6addd812016-02-02 17:17:23 -070011133TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011134 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070011135 // to using a DS format, then cause it to hit error due to COLOR_BIT not
11136 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011137 // The image format check comes 2nd in validation so we trigger it first,
11138 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070011139 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011140
Karl Schultz6addd812016-02-02 17:17:23 -070011141 m_errorMonitor->SetDesiredFailureMsg(
11142 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011143 "Combination depth/stencil image formats can have only the ");
11144
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011145 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011146
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011147 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011148 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
11149 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011150
11151 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011152 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11153 ds_pool_ci.pNext = NULL;
11154 ds_pool_ci.maxSets = 1;
11155 ds_pool_ci.poolSizeCount = 1;
11156 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011157
11158 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -070011159 err =
11160 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011161 ASSERT_VK_SUCCESS(err);
11162
11163 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011164 dsl_binding.binding = 0;
11165 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
11166 dsl_binding.descriptorCount = 1;
11167 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11168 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011169
11170 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011171 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11172 ds_layout_ci.pNext = NULL;
11173 ds_layout_ci.bindingCount = 1;
11174 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011175 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070011176 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
11177 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011178 ASSERT_VK_SUCCESS(err);
11179
11180 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011181 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011182 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011183 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011184 alloc_info.descriptorPool = ds_pool;
11185 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070011186 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
11187 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011188 ASSERT_VK_SUCCESS(err);
11189
Karl Schultz6addd812016-02-02 17:17:23 -070011190 VkImage image_bad;
11191 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011192 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060011193 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011194 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070011195 const int32_t tex_width = 32;
11196 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011197
11198 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011199 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11200 image_create_info.pNext = NULL;
11201 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11202 image_create_info.format = tex_format_bad;
11203 image_create_info.extent.width = tex_width;
11204 image_create_info.extent.height = tex_height;
11205 image_create_info.extent.depth = 1;
11206 image_create_info.mipLevels = 1;
11207 image_create_info.arrayLayers = 1;
11208 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11209 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11210 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
11211 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11212 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011213
Karl Schultz6addd812016-02-02 17:17:23 -070011214 err =
11215 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011216 ASSERT_VK_SUCCESS(err);
11217 image_create_info.format = tex_format_good;
Karl Schultz6addd812016-02-02 17:17:23 -070011218 image_create_info.usage =
11219 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11220 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
11221 &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011222 ASSERT_VK_SUCCESS(err);
11223
11224 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011225 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11226 image_view_create_info.image = image_bad;
11227 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11228 image_view_create_info.format = tex_format_bad;
11229 image_view_create_info.subresourceRange.baseArrayLayer = 0;
11230 image_view_create_info.subresourceRange.baseMipLevel = 0;
11231 image_view_create_info.subresourceRange.layerCount = 1;
11232 image_view_create_info.subresourceRange.levelCount = 1;
11233 image_view_create_info.subresourceRange.aspectMask =
11234 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011235
11236 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070011237 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
11238 &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011239
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011240 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011241
Chia-I Wuf7458c52015-10-26 21:10:41 +080011242 vkDestroyImage(m_device->device(), image_bad, NULL);
11243 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011244 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11245 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011246}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060011247
11248TEST_F(VkLayerTest, ClearImageErrors) {
11249 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
11250 "ClearDepthStencilImage with a color image.");
11251
11252 ASSERT_NO_FATAL_FAILURE(InitState());
11253 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11254
11255 // Renderpass is started here so end it as Clear cmds can't be in renderpass
11256 BeginCommandBuffer();
11257 m_commandBuffer->EndRenderPass();
11258
11259 // Color image
11260 VkClearColorValue clear_color;
11261 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
11262 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
11263 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
11264 const int32_t img_width = 32;
11265 const int32_t img_height = 32;
11266 VkImageCreateInfo image_create_info = {};
11267 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11268 image_create_info.pNext = NULL;
11269 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11270 image_create_info.format = color_format;
11271 image_create_info.extent.width = img_width;
11272 image_create_info.extent.height = img_height;
11273 image_create_info.extent.depth = 1;
11274 image_create_info.mipLevels = 1;
11275 image_create_info.arrayLayers = 1;
11276 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11277 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11278 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11279
11280 vk_testing::Image color_image;
11281 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info,
11282 reqs);
11283
11284 const VkImageSubresourceRange color_range =
11285 vk_testing::Image::subresource_range(image_create_info,
11286 VK_IMAGE_ASPECT_COLOR_BIT);
11287
11288 // Depth/Stencil image
11289 VkClearDepthStencilValue clear_value = {0};
11290 reqs = 0; // don't need HOST_VISIBLE DS image
11291 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
11292 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
11293 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
11294 ds_image_create_info.extent.width = 64;
11295 ds_image_create_info.extent.height = 64;
11296 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11297 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11298
11299 vk_testing::Image ds_image;
11300 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info,
11301 reqs);
11302
11303 const VkImageSubresourceRange ds_range =
11304 vk_testing::Image::subresource_range(ds_image_create_info,
11305 VK_IMAGE_ASPECT_DEPTH_BIT);
11306
11307 m_errorMonitor->SetDesiredFailureMsg(
11308 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11309 "vkCmdClearColorImage called with depth/stencil image.");
11310
11311 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
11312 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
11313 &color_range);
11314
11315 m_errorMonitor->VerifyFound();
11316
11317 // Call CmdClearDepthStencilImage with color image
11318 m_errorMonitor->SetDesiredFailureMsg(
11319 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11320 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
11321
11322 vkCmdClearDepthStencilImage(
11323 m_commandBuffer->GetBufferHandle(), color_image.handle(),
11324 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
11325 &ds_range);
11326
11327 m_errorMonitor->VerifyFound();
11328}
Tobin Ehliscde08892015-09-22 10:11:37 -060011329#endif // IMAGE_TESTS
11330
Tony Barbour300a6082015-04-07 13:44:53 -060011331int main(int argc, char **argv) {
11332 int result;
11333
Cody Northrop8e54a402016-03-08 22:25:52 -070011334#ifdef ANDROID
11335 int vulkanSupport = InitVulkan();
11336 if (vulkanSupport == 0)
11337 return 1;
11338#endif
11339
Tony Barbour300a6082015-04-07 13:44:53 -060011340 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060011341 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060011342
11343 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
11344
11345 result = RUN_ALL_TESTS();
11346
Tony Barbour6918cd52015-04-09 12:58:51 -060011347 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060011348 return result;
11349}